├── images ├── nas_l2.png ├── nas_l3.png ├── nas_mac.png ├── nas_stg.png ├── cii_badge.png ├── map_ports.png ├── nas_design.png ├── nas_l3_2.png ├── nas_lag2.png ├── nas_lldp.png ├── nas_lldp2.png ├── oe_puppet.png ├── oe_quagga.png ├── run_time.png ├── sdi_arch.png ├── oe_bgpquagga.png ├── oe_prodarch2.png ├── arp_table_entry.png ├── oe_evtflow_cs.png ├── opx_components.png ├── vlan_bridging.png ├── opx_architecture.png ├── routing_subsystem.png ├── local_port_mirroring.png ├── open_install_bootseq.png ├── temperature_control.png ├── ipv4_routing_topology.png ├── remote_port_mirroring.png ├── add_linux_bond_interface.png └── hardware_virtualization.png ├── .gitreview ├── examples ├── openswitch_opx_installation_guide_71917.pdf ├── python_event_publisher_application.py ├── python_client_application_template.py ├── python_event_subscriber_application.py ├── publish_events.py ├── register_for_events.py ├── delete_acl.py ├── delete_vlan.py ├── create_vlan.py ├── create_mac_table_entry.py ├── configure_ip_address.py ├── delete_ip_address.py ├── delete_mac_table_entry.py ├── get_mac_table_entry.py ├── remove_mac_table_entries_from_multiple_vlans.py ├── route_delete.py ├── delete_ports_vlan.py ├── add_vlan_port.py ├── route_create.py ├── config_acl.py ├── c_template_event_publisher_application.c ├── publish_events.c ├── register_for_events.c ├── create_acl.py ├── delete_mac_table_entry.c ├── python_server_template.py ├── create_mac_table_entry.c ├── get_mac_table_entry.c ├── remove_mac_table_entries_from_multiple_vlans.c ├── create_acl_table.py ├── c_template_event_subscriber_application.c ├── c_client_template.c └── c_template_server_application.c └── README.md /images/nas_l2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-switch/opx-docs/HEAD/images/nas_l2.png -------------------------------------------------------------------------------- /images/nas_l3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-switch/opx-docs/HEAD/images/nas_l3.png -------------------------------------------------------------------------------- /images/nas_mac.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-switch/opx-docs/HEAD/images/nas_mac.png -------------------------------------------------------------------------------- /images/nas_stg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-switch/opx-docs/HEAD/images/nas_stg.png -------------------------------------------------------------------------------- /.gitreview: -------------------------------------------------------------------------------- 1 | [gerrit] 2 | host=review.openswitch.net 3 | port=29418 4 | project=opx/opx-docs 5 | -------------------------------------------------------------------------------- /images/cii_badge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-switch/opx-docs/HEAD/images/cii_badge.png -------------------------------------------------------------------------------- /images/map_ports.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-switch/opx-docs/HEAD/images/map_ports.png -------------------------------------------------------------------------------- /images/nas_design.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-switch/opx-docs/HEAD/images/nas_design.png -------------------------------------------------------------------------------- /images/nas_l3_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-switch/opx-docs/HEAD/images/nas_l3_2.png -------------------------------------------------------------------------------- /images/nas_lag2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-switch/opx-docs/HEAD/images/nas_lag2.png -------------------------------------------------------------------------------- /images/nas_lldp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-switch/opx-docs/HEAD/images/nas_lldp.png -------------------------------------------------------------------------------- /images/nas_lldp2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-switch/opx-docs/HEAD/images/nas_lldp2.png -------------------------------------------------------------------------------- /images/oe_puppet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-switch/opx-docs/HEAD/images/oe_puppet.png -------------------------------------------------------------------------------- /images/oe_quagga.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-switch/opx-docs/HEAD/images/oe_quagga.png -------------------------------------------------------------------------------- /images/run_time.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-switch/opx-docs/HEAD/images/run_time.png -------------------------------------------------------------------------------- /images/sdi_arch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-switch/opx-docs/HEAD/images/sdi_arch.png -------------------------------------------------------------------------------- /images/oe_bgpquagga.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-switch/opx-docs/HEAD/images/oe_bgpquagga.png -------------------------------------------------------------------------------- /images/oe_prodarch2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-switch/opx-docs/HEAD/images/oe_prodarch2.png -------------------------------------------------------------------------------- /images/arp_table_entry.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-switch/opx-docs/HEAD/images/arp_table_entry.png -------------------------------------------------------------------------------- /images/oe_evtflow_cs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-switch/opx-docs/HEAD/images/oe_evtflow_cs.png -------------------------------------------------------------------------------- /images/opx_components.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-switch/opx-docs/HEAD/images/opx_components.png -------------------------------------------------------------------------------- /images/vlan_bridging.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-switch/opx-docs/HEAD/images/vlan_bridging.png -------------------------------------------------------------------------------- /images/opx_architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-switch/opx-docs/HEAD/images/opx_architecture.png -------------------------------------------------------------------------------- /images/routing_subsystem.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-switch/opx-docs/HEAD/images/routing_subsystem.png -------------------------------------------------------------------------------- /images/local_port_mirroring.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-switch/opx-docs/HEAD/images/local_port_mirroring.png -------------------------------------------------------------------------------- /images/open_install_bootseq.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-switch/opx-docs/HEAD/images/open_install_bootseq.png -------------------------------------------------------------------------------- /images/temperature_control.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-switch/opx-docs/HEAD/images/temperature_control.png -------------------------------------------------------------------------------- /images/ipv4_routing_topology.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-switch/opx-docs/HEAD/images/ipv4_routing_topology.png -------------------------------------------------------------------------------- /images/remote_port_mirroring.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-switch/opx-docs/HEAD/images/remote_port_mirroring.png -------------------------------------------------------------------------------- /images/add_linux_bond_interface.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-switch/opx-docs/HEAD/images/add_linux_bond_interface.png -------------------------------------------------------------------------------- /images/hardware_virtualization.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-switch/opx-docs/HEAD/images/hardware_virtualization.png -------------------------------------------------------------------------------- /examples/openswitch_opx_installation_guide_71917.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-switch/opx-docs/HEAD/examples/openswitch_opx_installation_guide_71917.pdf -------------------------------------------------------------------------------- /examples/python_event_publisher_application.py: -------------------------------------------------------------------------------- 1 | #Python code block for CPS event publisher application 2 | 3 | import cps 4 | import cps_utils 5 | 6 | handle = cps.event_connect() 7 | 8 | obj = cps_utils.CPSObject('base-port/interface',qual='observed', data= {"ifindex":23}) 9 | 10 | cps.event_send(handle, obj.get()) 11 | -------------------------------------------------------------------------------- /examples/python_client_application_template.py: -------------------------------------------------------------------------------- 1 | #Python code block for CPS client application 2 | 3 | import cps 4 | import cps_utils 5 | 6 | #Example get request cps_get_response = [] 7 | cps.get([cps.key_from_name('observed','base-pas/chassis')], cps_get_response) 8 | 9 | chassis_vendor_name = cps_attr_get(cps_get_response[0]['data'],'base-pas/chassis/vendor-name') 10 | -------------------------------------------------------------------------------- /examples/python_event_subscriber_application.py: -------------------------------------------------------------------------------- 1 | #Python code block for CPS event subscriber application 2 | 3 | import cps 4 | import cps_utils 5 | 6 | handle = cps.event_connect() 7 | 8 | cps.event_register(handle, cps_api_object_key) 9 | 10 | while True: 11 | ev = cps.event_wait(handle) 12 | 13 | if ev[‘key’] == ...: 14 | ... elif ev['key'] == ...: 15 | ... 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # opx-docs 2 | This repository contains the documentation for the OpenSwitch OPX project. See [OpenSwitch OPX Wiki](https://github.com/open-switch/opx-docs/wiki) for complete information. 3 | 4 | © 2018-2019 OpenSwitch project. All information is contributed to and made available by OPX under the Creative Commons Attribution 4.0 International License (available at http://creativecommons.org/licenses/by/4.0/). 5 | -------------------------------------------------------------------------------- /examples/publish_events.py: -------------------------------------------------------------------------------- 1 | #Python code block to publish events 2 | 3 | import cps 4 | import cps_utils 5 | 6 | #Create a handle to connect to the event service 7 | handle = cps.event_connect() 8 | 9 | #Create a CPS object 10 | obj = cps_utils.CPSObject('base-port/interface', qual='observed', 11 | data={'ifindex': 23}) 12 | 13 | #Publish the CPS object 14 | cps.event_send(handle, obj.get()) 15 | -------------------------------------------------------------------------------- /examples/register_for_events.py: -------------------------------------------------------------------------------- 1 | #Python code block to register for events 2 | 3 | import cps 4 | 5 | #Create a handle to connect to the event service 6 | handle = cps.event_connect() 7 | 8 | #Register a key with the event service to receive notification when an event is published 9 | cps.event_register(handle, cps.key_from_name('observed', 10 | 'base-port/interface')) 11 | while True: 12 | obj = cps.event_wait(handle) 13 | print obj 14 | -------------------------------------------------------------------------------- /examples/delete_acl.py: -------------------------------------------------------------------------------- 1 | #Python code block to delete ACL entry 2 | 3 | import cps_utils 4 | 5 | #Create the CPS Object and fill the table-id and entry-id key values 6 | cps_obj = cps_utils.CPSObject(module='base-acl/entry', data={'table-id': 2, 'id': 1}) 7 | 8 | #Associate the CPS Object with a CPS operation 9 | cps_update = ('delete', cps_obj.get()) 10 | 11 | #Add the CPS object to a new CPS Transaction 12 | cps_trans = cps_utils.CPSTransaction([cps_update]) 13 | 14 | #Verify return value 15 | ret = cps_trans.commit() 16 | if not ret: 17 | raise RuntimeError ("Error deleting ACL Entry") 18 | -------------------------------------------------------------------------------- /examples/delete_vlan.py: -------------------------------------------------------------------------------- 1 | # Python code block to delete VLAN 2 | 3 | import cps 4 | import cps_object 5 | 6 | #Create CPS object 7 | cps_obj = \ 8 | cps_object.CPSObject('dell-base-if-cmn/if/interfaces/interface') 9 | 10 | #Populate the VLAN attributes VLAN_ID='br100' 11 | VLAN_ID = 'br100' 12 | cps_obj.add_attr('if/interfaces/interface/name', VLAN_ID) 13 | 14 | #Associate a CPS set operation with the CPS object 15 | cps_update = {'change': cps_obj.get(), 'operation': 'delete'} 16 | 17 | #Add the CPS operation,obj pair to a new CPS transaction 18 | transaction = cps.transaction([cps_update]) 19 | 20 | #Check for failure 21 | if not transaction: 22 | raise RuntimeError('Error in deleting Vlan') 23 | print 'successful' 24 | -------------------------------------------------------------------------------- /examples/create_vlan.py: -------------------------------------------------------------------------------- 1 | #Python code block to create VLAN 2 | 3 | import cps_object 4 | import cps 5 | 6 | #Create CPS Object 7 | cps_obj = \ 8 | cps_object.CPSObject('dell-base-if-cmn/if/interfaces/interface') 9 | 10 | #Populate the attributes for the CPS Object 11 | cps_obj.add_attr('base-if-vlan/if/interfaces/interface/id', 100) 12 | cps_obj.add_attr('if/interfaces/interface/type', 'ianaift:l2vlan') 13 | 14 | #Associate a CPS Operation with the CPS Object 15 | cps_update = {'change': cps_obj.get(), 'operation': 'create'} 16 | 17 | #Add the CPS Operation,Obj pair to a new CPS Transaction 18 | transaction = cps.transaction([cps_update]) 19 | 20 | #Check for failure 21 | if not transaction: 22 | raise RuntimeError('Error creating Vlan') 23 | print 'Successfully created' 24 | -------------------------------------------------------------------------------- /examples/create_mac_table_entry.py: -------------------------------------------------------------------------------- 1 | #Python code block to configure MAC address table entry 2 | 3 | import cps_utils 4 | 5 | #Register the attribute type 6 | cps_utils.add_attr_type('base-mac/table/mac-address', 'mac') 7 | 8 | #Define the MAC address, interface index and VLAN attributes 9 | d = {'mac-address': '00:0a:0b:cc:0d:0e', 'ifindex': 18, 'vlan': '100'} 10 | 11 | #Create a CPS object 12 | obj = cps_utils.CPSObject('base-mac/table', data=d) 13 | 14 | #Associate the operation to the CPS object 15 | tr_obj = ('create', obj.get()) 16 | 17 | #Create a transaction object 18 | transaction = cps_utils.CPSTransaction([tr_obj]) 19 | 20 | #Check for failure 21 | ret = transaction.commit() 22 | if not ret: 23 | raise RuntimeError('Error creating MAC Table Entry') 24 | print 'Successfully created' 25 | -------------------------------------------------------------------------------- /examples/configure_ip_address.py: -------------------------------------------------------------------------------- 1 | #Python code block to set IP address 2 | 3 | import cps_utils 4 | 5 | #Populate attributes for the CPS object 6 | ifindex = 16 7 | ip_addr = '10.0.0.1' 8 | pfix_len = 16 9 | ip_attributes = {'base-ip/ipv4/ifindex': ifindex, 'ip': ip_addr, 10 | 'prefix-length': pfix_len} 11 | 12 | #Create CPS object 13 | cps_utils.add_attr_type('base-ip/ipv4/address/ip', 'ipv4') 14 | cps_obj = cps_utils.CPSObject('base-ip/ipv4/address', 15 | data=ip_attributes) 16 | 17 | #Create CPS transaction for object create 18 | cps_update = ('create', cps_obj.get()) 19 | transaction = cps_utils.CPSTransaction([cps_update]) 20 | 21 | #Commit transaction 22 | ret = transaction.commit() 23 | 24 | #Check for failure 25 | if not ret: 26 | raise RuntimeError('Error ') 27 | print 'Successfully created' 28 | -------------------------------------------------------------------------------- /examples/delete_ip_address.py: -------------------------------------------------------------------------------- 1 | #Python code block to delete IP address 2 | 3 | import cps_utils 4 | 5 | #Populate attributes for the CPS object 6 | idx = 16 7 | ip_addr = '10.0.0.1' 8 | pfix_len = 16 9 | ip_attributes = {'base-ip/ipv4/ifindex': idx, 'ip': ip_addr, 10 | 'prefix-length': pfix_len} 11 | 12 | #Create CPS object 13 | cps_utils.add_attr_type('base-ip/ipv4/address/ip', 'ipv4') 14 | cps_obj = cps_utils.CPSObject('base-ip/ipv4/address', 15 | data=ip_attributes) 16 | 17 | #Create CPS transaction to delete the CPS object 18 | cps_update = ('delete', cps_obj.get()) 19 | transaction = cps_utils.CPSTransaction([cps_update]) 20 | 21 | #Commit the transaction 22 | ret = transaction.commit() 23 | 24 | #Check for failure 25 | if not ret: 26 | raise RuntimeError('Error ') 27 | print 'Successfully deleted' 28 | -------------------------------------------------------------------------------- /examples/delete_mac_table_entry.py: -------------------------------------------------------------------------------- 1 | #Python code block to delete MAC address table entry 2 | 3 | import cps_utils 4 | 5 | #Register the attribute type to convert between string and byte-array format 6 | cps_utils.add_attr_type('base-mac/table/mac-address', 'mac') 7 | 8 | #Define the MAC address interface index, and VLAN to delete the static address entry 9 | d = {'mac-address': '00:0a:0b:cc:0d:0e', 'ifindex': 18, 'vlan': '100'} 10 | 11 | #Create a CPS object 12 | obj = cps_utils.CPSObject('base-mac/table', data=d) 13 | 14 | #Add the operation to the CPS object 15 | tr_obj = ('delete', obj.get()) 16 | 17 | #Create a transaction object 18 | transaction = cps_utils.CPSTransaction([tr_obj]) 19 | 20 | #Check for failure 21 | ret = transaction.commit() 22 | if not ret: 23 | raise RuntimeError('Error deleting entry from MAC Table') 24 | print 'Successfully deleted' 25 | -------------------------------------------------------------------------------- /examples/get_mac_table_entry.py: -------------------------------------------------------------------------------- 1 | #Python code block to request MAC address table entry 2 | 3 | import cps_utils 4 | import cps 5 | 6 | #Register the attribute type 7 | cps_utils.add_attr_type("base-mac/query/mac-address", "mac") 8 | 9 | #Define the MAC address request type 10 | d = {"mac-address": "00:0a:0b:cc:0d:0e","request-type":"2"} 11 | 12 | #Associate the get operation with the CPS object 13 | obj = cps_utils.CPSObject('base-mac/query', data= d) 14 | 15 | #Create an object filter list 16 | filter_list = [] filter_list.append(obj.get()) l = [] 17 | 18 | #Check for failure 19 | if cps.get(filter_list,l): 20 | if l: 21 | for ret_obj in l: 22 | cps_utils.print_obj(ret_obj) 23 | else: 24 | print "No objects found" 25 | else: 26 | print "No objects found" 27 | raise RuntimeError ("Error Getting MAC Table Entries") 28 | -------------------------------------------------------------------------------- /examples/remove_mac_table_entries_from_multiple_vlans.py: -------------------------------------------------------------------------------- 1 | #Python code block to remove MAC table entries from multiple VLANs 2 | 3 | import cps_utils 4 | 5 | #Define VLANs to remove MAC address entries from 6 | vlan_list = [1, 2, 3, 4, 5] 7 | 8 | #Create the CPS object 9 | obj = cps_utils.CPSObject('base-mac/flush') 10 | 11 | #Add the VLAN list to the CPS object 12 | count = 0 13 | el = ['input/filter', '0', 'vlan'] 14 | 15 | for vlan in vlan_list: 16 | obj.add_embed_attr(el, vlan) 17 | count = count + 1 18 | 19 | el[1] = str(count) 20 | 21 | #Associate the operation to the CPS object 22 | tr_obj = ('rpc', obj.get()) 23 | 24 | #Create a transaction object 25 | transaction = cps_utils.CPSTransaction([tr_obj]) 26 | 27 | #Check for failure 28 | ret = transaction.commit() 29 | if not ret: 30 | raise RuntimeError('Error Flushing entries from MAC Table' 31 | ) 32 | print 'Successfully removed' 33 | -------------------------------------------------------------------------------- /examples/route_delete.py: -------------------------------------------------------------------------------- 1 | #Python code block to delete a route 2 | 3 | import cps_utils 4 | import socket 5 | import netaddr as net 6 | 7 | #Populate the attributes 8 | version = 'ipv4' 9 | route_ip = '70.5.5.0' 10 | obj = cps_utils.CPSObject('base-route/obj/entry') 11 | obj.add_attr('vrf-id', 0) 12 | 13 | if version == 'ipv4': 14 | obj.add_attr('af', socket.AF_INET) 15 | elif version == 'ipv6': 16 | obj.add_attr('af', socket.AF_INET6) 17 | 18 | ip = net.IPNetwork(route_ip) 19 | 20 | obj.add_attr_type('route-prefix', version) 21 | obj.add_attr('route-prefix', str(ip.network)) 22 | obj.add_attr('prefix-len', int(ip.prefixlen)) 23 | 24 | print obj.get() 25 | cps_update = ('delete', obj.get()) 26 | transaction = cps_utils.CPSTransaction([cps_update]) 27 | 28 | #Commit transaction 29 | ret = transaction.commit() 30 | 31 | #Check for failure 32 | if not ret: 33 | raise RuntimeError('Error deleting Route') 34 | print 'Successfully deleted' 35 | -------------------------------------------------------------------------------- /examples/delete_ports_vlan.py: -------------------------------------------------------------------------------- 1 | #Python code block to delete port to VLAN 2 | 3 | import cps 4 | import cps_object 5 | 6 | #Create CPS object 7 | cps_obj = \ 8 | cps_object.CPSObject('dell-base-if-cmn/if/interfaces/interface') 9 | 10 | #Populate the VLAN attributes VLAN_ID='br100' 11 | VLAN_ID = 'br100' 12 | cps_obj.add_attr('if/interfaces/interface/name', VLAN_ID) 13 | 14 | #Delete the untagged-ports from VLAN, include the ports which is needed in the if_port_list 15 | if_port_list = ['e101-002-0'] 16 | cps_obj.add_attr('dell-if/if/interfaces/interface/untagged-ports', 17 | if_port_list) 18 | 19 | #Associate a CPS set operation with the CPS object 20 | cps_update = {'change': cps_obj.get(), 'operation': 'set'} 21 | 22 | #Add the CPS operation,obj pair to a new CPS transaction 23 | transaction = cps.transaction([cps_update]) 24 | 25 | #Check for failure 26 | if not transaction: 27 | raise RuntimeError('Error in deleting ports to Vlan') 28 | print 'successful' 29 | -------------------------------------------------------------------------------- /examples/add_vlan_port.py: -------------------------------------------------------------------------------- 1 | #Python code block to add port to VLAN 2 | 3 | import cps 4 | import cps_object 5 | 6 | #Create CPS object 7 | cps_obj = \ 8 | cps_object.CPSObject('dell-base-if-cmn/if/interfaces/interface') 9 | 10 | #Populate the VLAN attributes VLAN_ID='br100' 11 | VLAN_ID = 'br100' 12 | cps_obj.add_attr('if/interfaces/interface/name', VLAN_ID) 13 | 14 | #Add one or more ports to the untagged-ports property of the VLAN 15 | if_port_list = ['e101-001-0', 'e101-002-0', 'e101-003-0'] 16 | cps_obj.add_attr('dell-if/if/interfaces/interface/untagged-ports', 17 | if_port_list) 18 | 19 | #Associate a CPS set operation with the CPS object 20 | cps_update = {'change': cps_obj.get(), 'operation': 'set'} 21 | 22 | #Add the CPS operation,obj pair to a new CPS transaction 23 | transaction = cps.transaction([cps_update]) 24 | 25 | #Check for failure 26 | if not transaction: 27 | raise RuntimeError('Error in adding port to Vlan') 28 | print 'successful' 29 | -------------------------------------------------------------------------------- /examples/route_create.py: -------------------------------------------------------------------------------- 1 | #Python code block to create a route 2 | 3 | import cps_utils 4 | import socket 5 | import netaddr as net 6 | 7 | #Populate the attributes 8 | version = 'ipv4' 9 | route_ip = '70.5.5.0' 10 | obj = cps_utils.CPSObject('base-route/obj/entry') 11 | obj.add_attr('vrf-id', 0) 12 | if version == 'ipv4': 13 | obj.add_attr('af', socket.AF_INET) 14 | elif version == 'ipv6': 15 | obj.add_attr('af', socket.AF_INET6) 16 | ip = net.IPNetwork(route_ip) 17 | obj.add_attr_type('route-prefix', version) 18 | obj.add_attr('route-prefix', str(ip.network)) 19 | obj.add_attr('prefix-len', int(ip.prefixlen)) 20 | 21 | nh_addr = '1.1.1.2' 22 | lst = ['nh-list', '0', 'nh-addr'] 23 | obj.add_embed_attr(lst, nh_addr) 24 | obj.add_attr('nh-count', 1) 25 | 26 | print obj.get() 27 | 28 | #Create transaction 29 | cps_update = ('create', obj.get()) 30 | transaction = cps_utils.CPSTransaction([cps_update]) 31 | 32 | #Commit transaction 33 | ret = transaction.commit() 34 | 35 | #Check for failure 36 | if not ret: 37 | raise RuntimeError('Error creating Route') 38 | print 'Successfully created' 39 | -------------------------------------------------------------------------------- /examples/config_acl.py: -------------------------------------------------------------------------------- 1 | #Python code block to configure ACL 2 | 3 | import cps_utils 4 | 5 | #Define the enum map 6 | e_stg = {'INGRESS': 1, 'EGRESS': 2} 7 | e_ftype = {'SRC_MAC': 3, 'DST_MAC': 4, 'SRC_IP': 5, 'DST_IP': 6, 8 | 'IN_PORT': 9, 'DSCP': 21} 9 | e_atype = {'PACKET_ACTION': 3, 'SET_TC': 10} 10 | e_ptype = {'DROP': 1} 11 | 12 | #Register the attribute type with the CPS utility for attributes with non-integer values 13 | type_map = { 14 | 'base-acl/entry/SRC_MAC_VALUE/addr': 'mac', 15 | 'base-acl/entry/SRC_MAC_VALUE/mask': 'mac', 16 | } 17 | for key,val in type_map.items(): 18 | cps_utils.cps_attr_types_map.add_type(key, val) 19 | 20 | #Create the CPS object and populate the attributes 21 | cps_obj = cps_utils.CPSObject(module='base-acl/table') 22 | 23 | #Set the stage and priority 24 | cps_obj.add_attr ('stage', e_stg['INGRESS']) 25 | cps_obj.add_attr ('priority', 99) 26 | 27 | #Define an add operation and object pair to the CPS transaction 28 | cps_trans = cps_utils.CPSTransaction([cps_update]) 29 | 30 | #Verify the return value 31 | r = cps_trans.commit() 32 | if not r: 33 | raise RuntimeError ("Error creating ACL Table") 34 | -------------------------------------------------------------------------------- /examples/c_template_event_publisher_application.c: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | Template for an event publish function. 3 | 4 | *******************************************************************/ 5 | 6 | cps_api_return_code_t event_publish(cps_api_object_t event_obj) 7 | { 8 | static bool init_flag = false; 9 | static cps_api_event_service_handle_t handle; 10 | 11 | 12 | if (!init_flag) { 13 | /* Not initialized 14 | => Connect to CPS event subsystem 15 | */ 16 | if (cps_api_event_service_init() != cps_api_ret_code_OK) { 17 | return (cps_api_ret_code_ERR); 18 | } 19 | 20 | 21 | if (cps_api_event_client_connect(&handle) != 22 | cps_api_ret_code_OK 23 | ) { 24 | return (cps_api_ret_code_ERR); 25 | } 26 | 27 | /* Mark as initialized */ 28 | init_flag = true; 29 | } 30 | 31 | cps_api_return_code_t result; 32 | 33 | /* Publish the given object */ 34 | result = cps_api_event_publish(handle, event_obj); 35 | 36 | /* Consume the given object */ 37 | cps_api_object_delete(event_obj); 38 | 39 | return (result); 40 | } 41 | 42 | -------------------------------------------------------------------------------- /examples/publish_events.c: -------------------------------------------------------------------------------- 1 | #include "cps_api_events.h" 2 | #include "cps_api_object.h" 3 | #include "dell-base-phy-interface.h" 4 | #include "cps_class_map.h" 5 | #include "cps_api_object_key.h" 6 | 7 | 8 | #include 9 | #include 10 | 11 | 12 | bool cps_pub_intf_event() { 13 | 14 | 15 | static cps_api_event_service_handle_t handle; 16 | if (cps_api_event_service_init() != cps_api_ret_code_OK) { 17 | return false; 18 | } 19 | if (cps_api_event_client_connect(&handle) != cps_api_ret_code_OK) { 20 | return false; 21 | } 22 | 23 | 24 | //Create and intialize the key 25 | cps_api_key_t key; 26 | cps_api_key_from_attr_with_qual(&key, BASE_PORT_INTERFACE_OBJ, cps_api_qualifier_OBSERVED); 27 | 28 | // Create the object 29 | cps_api_object_t obj = cps_api_object_create(); 30 | 31 | 32 | if(obj == NULL){ 33 | return false; 34 | } 35 | 36 | 37 | // Add attributes to the object 38 | cps_api_object_attr_add_u32(obj,BASE_PORT_INTERFACE_IFINDEX, if_nametoindex("e101-001-0")); 39 | 40 | 41 | //Set the Key to the object 42 | cps_api_object_set_key(obj,&key); 43 | 44 | //Publish the object 45 | if(cps_api_event_publish(handle,obj)!= cps_api_ret_code_OK){ 46 | cps_api_object_delete(obj); 47 | return false; 48 | } 49 | // Delete the object 50 | cps_api_object_delete(obj); 51 | return true; 52 | 53 | } 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /examples/register_for_events.c: -------------------------------------------------------------------------------- 1 | #include "cps_api_events.h" 2 | #include "cps_api_object.h" 3 | #include "dell-base-phy-interface.h" 4 | #include "cps_class_map.h" 5 | #include "cps_api_object_key.h" 6 | 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | 13 | //Callback for the interface event handling 14 | static bool cps_if_event_cb(cps_api_object_t obj, void *param){ 15 | 16 | char buf[1024]; 17 | cps_api_object_to_string(obj,buf,sizeof(buf)); 18 | printf("Object Received %s \n",buf); 19 | return true; 20 | } 21 | 22 | bool cps_reg_intf_events(){ 23 | 24 | 25 | // Initialize the event service 26 | if (cps_api_event_service_init() != cps_api_ret_code_OK) { 27 | return false; 28 | } 29 | // Initialize the event handling thread 30 | if (cps_api_event_thread_init() != cps_api_ret_code_OK) { 31 | return false; 32 | } 33 | 34 | 35 | //Create and initialize the key 36 | cps_api_key_t key; 37 | cps_api_key_from_attr_with_qual(&key, BASE_PORT_INTERFACE_OBJ, cps_api_qualifier_OBSERVED); 38 | 39 | //Create the registration object 40 | cps_api_event_reg_t reg; 41 | memset(®,0,sizeof(reg)); 42 | 43 | reg.number_of_objects = 1; 44 | reg.objects = &key; 45 | 46 | 47 | // Register to receive events for key created above 48 | if (cps_api_event_thread_reg(®, cps_if_event_cb,NULL)!=cps_api_ret_code_OK) { 49 | return false; 50 | } 51 | 52 | 53 | //Wait for the events 54 | while(1){ 55 | sleep(1); 56 | } 57 | 58 | return true; 59 | 60 | } 61 | -------------------------------------------------------------------------------- /examples/create_acl.py: -------------------------------------------------------------------------------- 1 | #Python code block to create ACL entry to drop all packets 2 | #received on specific port from specific source MAC address 3 | 4 | import cps_utils 5 | import nas_os_utils 6 | 7 | #Define the enum name to number map 8 | e_stg = {'INGRESS': 1, 'EGRESS': 2} 9 | e_ftype = {'SRC_MAC': 3, 'DST_MAC': 4, 'SRC_IP': 5, 'DST_IP': 6, 'IN_PORT': 9, 'DSCP': 21} 10 | e_atype = {'PACKET_ACTION': 3, 'SET_TC': 10} 11 | e_ptype = {'DROP': 1} 12 | 13 | #Register the attribute type with the CPS utility for non-integer values 14 | type_map = { 15 | 'base-acl/entry/SRC_MAC_VALUE/addr': 'mac', 16 | 'base-acl/entry/SRC_MAC_VALUE/mask': 'mac', 17 | } 18 | for key,val in type_map.items(): 19 | cps_utils.cps_attr_types_map.add_type(key, val) 20 | 21 | #Create the CPS object and populate the attributes 22 | cps_obj = cps_utils.CPSObject(module='base-acl/table') 23 | 24 | #Set the stage and priority 25 | cps_obj.add_attr('stage', e_stg['INGRESS']) 26 | cps_obj.add_attr('priority', 99) 27 | 28 | #Populate the leaf-list attribute 29 | cps_obj.add_list ('allowed-match-fields', [e_ftype['SRC_MAC'], e_ftype['DST_IP'], e_ftype['DSCP'], e_ftype['IN_PORT']]) 30 | 31 | #Define the CPS object 32 | cps_update = ('create', cps_obj.get()) 33 | 34 | #Define an add operation and object pair to the CPS transaction 35 | cps_trans = cps_utils.CPSTransaction([cps_update]) 36 | 37 | #Verify return value 38 | ret = cps_trans.commit() 39 | if not ret: 40 | raise RuntimeError ("Error creating ACL Table") 41 | ret = cps_utils.CPSObject (module='base-acl/table', obj=r[0]['change']) 42 | 43 | #Retrieve the CPS objectID from the ACL table 44 | cps_get_val = cps_utils.CPSObject (module='base-acl/table', obj=r[0]['change']) 45 | tbl_id = ret.get_attr_data ('id') 46 | print "Successfully created ACL Table " + str(tbl_id) 47 | -------------------------------------------------------------------------------- /examples/delete_mac_table_entry.c: -------------------------------------------------------------------------------- 1 | #include "cps_api_object.h" 2 | #include "dell-base-l2-mac.h" 3 | #include "cps_class_map.h" 4 | #include "cps_api_object_key.h" 5 | 6 | 7 | #include 8 | #include 9 | 10 | 11 | bool cps_delete_mac(){ 12 | // Create and initialize the transaction object cps_api_transaction_params_t tran; 13 | if (cps_api_transaction_init(&tran) != cps_api_ret_code_OK ){ 14 | return false; 15 | } 16 | 17 | 18 | // Create and initialize the key cps_api_key_t key; 19 | cps_api_key_from_attr_with_qual(&key, BASE_MAC_TABLE_OBJ, cps_api_qualifier_TARGET); 20 | 21 | 22 | // Create the object 23 | cps_api_object_t obj = cps_api_object_create(); 24 | 25 | if(obj == NULL ){ cps_api_transaction_close(&tran); return false; 26 | } 27 | 28 | 29 | // Set the key for the object 30 | cps_api_object_set_key(obj,&key); 31 | 32 | // Add attributes mandatory to create MAC address entry 33 | uint8_t mac_addr[6] = {0x0,0xa,0xb,0xc,0xd,0xe}; 34 | 35 | 36 | 37 | uint16_t vlan_id = 131; 38 | 39 | 40 | cps_api_object_attr_add(obj,BASE_MAC_TABLE_MAC_ADDRESS, mac_addr, sizeof(hal_mac_addr_t)); cps_api_object_attr_add_u32(obj,BASE_MAC_TABLE_IFINDEX,if_nametoindex("e101-001-0") ); cps_api_object_attr_add_u16(obj,BASE_MAC_TABLE_VLAN,vlan_id); 41 | 42 | // Add the object along with the operation to transaction if(cps_api_delete(&tran,obj) != cps_api_ret_code_OK ){ 43 | cps_api_delete_object(obj); 44 | return false; 45 | } 46 | 47 | 48 | // Commit the transaction 49 | if(cps_api_commit(&tran) != cps_api_ret_code_OK ) { 50 | cps_api_transaction_close(&tran); 51 | return false; 52 | } 53 | 54 | // Cleanup the Transaction 55 | cps_api_transaction_close(&tran); 56 | 57 | return true; 58 | } 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /examples/python_server_template.py: -------------------------------------------------------------------------------- 1 | #Python code block for CPS server application 2 | 3 | import time import cps 4 | import cps_utils 5 | 6 | #Define the get callback handler function 7 | def get_callback(methods, params): 8 | 9 | #Append an object to the response, echoing back the key 10 | #from the request, and supplying some attributes 11 | params[ list ].append({ key : params[ filter ][ key ], 12 | data : { attr_1 : value_1 , 13 | attr_n : value_n 14 | } 15 | } 16 | ) 17 | 18 | return True 19 | 20 | #Define the transaction callback handler function 21 | def transaction_callback(methods, params): 22 | if params[ operation ] == set : 23 | #Set operation requested 24 | #Extract the attributes from the request object attr_1 = params[ change ][ data ][ attr_1 ] 25 | attr_n = params[ change ][ data ][ attr_n ] 26 | 27 | #Do something with them -- program hardware, 28 | #update the configuration, etc. 29 | return True 30 | if params[ operation ] == create : 31 | return True 32 | 33 | if params[ operation ] == delete : 34 | return True 35 | 36 | if params[ operation ] == action : 37 | return True 38 | 39 | return False 40 | 41 | #Obtain a handle to the CPS API service 42 | handle = cps.obj_init() 43 | 44 | #Register the above handlers to be run when a request is received 45 | #for the given key 46 | cps.obj_register(handle, key, 47 | { get : get_callback, 48 | transaction : transaction_callback 49 | } 50 | ) 51 | 52 | #Let the handlers run 53 | while True: 54 | time.sleep(1000) 55 | -------------------------------------------------------------------------------- /examples/create_mac_table_entry.c: -------------------------------------------------------------------------------- 1 | #include "cps_api_object.h" 2 | #include "dell-base-l2-mac.h" 3 | #include "cps_class_map.h" 4 | #include "cps_api_object_key.h" 5 | 6 | 7 | #include 8 | #include 9 | 10 | 11 | bool cps_create_mac(){ 12 | 13 | 14 | // Create and initialize the transaction object 15 | cps_api_transaction_params_t tran; 16 | 17 | if (cps_api_transaction_init(&tran) != cps_api_ret_code_OK ){ 18 | return false; 19 | } 20 | 21 | 22 | // Create and initialize the key cps_api_key_t key; 23 | cps_api_key_from_attr_with_qual(&key, BASE_MAC_TABLE_OBJ, cps_api_qualifier_TARGET); 24 | 25 | 26 | // Create the object 27 | cps_api_object_t obj = cps_api_object_create(); 28 | 29 | if(obj == NULL ){ 30 | cps_api_transaction_close(&tran); 31 | return false; 32 | } 33 | 34 | 35 | // Set the key for the obejct 36 | cps_api_object_set_key(obj,&key); 37 | 38 | // Add attributes mandatory to create MAC address entry 39 | uint8_t mac_addr[6] = {0x0,0xa,0xb,0xc,0xd,0xe}; uint16_t vlan_id = 100; 40 | 41 | cps_api_object_attr_add(obj,BASE_MAC_TABLE_MAC_ADDRESS, mac_addr, sizeof(hal_mac_addr_t)); 42 | cps_api_object_attr_add_u32(obj,BASE_MAC_TABLE_IFINDEX,if_nametoindex("e101-001-0") ); 43 | 44 | 45 | 46 | cps_api_object_attr_add_u16(obj,BASE_MAC_TABLE_VLAN,vlan_id); 47 | 48 | 49 | // Add the object along with the operation to transaction 50 | if(cps_api_create(&tran,obj) != cps_api_ret_code_OK ){ 51 | cps_api_object_delete(obj); 52 | return false; 53 | } 54 | 55 | 56 | // Commit the transaction 57 | if(cps_api_commit(&tran) != cps_api_ret_code_OK ) { 58 | cps_api_transaction_close(&tran); 59 | return false; 60 | } 61 | 62 | // Cleanup the Transaction 63 | cps_api_transaction_close(&tran); 64 | 65 | return true; 66 | } 67 | 68 | -------------------------------------------------------------------------------- /examples/get_mac_table_entry.c: -------------------------------------------------------------------------------- 1 | #include "cps_api_object.h" 2 | #include "dell-base-l2-mac.h" 3 | #include "cps_class_map.h" 4 | #include "cps_api_object_key.h" 5 | 6 | 7 | #include 8 | 9 | 10 | bool cps_get_mac(){ 11 | 12 | 13 | // Create and initialize the Get object 14 | cps_api_get_params_t gp; cps_api_get_request_init(&gp); 15 | 16 | // Create a new object and append it to get request's filter object list 17 | cps_api_object_t obj = cps_api_object_list_create_obj_and_append(gp.filters); 18 | if(obj == NULL){ 19 | cps_api_get_request_close(&gp); 20 | return false; 21 | } 22 | 23 | 24 | 25 | // Create, initialize and set the key for object 26 | cps_api_key_t key; 27 | cps_api_key_from_attr_with_qual(&key, BASE_MAC_QUERY_OBJ, cps_api_qualifier_TARGET); 28 | cps_api_object_set_key(obj,&key); 29 | 30 | 31 | //Perform a get request bool rc=false; 32 | if (cps_api_get(&gp)==cps_api_ret_code_OK) { 33 | rc = true; 34 | size_t mx = cps_api_object_list_size(gp.list); 35 | for (size_t ix = 0 ; ix < mx ; ++ix ) { 36 | cps_api_object_t obj = cps_api_object_list_get(gp.list,ix); 37 | cps_api_object_attr_t vlan_id = cps_api_object_attr_get(obj,BASE_MAC_QUERY_VLAN); 38 | cps_api_object_attr_t ifindex = cps_api_object_attr_get(obj,BASE_MAC_QUERY_IFINDEX); 39 | cps_api_object_attr_t mac_addr = cps_api_object_attr_get(obj,BASE_MAC_QUERY_MAC_ADDRESS); 40 | 41 | printf("VLAN ID %d\n",cps_api_object_attr_data_u16(vlan_id)); 42 | printf("Ifindex %d\n",cps_api_object_attr_data_u32(ifindex)); 43 | char mt[6]; 44 | char mac_string[20]; 45 | memcpy(mt, cps_api_object_attr_data_bin(mac_addr), 6); 46 | sprintf(mac_string, "%x:%x:%x:%x:%x:%x", mt[0], mt[1], mt[2], mt[3], mt[4], mt[5]); 47 | printf("MAC Address %s\n",mac_string); 48 | } 49 | } 50 | 51 | // Close the get the request 52 | cps_api_get_request_close(&gp); 53 | return rc; 54 | } 55 | 56 | 57 | -------------------------------------------------------------------------------- /examples/remove_mac_table_entries_from_multiple_vlans.c: -------------------------------------------------------------------------------- 1 | #include "cps_api_object.h" 2 | #include "dell-base-l2-mac.h" 3 | #include "cps_class_map.h" 4 | #include "cps_api_object_key.h" 5 | 6 | 7 | #include 8 | #include 9 | 10 | 11 | bool cps_flush_mac(){ 12 | 13 | // Create and initialize the transaction object 14 | cps_api_transaction_params_t tran; 15 | if (cps_api_transaction_init(&tran) != cps_api_ret_code_OK ){ 16 | return false; 17 | } 18 | 19 | // Create and initialize the key 20 | cps_api_key_t key; 21 | cps_api_key_from_attr_with_qual(&key, BASE_MAC_FLUSH_OBJ, cps_api_qualifier_TARGET); 22 | 23 | 24 | // Create the object 25 | cps_api_object_t obj = cps_api_object_create(); 26 | 27 | 28 | if(obj == NULL ){ 29 | cps_api_transaction_close(&tran); 30 | return false; 31 | } 32 | 33 | // Set the key for the obejct 34 | cps_api_object_set_key(obj,&key); 35 | 36 | // Add attributes to Flush MAC entries 37 | cps_api_attr_id_t ids[3] = {BASE_MAC_FLUSH_INPUT_FILTER,0, BASE_MAC_FLUSH_INPUT_FILTER_VLAN }; 38 | const int ids_len = sizeof(ids)/sizeof(ids[0]); 39 | 40 | 41 | uint16_t vlan_list[3]={1,2,3}; 42 | for(unsigned int ix=0; ix Connect to CPS event subsystem 17 | */ 18 | 19 | 20 | if (cps_api_event_service_init() != cps_api_ret_code_OK) { 21 | return (cps_api_ret_code_ERR); 22 | } 23 | 24 | 25 | if (cps_api_event_client_connect(&handle) != 26 | cps_api_ret_code_OK 27 | ) { 28 | return (cps_api_ret_code_ERR); 29 | } 30 | 31 | /* Mark as initialized */ 32 | 33 | init_flag = true; 34 | } 35 | 36 | cps_api_return_code_t result; 37 | 38 | 39 | 40 | 41 | /* Publish the given object */ 42 | 43 | 44 | result = cps_api_event_publish(handle, event_obj); 45 | 46 | 47 | /* Consume the given object */ 48 | 49 | 50 | cps_api_object_delete(event_obj); 51 | 52 | return (result); 53 | } 54 | 55 | /****************************************************************** 56 | Python Template: CPS event publisher application 57 | ******************************************************************/ 58 | 59 | import cps 60 | import cps_utils 61 | 62 | 63 | handle = cps.event_connect() 64 | 65 | 66 | obj = cps_utils.CPSObject('base-port/interface',qual='observed', data= {"ifindex":23}) 67 | 68 | cps.event_send(handle, obj.get()) 69 | 70 | 71 | 72 | /****************************************************************** 73 | C Template: Event Subscriber Application 74 | 75 | This template illustrates the initialization of the event service 76 | and event processing thread, registration of the event handler 77 | function and event processing callback. The key list specified 78 | in the registration is used to determine the events that are 79 | delivered to this application (in this case, the list contains 80 | a single element). 81 | ******************************************************************/ 82 | 83 | bool event_handler(cps_api_object_t object, void *context) 84 | { 85 | /* Extract key and attributes of received object */ 86 | /* Do something with that information */ 87 | } 88 | 89 | cps_api_return_code_t event_subscribe() 90 | { 91 | /* Connect to CPS API event service */ 92 | 93 | if (cps_api_event_service_init() != cps_api_ret_code_OK) { 94 | return (cps_api_ret_code_ERR); 95 | } 96 | 97 | if (cps_api_event_thread_init() != cps_api_ret_code_OK) { 98 | return (cps_api_ret_code_ERR); 99 | } 100 | 101 | /* Register event handler function */ 102 | cps_api_key_t key; cps_api_key_init(&key, ); cps_api_event_reg_t reg; reg.objects = key; 103 | reg.number_of_objects = 1; 104 | 105 | if (cps_api_event_thread_reg(®, event_handler, 0) 106 | != cps_api_ret_code_OK 107 | ) { 108 | 109 | /* Failed to register handler */ 110 | return (cps_api_ret_code_ERR); 111 | } 112 | 113 | /* Indicate success */ 114 | return (cps_api_reg_code_OK); 115 | } 116 | -------------------------------------------------------------------------------- /examples/c_client_template.c: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | Template to perform a CPS API GET request. 3 | *******************************************************************/ 4 | cps_api_return_code_t do_get_request() 5 | { 6 | /* Allocate and initialize the get request structure */ 7 | cps_api_get_params_t get_req; 8 | 9 | if (cps_api_get_request_init(&get_req) != cps_api_ret_code_OK) { 10 | /* Failed to initialize get request 11 | => Indicate error 12 | */ 13 | 14 | return (cps_api_ret_code_ERR); 15 | } 16 | 17 | /* Assume failure response */ 18 | cps_api_return_code_t result = cps_api_ret_code_ERR; 19 | do { 20 | /* Allocate the request object and add it to the get request 21 | */ 22 | cps_api_object_t request_obj; 23 | request_obj = cps_api_object_list_create_obj_and_append( 24 | get_req.filters 25 | ); 26 | if (request_obj == CPS_API_OBJECT_NULL) { 27 | /* Failed to allocate response object and add it to get request 28 | */ 29 | break; 30 | } 31 | 32 | /* Set the key and key attributes for the request object. 33 | The actual object key and key attribute ids, types and values 34 | will of course depend on which object is being requested; 35 | such dependent values are indicated by ellipses ... below. 36 | Consult the data model for the desired object. 37 | */ 38 | 39 | 40 | cps_api_key_from_attr_with_qual(cps_api_object_key( 41 | request_obj 42 | ), 43 | ... 44 | ); 45 | 46 | 47 | cps_api_set_key_data(request_obj, ...); 48 | ... cps_api_set_key_data(request_obj, ...); 49 | 50 | 51 | cps_api_object_attr_add_...(request_obj, ...); 52 | ... cps_api_object_attr_add_...(request_obj, ...); 53 | 54 | 55 | /* Do the GET request */ 56 | if (cps_api_get(&get_req) != cps_api_ret_code_OK) { 57 | /* GET request failed */ 58 | break; 59 | } 60 | 61 | /* Extract the response object */ 62 | cps_api_object_t response_obj; 63 | 64 | response_obj = cps_api_object_list_get(get_req.list, 0); 65 | if (response_obj == CPS_API_OBJECT_NULL) { 66 | /* Failed to extract the response object */ 67 | break; 68 | } 69 | 70 | /* Extract the desired object attributes from the response object. 71 | (The actual object attributes will depend on the nature of the response object; 72 | such dependent values are indicated by ellipses below. 73 | Consult the appropriate data model for details.) 74 | */ 75 | 76 | cps_api_object_attr_t attr; 77 | attr = cps_api_object_attr_get(response_obj, ); 78 | if (attr == CPS_API_ATTR_NULL) { 79 | /* Failed to extract expected attribute */ 80 | break; 81 | } 82 | 83 | /* Get the value for the attribute */ 84 | = cps_api_object_attr_data_...(attr); 85 | 86 | 87 | /* Do something with the extracted value */ 88 | 89 | /* Indicate success */ 90 | result = cps_api_ret_code_OK; 91 | } while (0); 92 | 93 | 94 | cps_api_get_request_close(&get_req); 95 | return (result); 96 | } 97 | 98 | 99 | 100 | 101 | /****************************************************************** 102 | Template to perform a CPS API SET 103 | *******************************************************************/ 104 | 105 | 106 | cps_api_return_code_t do_set_request() 107 | { 108 | cps_api_transaction_params_t xact ; 109 | if (cps_api_transaction_init(&xact) != cps_api_ret_code_OK) { 110 | return (cps_api_ret_code_ERR); 111 | } 112 | 113 | 114 | cps_api_return_code_t result = cps_api_ret_code_ERR; 115 | do { 116 | cps_api_object_t request_obj; 117 | 118 | request_obj = cps_api_object_create() ; 119 | if (request_obj == CPS_API_OBJECT_NULL) { 120 | break; 121 | } 122 | 123 | 124 | /* Set key and attributes in request object */ 125 | cps_api_key_from_attr_with_qual(cps_api_object_key( 126 | request_obj 127 | ), 128 | 129 | ); 130 | 131 | 132 | cps_api_set_key_data(request_obj, ...); 133 | ... cps_api_set_key_data(request_obj, ...); 134 | 135 | 136 | cps_api_object_attr_add_...(request_obj, ...); 137 | ... cps_api_object_attr_add_...(request_obj, ...); 138 | 139 | 140 | if (cps_api_set(&xact, request_obj) != cps_api_ret_code_OK) { 141 | cps_api_object_delete(request_obj); 142 | 143 | break; 144 | } 145 | 146 | result = cps_api_commit(&xact); 147 | } while (0); 148 | 149 | 150 | cps_api_transaction_close(&xact); 151 | 152 | return (result); 153 | } 154 | -------------------------------------------------------------------------------- /examples/c_template_server_application.c: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | Template CPS API object server read handler function 3 | This function is invoked by the CPS API service when a GET request 4 | is placed for a registered CPS API object. The binding of CPS 5 | API object key to the read handler function is done below. 6 | *******************************************************************/ 7 | 8 | cps_api_return_code_t xyz_read( 9 | void *context, 10 | cps_api_get_params_t *param, 11 | size_t key_idx 12 | ) 13 | { 14 | /* Allocate a response object, and add to response */ 15 | cps_api_object_t response_obj; 16 | response_obj = cps_api_object_list_create_obj_and_append( 17 | param->list 18 | ); 19 | 20 | if (response_obj == CPS_API_OBJECT_NULL) { 21 | /* Failed to allocate response object 22 | => Indicate an error 23 | */ 24 | return (cps_api_ret_code_ERR); 25 | } 26 | 27 | /* Fill in response object */ 28 | cps_api_key_from_attr_with_qual(cps_api_object_key(response_obj), 29 | ... 30 | ); 31 | 32 | cps_api_set_key_data(response_obj, ...); 33 | ... cps_api_set_key_data(response_obj, ...); 34 | 35 | cps_api_object_attr_add_...(response_obj, ...); 36 | 37 | ... cps_api_object_attr_add_...(response_obj, ...); 38 | 39 | /* Indicate GET response successful */ 40 | return (cps_api_ret_code_OK);} 41 | 42 | /****************************************************************** 43 | Template CPS API object server write handler function 44 | This function is invoked by the CPS API service when a SET request 45 | is placed for a registered CPS API object. The binding of CPS 46 | API object key to the write handler function is done below. 47 | *******************************************************************/ 48 | 49 | cps_api_return_code_t xyz_write( 50 | void *context, 51 | cps_api_transaction_params_t *param, 52 | size_t index_of_element_being_updated 53 | ) 54 | 55 | { 56 | /* Extract the object given in the request */ 57 | cps_api_object_t request_obj; 58 | request_obj = cps_api_object_list_get( 59 | param->change_list, 60 | index_of_element_being_updated 61 | ); 62 | 63 | if (request_obj == CPS_API_OBJECT_NULL) { 64 | /* Failed to extract request object 65 | => Indicate error 66 | */ 67 | return (cps_api_ret_code_ERR); 68 | } 69 | 70 | /* Assume error response */ 71 | cps_api_return_code_t result = cps_api_ret_code_ERR; 72 | 73 | /* Determine the type of write operation */ 74 | switch (cps_api_object_type_operation( 75 | cps_api_object_key(request_obj) 76 | ) 77 | ) { 78 | 79 | case cps_api_oper_SET: 80 | 81 | /* SET operation requested */ 82 | /* Create the rollback object, i.e. an object to return 83 | containing the old values for any attributes set, and 84 | add to transaction 85 | */ 86 | 87 | cps_api_object_t rollback_obj; 88 | rollback_obj = cps_api_object_list_create_obj_and_append( 89 | param->prev 90 | ); 91 | 92 | if (rollback_obj == CPS_API_OBJECT_NULL) { 93 | /* Failed to create rollback object */ 94 | break; 95 | 96 | } 97 | 98 | /* Assume SET successful */ 99 | result = cps_api_ret_code_OK; 100 | 101 | /* For each attribute given in the request, */ 102 | cps_api_object_it_t attr_iter; 103 | 104 | cps_api_object_it_begin(request_obj, &attr_iter); 105 | while (cps_api_object_it_valid(&attr_iter)) { 106 | 107 | /* Get the attribute id from the attribute iterator */ 108 | cps_api_attr_id_t attr_id; 109 | 110 | attr_id = cps_api_object_attr_id(attr_iter.attr); 111 | 112 | /* Update the rollback object with the old value 113 | of the attribute 114 | */ 115 | 116 | cps_api_object_attr_add_...(rollback_obj, 117 | attr_id, 118 | 119 | ); 120 | 121 | /* Extract the attribute from the request object */ 122 | cps_api_object_attr_t attr; 123 | 124 | attr = cps_api_object_attr_get(request_obj, attr_id); 125 | 126 | if (attr == CPS_API_ATTR_NULL)) { 127 | /* Failed to extract attribute 128 | => Indicate error 129 | */ 130 | result = cps_api_ret_code_ERR; 131 | continue; 132 | } 133 | 134 | /* Extract the value of the attribute in the request 135 | object 136 | */ 137 | value = cps_api_object_attr_data_....(attr); 138 | 139 | /* Validate the requested attribute value, its 140 | consistency with other attributes and/or existing 141 | configuration, etc. 142 | */ 143 | 144 | } 145 | 146 | /* If the whole request has been validated, do something with 147 | the extracted values program hardware, 148 | take some action, etc. 149 | */ 150 | break; 151 | 152 | case cps_api_oper_CREATE: 153 | /* CREATE operation requested */ 154 | break; 155 | 156 | case cps_api_oper_DELETE: 157 | /* DELETE operation requested */ 158 | break; 159 | 160 | case cps_api_oper_ACTION: 161 | /* ACTION operation requested */ 162 | break; 163 | 164 | default: 165 | /* Invalid SET request type */ 166 | break; 167 | } 168 | 169 | return (result); 170 | 171 | } 172 | 173 | /********************************************************** 174 | Template CPS API object server rollback handler function 175 | *******************************************************************/ 176 | cps_api_return_code_t xyz_rollback( 177 | void *context, 178 | cps_api_transaction_params_t *param, 179 | size_t index_of_element_being_updated 180 | ) 181 | { 182 | /* Extract object to be rolled back */ 183 | cps_api_object_t rollback_obj; 184 | rollback_obj = cps_api_object_list_get( 185 | param->prev, 186 | index_of_element_being_updated 187 | ); 188 | 189 | if (rollback_obj == CPS_API_OBJECT_NULL) { 190 | /* Failed to extract rollback object 191 | => Indicate failure 192 | */ 193 | 194 | return (cps_api_ret_code_ERR); 195 | 196 | } 197 | 198 | /* For each attribute to be rolled back, */ 199 | cps_api_object_it_t attr_iter; 200 | 201 | cps_api_object_it_begin(rollback_obj, &attr_iter); 202 | while (cps_api_object_it_valid(&attr_iter)) { 203 | 204 | /* Get the attribute id from the attribute iterator */ 205 | cps_api_attr_id_t attr_id; 206 | 207 | attr_id = cps_api_object_attr_id(attr_iter.attr); 208 | /* Extract the attribute from the rollback object */ 209 | 210 | cps_api_object_attr_t attr; 211 | 212 | attr = cps_api_object_attr_get(rollback_obj, attr_id); 213 | 214 | if (attr == CPS_API_ATTR_NULL)) { 215 | 216 | /* Failed to extract attribute 217 | => Indicate error 218 | */ 219 | 220 | result = cps_api_ret_code_ERR; 221 | continue; 222 | 223 | } 224 | 225 | /* Extract the value of the attribute in the rollback 226 | object 227 | */ 228 | value = cps_api_object_attr_data_....(attr); 229 | 230 | /* Apply attribute value */ 231 | 232 | } 233 | 234 | return (result); 235 | } 236 | 237 | /****************************************************************** 238 | Template mainline function for a CPS API object server 239 | This function registers with the CPS API service, and registers handler 240 | functions to be invoked by the CPS API service when CPS API requests 241 | are made for certain CPS API objects. 242 | *******************************************************************/ 243 | 244 | cps_api_return_code_t init(void) 245 | { /* Obtain a handle for the CPS API service */ 246 | 247 | cps_api_operation_handle_t cps_hdl; 248 | 249 | if (cps_api_operation_subsystem_init(&cps_hdl, 1) != 250 | cps_api_ret_code_OK 251 | ) { 252 | 253 | /* Failed to obtain handle for CPS API service 254 | => Indicate an error 255 | */ 256 | return (cps_api_ret_code_ERR); 257 | } 258 | 259 | /* Allocate a CPS API object registration structure */ 260 | cps_api_registration_functions_t reg; 261 | 262 | /* Assign the key of the CPS API object to be registered */ 263 | cps_api_key_init(®.key, ); 264 | 265 | /* Assign the handler functions to be invoked for this object */ 266 | reg._read_function = xyz_read; 267 | reg._write_function = xyz_write; 268 | reg._rollback_function = xyz_rollback; 269 | 270 | /* Use obtained handle for CPS API service */ 271 | reg.handle = cps_hdl; 272 | 273 | /* Perform the object registration */ 274 | if (cps_api_register(®) != cps_api_ret_code_OK) { 275 | 276 | /* Failed to register handler function with CPS API service 277 | => Indicate an error 278 | */ 279 | return (cps_api_ret_code_ERR); 280 | } 281 | 282 | /* All done */ 283 | return (cps_api_ret_code_OK); 284 | } 285 | --------------------------------------------------------------------------------