def of_demo_3(): f = "cfg.yml" d = {} if(load_dict_from_file(f, d) is False): print("Config file '%s' read error: " % f) exit() try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] nodeName = d['nodeName'] rundelay = d['rundelay'] except: print ("Failed to get Controller device attributes") exit(0) print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print ("<<< Demo 3 Start") print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print ("\n") print ("<<< Creating Controller instance") time.sleep(rundelay) ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd, None) print ("'Controller':") print ctrl.brief_json() print ("\n") print ("<<< Get detailed information about ports on OpenFlow node '%s'" % nodeName) time.sleep(rundelay) ofswitch = OFSwitch(ctrl, nodeName) result = ofswitch.get_ports_list() status = result.get_status() if(status.eq(STATUS.OK)): ports = result.get_data() for port in ports: result = ofswitch.get_port_detail_info(port) status = result.get_status() if(status.eq(STATUS.OK)): print ("Port '%s' info:" % port) info = result.get_data() print json.dumps(info, indent=4) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print (">>> Demo End") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def nc_demo_7(): f = "cfg1.yml" d = {} if(load_dict_from_file(f, d) is False): print("Config file '%s' read error: " % f) exit() try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] rundelay = d['rundelay'] except: print ("Failed to get Controller device attributes") exit(0) print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print ("<<< Demo Start") print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print ("\n") print ("<<< Creating Controller instance") time.sleep(rundelay) ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) print ("'Controller':") print ctrl.to_json() print "\n" print ("<<< Show a particular configuration module on the Controller") moduleType = "opendaylight-rest-connector:rest-connector-impl" moduleName = "rest-connector-default-impl" print (" (module type: %s,\n module name: %s)" % (moduleType, moduleName)) time.sleep(rundelay) result = ctrl.get_module_operational_state(moduleType, moduleName) status = result.get_status() if(status.eq(STATUS.OK)): print "Module:" slist = result.get_data() print json.dumps(slist, default=lambda o: o.__dict__, sort_keys=True, indent=4) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief()) exit(0) print ("\n") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print (">>> Demo End") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def nc_demo_7(): f = "cfg1.yml" d = {} if (load_dict_from_file(f, d) is False): print("Config file '%s' read error: " % f) exit() try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] rundelay = d['rundelay'] except: print("Failed to get Controller device attributes") exit(0) print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print("<<< Demo Start") print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print("\n") print("<<< Creating Controller instance") time.sleep(rundelay) ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) print("'Controller':") print ctrl.to_json() print "\n" print("<<< Show a particular configuration module on the Controller") moduleType = "opendaylight-rest-connector:rest-connector-impl" moduleName = "rest-connector-default-impl" print(" (module type: %s,\n module name: %s)" % (moduleType, moduleName)) time.sleep(rundelay) result = ctrl.get_module_operational_state(moduleType, moduleName) status = result.get_status() if (status.eq(STATUS.OK)): print "Module:" slist = result.get_data() print json.dumps(slist, default=lambda o: o.__dict__, sort_keys=True, indent=4) else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief()) exit(0) print("\n") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print(">>> Demo End") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def nc_demo_2(): f = "cfg1.yml" d = {} if(load_dict_from_file(f, d) is False): print("Config file '%s' read error: " % f) exit() try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] rundelay = d['rundelay'] except: print ("Failed to get Controller device attributes") exit(0) print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print ("<<< Demo Start") print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print ("\n") print ("<<< Creating Controller instance") time.sleep(rundelay) ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) print ("'Controller':") print ctrl.to_json() print "\n" yangModelName = "flow-topology-discovery" yangModelVerson = "2013-08-19" print ("<<< Retrieve '%s' YANG model definition " "from the Controller" % yangModelName) time.sleep(rundelay) nodeName = "controller-config" result = ctrl.get_schema(nodeName, yangModelName, yangModelVerson) status = result.get_status() if(status.eq(STATUS.OK)): print ("YANG model:") schema = result.get_data() print schema else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief()) exit(0) print ("\n") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print (">>> Demo End") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def nc_demo_5(): f = "cfg1.yml" d = {} if (load_dict_from_file(f, d) is False): print("Config file '%s' read error: " % f) exit() try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] rundelay = d['rundelay'] except: print("Failed to get Controller device attributes") exit(0) print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print("<<< Demo Start") print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print("\n") print("<<< Creating Controller instance") time.sleep(rundelay) ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) print("'Controller':") print ctrl.to_json() print "\n" print( "<<< Show list of all NETCONF operations " "supported by the Controller") time.sleep(rundelay) result = ctrl.get_netconf_operations("controller-config") status = result.get_status() if (status.eq(STATUS.OK)): print "NETCONF operations:" slist = result.get_data() print json.dumps(slist, default=lambda o: o.__dict__, sort_keys=True, indent=4) else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief()) exit(0) print("\n") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print(">>> Demo End") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def nc_demo_3(): f = "cfg1.yml" d = {} if (load_dict_from_file(f, d) is False): print("Config file '%s' read error: " % f) exit() try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] rundelay = d['rundelay'] except: print("Failed to get Controller device attributes") exit(0) print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print("<<< Demo Start") print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print("\n") print("<<< Creating Controller instance") time.sleep(rundelay) ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) print("'Controller':") print ctrl.to_json() print "\n" print( "<<< Get list of service provider applications " "available on the Controller") time.sleep(rundelay) result = ctrl.get_service_providers_info() status = result.get_status() if (status.eq(STATUS.OK)): services = result.get_data() print "Service providers:" print json.dumps(services, default=lambda o: o.__dict__, sort_keys=True, indent=4) else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief()) exit(0) print("\n") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print(">>> Demo End") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def nc_demo_4(): f = "cfg1.yml" d = {} if(load_dict_from_file(f, d) is False): print("Config file '%s' read error: " % f) exit() try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] rundelay = d['rundelay'] except: print ("Failed to get Controller device attributes") exit(0) print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print ("<<< Demo Start") print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print ("\n") print ("<<< Creating Controller instance") time.sleep(rundelay) ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) print ("'Controller':") print ctrl.to_json() print "\n" name = "opendaylight-md-sal-binding:binding-data-broker" print ("<<< Get '%s' service provider info" % name) time.sleep(rundelay) result = ctrl.get_service_provider_info(name) status = result.get_status() if(status.eq(STATUS.OK)): print "Service provider:" service = result.get_data() print json.dumps(service, default=lambda o: o.__dict__, sort_keys=True, indent=4) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief()) exit(0) print ("\n") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print (">>> Demo End") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def nc_demo_8(): f = "cfg1.yml" d = {} if(load_dict_from_file(f, d) is False): print("Config file '%s' read error: " % f) exit() try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] rundelay = d['rundelay'] except: print ("Failed to get Controller device attributes") exit(0) print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print ("<<< Demo Start") print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print ("\n") print ("<<< Creating Controller instance") time.sleep(rundelay) ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) print ("'Controller':") print ctrl.to_json() print "\n" print ("<<< Show sessions running on the Controller ") nodeName = "controller-config" time.sleep(rundelay) result = ctrl.get_sessions_info(nodeName) status = result.get_status() if(status.eq(STATUS.OK)): print "Sessions:" slist = result.get_data() print json.dumps(slist, default=lambda o: o.__dict__, sort_keys=True, indent=4) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief()) exit(0) print ("\n") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print (">>> Demo End") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def setUp(self): f = "cfg1.yml" d = {} if not (load_dict_from_file(f, d)): print("Config file '%s' read error: " % f) exit() try: self.ctrlIpAddr = d['ctrlIpAddr'] self.ctrlPortNum = d['ctrlPortNum'] self.ctrlUname = d['ctrlUname'] self.ctrlPswd = d['ctrlPswd'] self.rundelay = d['rundelay'] except: print("Failed to get Controller device attributes") exit(0)
def setUp(self): f = "cfg1.yml" d = {} if not (load_dict_from_file(f, d)): print ("Config file '%s' read error: " % f) exit() try: self.ctrlIpAddr = d["ctrlIpAddr"] self.ctrlPortNum = d["ctrlPortNum"] self.ctrlUname = d["ctrlUname"] self.ctrlPswd = d["ctrlPswd"] self.rundelay = d["rundelay"] except: print ("Failed to get Controller device attributes") exit(0)
def of_demo_40(): f = "cfg.yml" d = {} if (load_dict_from_file(f, d) is False): print("Config file '%s' read error: " % f) exit(0) try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] nodeName = d['nodeName'] rundelay = d['rundelay'] except: print("Failed to get Controller device attributes") exit(0) print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print("<<< Demo 40 Start") print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) ofswitch = OFSwitch(ctrl, nodeName) print("<<< 'Controller': %s, 'OpenFlow' switch: '%s'" % (ctrlIpAddr, nodeName)) first_flow_id = 110 # --------------------------------------------------- # First flow entry # --------------------------------------------------- table_id = 0 flow_id = first_flow_id flow_name = "Modify IP packet example1" priority = 900 cookie = 1300 match_in_port = 10 match_eth_type = ETH_TYPE_IPv4 match_ip_proto = IP_PROTO_TCP match_ipv4_src_addr = "192.1.2.0/24" match_ipv4_dst_addr = "173.194.123.40/32" match_tcp_dst_port = 8080 act_mod_ipv4_src_addr = "212.16.1.8/32" act_mod_ipv4_dst_addr = "52.87.12.11/32" act_mod_tcp_src_port = 8888 act_mod_tcp_dst_port = 9999 act_out_port = 119 print "\n" print("<<< Set OpenFlow flow on the Controller") print( " Match: Input Port (%s)\n" " Ethernet Type (%s)\n" " IP Protocol (%s)\n" " IPv4 Source Address (%s)\n" " IPv4 Destination Address (%s)\n" " TCP Destination Port (%s)" % (match_in_port, hex(match_eth_type), match_ip_proto, match_ipv4_src_addr, match_ipv4_dst_addr, match_tcp_dst_port)) print( " Actions: Modify IPv4 Source Address (%s)\n" " Modify IPv4 Destination Address (%s)\n" " Modify TCP Source Port (%s)\n" " Modify TCP Destination Port (%s)\n" " Output (%s)" % (act_mod_ipv4_src_addr, act_mod_ipv4_dst_addr, act_mod_tcp_src_port, act_mod_tcp_dst_port, act_out_port)) time.sleep(rundelay) # Allocate a placeholder for the Flow Entry flow_entry1 = FlowEntry() # Generic attributes of the Flow Entry flow_entry1.set_flow_table_id(table_id) flow_entry1.set_flow_name(flow_name) flow_entry1.set_flow_id(flow_id) flow_entry1.set_flow_cookie(cookie) flow_entry1.set_flow_priority(priority) flow_entry1.set_flow_hard_timeout(0) flow_entry1.set_flow_idle_timeout(0) # Instructions/Actions for the Flow Entry instruction = Instruction(instruction_order=0) action_order = 0 action = SetNwSrcAction(action_order) action.set_nw_src(act_mod_ipv4_src_addr) instruction.add_apply_action(action) action_order += 1 action = SetNwDstAction(action_order) action.set_nw_dst(act_mod_ipv4_dst_addr) instruction.add_apply_action(action) action_order += 1 action = SetTpSrcAction(action_order) action.set_tp_src(act_mod_tcp_src_port) instruction.add_apply_action(action) action_order += 1 action = SetTpDstAction(action_order) action.set_tp_dst(act_mod_tcp_dst_port) instruction.add_apply_action(action) action_order += 1 action = OutputAction(action_order) action.set_outport(act_out_port) instruction.add_apply_action(action) flow_entry1.add_instruction(instruction) # Match Fields for the Flow Entry match = Match() match.set_in_port(match_in_port) match.set_eth_type(match_eth_type) match.set_ip_proto(match_ip_proto) match.set_ipv4_src(match_ipv4_src_addr) match.set_ipv4_dst(match_ipv4_dst_addr) match.set_tcp_dst(match_tcp_dst_port) flow_entry1.add_match(match) print("\n") print("<<< Flow to send:") print flow_entry1.get_payload() time.sleep(rundelay) result = ofswitch.add_modify_flow(flow_entry1) status = result.get_status() if (status.eq(STATUS.OK)): print("<<< Flow successfully added to the Controller") else: print("\n") print("!!!Demo terminated, reason: %s" % status.detailed()) delete_flows(ofswitch, table_id, range(first_flow_id, flow_id + 1)) exit(0) # --------------------------------------------------- # Second flow entry # --------------------------------------------------- table_id = 0 flow_id += 1 flow_name = "Modify IP packet example2" priority = 900 cookie = 1300 match_in_port = 110 match_eth_type = ETH_TYPE_IPv4 match_ip_proto = IP_PROTO_UDP match_ipv4_src_addr = "10.1.0.0/16" match_ipv4_dst_addr = "168.1.1.101/32" match_udp_dst_port = 1812 act_mod_ipv4_src_addr = "172.101.1.9/32" act_mod_ipv4_dst_addr = "172.101.1.1/32" act_mod_udp_src_port = 5555 act_mod_udp_dst_port = 7777 act_out_port = 120 print "\n" print("<<< Set OpenFlow flow on the Controller") print( " Match: Input Port (%s)\n" " Ethernet Type (%s)\n" " IP Protocol (%s)\n" " IPv4 Source Address (%s)\n" " IPv4 Destination Address (%s)\n" " UDP Destination Port (%s)" % (match_in_port, hex(match_eth_type), match_ip_proto, match_ipv4_src_addr, match_ipv4_dst_addr, match_udp_dst_port)) print( " Actions: Set Field (IPv4 Source Address %s)\n" " Set Field (IPv4 Destination Address %s)\n" " Set Field (UDP Source Port %s)\n" " Set Field (UDP Destination Port %s)\n" " Output (%s)" % (act_mod_ipv4_src_addr, act_mod_ipv4_dst_addr, act_mod_udp_src_port, act_mod_udp_dst_port, act_out_port)) time.sleep(rundelay) # Allocate a placeholder for the Flow Entry flow_entry2 = FlowEntry() # Generic attributes of the Flow Entry flow_entry2.set_flow_table_id(table_id) flow_entry2.set_flow_name(flow_name) flow_entry2.set_flow_id(flow_id) flow_entry2.set_flow_cookie(cookie) flow_entry2.set_flow_priority(priority) flow_entry2.set_flow_hard_timeout(0) flow_entry2.set_flow_idle_timeout(0) # Instructions/Actions for the Flow Entry instruction = Instruction(instruction_order=0) action_order = 0 action = SetFieldAction(action_order) action.set_ipv4_src(act_mod_ipv4_src_addr) instruction.add_apply_action(action) action_order += 1 action = SetFieldAction(action_order) action.set_ipv4_dst(act_mod_ipv4_dst_addr) instruction.add_apply_action(action) action_order += 1 action = SetFieldAction(action_order) action.set_udp_src(act_mod_udp_src_port) instruction.add_apply_action(action) action_order += 1 action = SetFieldAction(action_order) action.set_udp_dst(act_mod_udp_dst_port) instruction.add_apply_action(action) action_order += 1 action = OutputAction(action_order) action.set_outport(act_out_port) instruction.add_apply_action(action) flow_entry2.add_instruction(instruction) # Match Fields for the Flow Entry match = Match() match.set_in_port(match_in_port) match.set_eth_type(match_eth_type) match.set_ip_proto(match_ip_proto) match.set_ipv4_src(match_ipv4_src_addr) match.set_ipv4_dst(match_ipv4_dst_addr) match.set_udp_dst(match_udp_dst_port) flow_entry2.add_match(match) print("\n") print("<<< Flow to send:") print flow_entry2.get_payload() time.sleep(rundelay) result = ofswitch.add_modify_flow(flow_entry2) status = result.get_status() if (status.eq(STATUS.OK)): print("<<< Flow successfully added to the Controller") else: print("\n") print("!!!Demo terminated, reason: %s" % status.detailed()) delete_flows(ofswitch, table_id, range(first_flow_id, flow_id + 1)) exit(0) print("\n") print( "<<< Delete flows from the Controller's cache " "and from the table '%s' on the '%s' node" % (table_id, nodeName)) time.sleep(rundelay) delete_flows(ofswitch, table_id, range(first_flow_id, flow_id + 1)) print("\n") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print(">>> Demo End") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def of_demo_32(): f = "cfg.yml" d = {} if(load_dict_from_file(f, d) is False): print("Config file '%s' read error: " % f) exit(0) try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] rundelay = d['rundelay'] except: print ("Failed to get Controller device attributes") exit(0) openflow_node_ids = [] openflow_nodes = [] print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print ("<<< Demo 32 Start") print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print "\n" ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) print ("<<< Controller '%s:%s'" % (ctrlIpAddr, ctrlPortNum)) time.sleep(rundelay) print "\n".strip() print ("<<< Get OpenFlow switches information") time.sleep(rundelay) inv_obj = None result = ctrl.build_inventory_object() status = result.get_status() if(status.eq(STATUS.OK)): inv_obj = result.get_data() assert(isinstance(inv_obj, Inventory)) else: print ("\n") print ("!!!Error, failed to obtain inventory info, reason: %s" % status.brief().lower()) exit(0) assert(inv_obj) openflow_node_ids = inv_obj.get_openflow_node_ids() for node_id in openflow_node_ids: node = inv_obj.get_openflow_node(node_id) assert(isinstance(node, OpenFlowCapableNode)) openflow_nodes.append(node) print "\n".strip() print ("<<< OpenFlow switches in the inventory store") s1 = 'IP Address' s2 = 'OpenFlow Id' sym = '-' print "\n".strip() print " {0:<15} {1:<30}".format(s1, s2) print " {0:<15} {1:<30}".format(sym*15, sym*30) for node in openflow_nodes: addr = node.get_ip_address() node_id = node.get_id() print " {0:<15} {1:<30}".format(addr, node_id) print "\n".strip() print ("<<< Get Group Table Information") time.sleep(rundelay) for node in openflow_nodes: assert(isinstance(node, OpenFlowCapableNode)) print "\n".strip() switch_id = node.get_id() print (" Switch '%s'") % switch_id print "\n".strip() group_features = node.get_group_features() assert(isinstance(group_features, GroupFeatures)) q = 2 # number of list items to be in a single chunk (output string) s = 'Max groups' alist = group_features.get_max_groups() if alist: chunks = [alist[x:x+q] for x in xrange(0, len(alist), q)] print " %s :" % s, for i in range(0, len(chunks)): n = 0 if i == 0 else len(s) + 19 print "%s%s" % (" "*n, ", ".join(map(str, chunks[i]))) else: print " %s : %s" % (s, "n/a") s = 'Group types' alist = group_features.get_types() if alist: chunks = [alist[x:x+q] for x in xrange(0, len(alist), q)] print " %s :" % s, for i in range(0, len(chunks)): n = 0 if i == 0 else len(s) + 18 print "%s%s" % (" "*n, ", ".join(chunks[i])) else: print " %s : %s" % (s, "n/a") s = 'Capabilities' alist = group_features.get_capabilities() if alist: chunks = [alist[x:x+q] for x in xrange(0, len(alist), q)] print " %s :" % s, for i in range(0, len(chunks)): n = 0 if i == 0 else len(s) + 17 print "%s%s" % (" "*n, ", ".join(chunks[i])) else: print " %s : %s" % (s, "n/a") print "\n".strip() total_num = node.get_groups_total_num() s = 'Num of groups' print " %s : %s" % (s, total_num) s = 'Group IDs' alist = node.get_group_ids() if alist: chunks = [alist[x:x+q] for x in xrange(0, len(alist), q)] print " %s :" % s, for i in range(0, len(chunks)): n = 0 if i == 0 else len(s) + 13 print "%s%s" % (" "*n, ", ".join(map(str, chunks[i]))) else: print " %s : %s" % (s, "") print ("\n") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print (">>> Demo End") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def of_demo_20(): f = "cfg.yml" d = {} if (load_dict_from_file(f, d) is False): print("Config file '%s' read error: " % f) exit() try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] nodeName = d['nodeName'] rundelay = d['rundelay'] except: print("Failed to get Controller device attributes") exit(0) print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print("<<< Demo 20 Start") print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) ofswitch = OFSwitch(ctrl, nodeName) # --- Flow Match: Ethernet Type # IP DSCP # IP ECN # IPv6 Source Address # IPv6 Destination Address # IPv6 Flow Label # ICMPv6 type # ICMPv6 Code # Metadata eth_type = ETH_TYPE_IPv6 ip_dscp = IP_DSCP_CS7 # 'Class Selector' = 'Network' ip_ecn = IP_ECN_CE # 'Congestion Encountered' ipv6_src = "1234:5678:9ABC:DEF0:FDCD:A987:6543:210F/76" ipv6_dst = "2000:2abc:edff:fe00::3456/94" ipv6_flabel = 15 ip_proto = IP_PROTO_ICMPv6 icmpv6_type = 1 # 'Destination Unreachable' icmpv6_code = 3 # 'Address Unreachable' metadata = "0x0123456789ABCDEF" # --- Flow Actions: Output (CONTROLLER) output_port = "CONTROLLER" print("<<< 'Controller': %s, 'OpenFlow' switch: '%s'" % (ctrlIpAddr, nodeName)) print "\n" print("<<< Set OpenFlow flow on the Controller") print( " Match: Ethernet Type (%s)\n" " IP DSCP (%s)\n" " IP ECN (%s)\n" " IPv6 Source Address (%s)\n" " IPv6 Destination Address (%s)\n" " IPv6 Flow Label (%s)\n" " ICMPv6 Type (%s)\n" " ICMPv6 Code (%s)\n" " Metadata (%s)" % (hex(eth_type), ip_dscp, ip_ecn, ipv6_src, ipv6_dst, ipv6_flabel, icmpv6_type, icmpv6_code, metadata)) print(" Action: Output (to %s)" % (output_port)) time.sleep(rundelay) flow_entry = FlowEntry() table_id = 0 flow_id = 26 flow_entry.set_flow_table_id(table_id) flow_entry.set_flow_name(flow_name="demo20.py") flow_entry.set_flow_id(flow_id) flow_entry.set_flow_priority(flow_priority=1019) flow_entry.set_flow_cookie(cookie=250) flow_entry.set_flow_cookie_mask(cookie_mask=255) flow_entry.set_flow_hard_timeout(hard_timeout=1200) flow_entry.set_flow_idle_timeout(idle_timeout=3400) # --- Instruction: 'Apply-actions' # Actions: 'Output' instruction = Instruction(instruction_order=0) action = OutputAction(order=0, port=output_port) instruction.add_apply_action(action) flow_entry.add_instruction(instruction) # --- Match Fields: Ethernet Type # IP DSCP # IP ECN # IPv6 Source Address # IPv6 Destination Address # IPv6 Flow Label # IP protocol number (ICMPv6) # ICMPv6 Type # ICMPv6 Code # Metadata match = Match() match.set_eth_type(eth_type) match.set_ip_dscp(ip_dscp) match.set_ip_ecn(ip_ecn) match.set_ipv6_src(ipv6_src) match.set_ipv6_dst(ipv6_dst) match.set_ipv6_flabel(ipv6_flabel) match.set_ip_proto(ip_proto) match.set_icmpv6_type(icmpv6_type) match.set_icmpv6_code(icmpv6_code) match.set_metadata(metadata) flow_entry.add_match(match) print("\n") print("<<< Flow to send:") print flow_entry.get_payload() time.sleep(rundelay) result = ofswitch.add_modify_flow(flow_entry) status = result.get_status() if (status.eq(STATUS.OK)): print("<<< Flow successfully added to the Controller") else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print("\n") print("<<< Get configured flow from the Controller") time.sleep(rundelay) result = ofswitch.get_configured_flow(table_id, flow_id) status = result.get_status() if (status.eq(STATUS.OK)): print("<<< Flow successfully read from the Controller") print("Flow info:") flow = result.get_data() print json.dumps(flow, indent=4) else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print("\n") print( "<<< Delete flow with id of '%s' from the Controller's cache " "and from the table '%s' on the '%s' node" % (flow_id, table_id, nodeName)) time.sleep(rundelay) result = ofswitch.delete_flow(flow_entry.get_flow_table_id(), flow_entry.get_flow_id()) status = result.get_status() if (status.eq(STATUS.OK)): print("<<< Flow successfully removed from the Controller") else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print("\n") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print(">>> Demo End") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def of_demo_11(): f = "cfg.yml" d = {} if(load_dict_from_file(f, d) is False): print("Config file '%s' read error: " % f) exit() try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] nodeName = d['nodeName'] rundelay = d['rundelay'] except: print ("Failed to get Controller device attributes") exit(0) print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print ("<<< Demo 11 Start") print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) ofswitch = OFSwitch(ctrl, nodeName) # --- Flow Match: Ethernet Source Address # Ethernet Destination Address # IPv4 Source Address # IPv4 Destination Address # ICMPv4 Type # ICMPv4 Code # IP DSCP # IP ECN # Input Port # NOTE: Ethernet type MUST be 2048 (0x800) -> IPv4 protocol # IP Protocol Type MUST be 1 -> ICMP eth_type = ETH_TYPE_IPv4 eth_src = "00:00:00:11:23:ae" eth_dst = "00:ff:20:01:1a:3d" ipv4_src = "17.1.2.3/8" ipv4_dst = "172.168.5.6/18" ip_proto = IP_PROTO_ICMP ip_dscp = IP_DSCP_CS2 # 'Class Selector' = 'Immediate' ip_ecn = IP_ECN_CE # Congestion Encountered icmpv4_type = 6 # Alternate Host Address icmpv4_code = 3 # Alternate Address for Host input_port = 10 print ("<<< 'Controller': %s, 'OpenFlow' switch: '%s'" % (ctrlIpAddr, nodeName)) print "\n" print ("<<< Set OpenFlow flow on the Controller") print (" Match: Ethernet Type (%s)\n" " Ethernet Source Address (%s)\n" " Ethernet Destination Address (%s)\n" " IPv4 Source Address (%s)\n" " IPv4 Destination Address (%s)\n" " IP Protocol Number (%s)\n" " IP DSCP (%s)\n" " IP ECN (%s)\n" " ICMPv4 Type (%s)\n" " ICMPv4 Code (%s)\n" " Input Port (%s)" % (hex(eth_type), eth_src, eth_dst, ipv4_src, ipv4_dst, ip_proto, ip_dscp, ip_ecn, icmpv4_type, icmpv4_code, input_port)) print (" Action: Output (NORMAL)") time.sleep(rundelay) flow_entry = FlowEntry() table_id = 0 flow_entry.set_flow_table_id(table_id) flow_id = 18 flow_entry.set_flow_id(flow_id) flow_entry.set_flow_hard_timeout(0) flow_entry.set_flow_idle_timeout(0) flow_entry.set_flow_priority(1009) # --- Instruction: 'Apply-actions' # Action: 'Output' NORMAL instruction = Instruction(instruction_order=0) action = OutputAction(order=0, port="NORMAL") instruction.add_apply_action(action) flow_entry.add_instruction(instruction) # --- Match Fields: Ethernet Type # Ethernet Source Address # Ethernet Destination Address # IPv4 Source Address # IPv4 Destination Address # IP Protocol Number # IP DSCP # IP ECN # ICMPv4 Type # ICMPv4 Code # Input Port match = Match() match.set_eth_type(eth_type) match.set_eth_src(eth_src) match.set_eth_dst(eth_dst) match.set_ipv4_src(ipv4_src) match.set_ipv4_dst(ipv4_dst) match.set_ip_proto(ip_proto) match.set_ip_dscp(ip_dscp) match.set_ip_ecn(ip_ecn) match.set_icmpv4_type(icmpv4_type) match.set_icmpv4_code(icmpv4_code) match.set_in_port(input_port) flow_entry.add_match(match) print ("\n") print ("<<< Flow to send:") print flow_entry.get_payload() time.sleep(rundelay) result = ofswitch.add_modify_flow(flow_entry) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully added to the Controller") else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print ("<<< Get configured flow from the Controller") time.sleep(rundelay) result = ofswitch.get_configured_flow(table_id, flow_id) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully read from the Controller") print ("Flow info:") flow = result.get_data() print json.dumps(flow, indent=4) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print ("<<< Delete flow with id of '%s' from the Controller's cache " "and from the table '%s' on the '%s' node" % (flow_id, table_id, nodeName)) time.sleep(rundelay) result = ofswitch.delete_flow(flow_entry.get_flow_table_id(), flow_entry.get_flow_id()) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully removed from the Controller") else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print (">>> Demo End") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
import json from pybvc.controller.controller import Controller # from pybvc.controller.openflownode import OpenflowNode from pybvc.openflowdev.ofswitch import OFSwitch from pybvc.common.status import STATUS from pybvc.common.utils import load_dict_from_file if __name__ == "__main__": f = "of_cfg.yml" d = {} if load_dict_from_file(f, d) == False: print ("Config file '%s' read error: " % f) exit() try: ctrlIpAddr = d["ctrlIpAddr"] ctrlPortNum = d["ctrlPortNum"] ctrlUname = d["ctrlUname"] ctrlPswd = d["ctrlPswd"] except: print ("Failed to get Controller device attributes") exit(0) print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print ("<<< Demo Start") print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
def of_demo_12(): f = "cfg.yml" d = {} if(load_dict_from_file(f, d) is False): print("Config file '%s' read error: " % f) exit() try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] nodeName = d['nodeName'] rundelay = d['rundelay'] except: print ("Failed to get Controller device attributes") exit(0) print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print ("<<< Demo 12 Start") print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) ofswitch = OFSwitch(ctrl, nodeName) # --- Flow Match: Ethernet Source Address # Ethernet Destination Address # ARP Operation # ARP Source IPv4 Address # ARP Target IPv4 Address # ARP source hardware address # ARP target hardware address # NOTE: Ethernet type MUST be 2054 (0x0806) -> ARP protocol eth_type = ETH_TYPE_ARP eth_src = "00:ab:fe:01:03:31" eth_dst = "ff:ff:ff:ff:ff:ff" arp_opcode = ARP_REQUEST arp_src_ipv4_addr = "192.168.4.1/32" arp_tgt_ipv4_addr = "10.21.22.23/32" arp_src_hw_addr = "12:34:56:78:98:ab" arp_tgt_hw_addr = "fe:dc:ba:98:76:54" print ("<<< 'Controller': %s, 'OpenFlow' switch: '%s'" % (ctrlIpAddr, nodeName)) print "\n" print ("<<< Set OpenFlow flow on the Controller") print (" Match: Ethernet Type (%s)\n" " Ethernet Source Address (%s)\n" " Ethernet Destination Address (%s)\n" " ARP Operation (%s)\n" " ARP Source IPv4 Address (%s)\n" " ARP Target IPv4 Address (%s)\n" " ARP Source Hardware Address (%s)\n" " ARP Target Hardware Address (%s)" % (hex(eth_type), eth_src, eth_dst, arp_opcode, arp_src_ipv4_addr, arp_tgt_ipv4_addr, arp_src_hw_addr, arp_tgt_hw_addr)) print (" Action: Output (CONTROLLER)") time.sleep(rundelay) flow_entry = FlowEntry() table_id = 0 flow_entry.set_flow_table_id(table_id) flow_id = 19 flow_entry.set_flow_id(flow_id) flow_entry.set_flow_hard_timeout(0) flow_entry.set_flow_idle_timeout(0) flow_entry.set_flow_priority(1010) # --- Instruction: 'Apply-actions' # Action: 'Output' CONTROLLER instruction = Instruction(instruction_order=0) action = OutputAction(order=0, port="CONTROLLER") instruction.add_apply_action(action) flow_entry.add_instruction(instruction) # --- Match Fields: Ethernet Type # Ethernet Source Address # Ethernet Destination Address # ARP Operation # ARP Source IPv4 Address # ARP Target IPv4 Address # ARP Source Hardware Address # ARP Target Hardware Address match = Match() match.set_eth_type(eth_type) match.set_eth_src(eth_src) match.set_eth_dst(eth_dst) match.set_arp_opcode(arp_opcode) match.set_arp_src_transport_address(arp_src_ipv4_addr) match.set_arp_tgt_transport_address(arp_tgt_ipv4_addr) match.set_arp_src_hw_address(arp_src_hw_addr) match.set_arp_tgt_hw_address(arp_tgt_hw_addr) flow_entry.add_match(match) print ("\n") print ("<<< Flow to send:") print flow_entry.get_payload() time.sleep(rundelay) result = ofswitch.add_modify_flow(flow_entry) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully added to the Controller") else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.detailed()) exit(0) print ("\n") print ("<<< Get configured flow from the Controller") time.sleep(rundelay) result = ofswitch.get_configured_flow(table_id, flow_id) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully read from the Controller") print ("Flow info:") flow = result.get_data() print json.dumps(flow, indent=4) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.detailed()) exit(0) print ("\n") print ("<<< Delete flow with id of '%s' from the Controller's cache " "and from the table '%s' on the '%s' node" % (flow_id, table_id, nodeName)) time.sleep(rundelay) result = ofswitch.delete_flow(flow_entry.get_flow_table_id(), flow_entry.get_flow_id()) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully removed from the Controller") else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print (">>> Demo End") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def of_demo_27(): f = "cfg.yml" d = {} if (load_dict_from_file(f, d) is False): print("Config file '%s' read error: " % f) exit() try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] rundelay = d['rundelay'] except: print("Failed to get Controller device attributes") exit(0) print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print("<<< Demo 27 Start") print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) print "\n" print("<<< Controller '%s:%s'" % (ctrlIpAddr, ctrlPortNum)) time.sleep(rundelay) print("\n") print("<<< Get OpenFlow Network Topology information") time.sleep(rundelay) topology_ids = [] topologies = [] inventory = None result = ctrl.build_inventory_object() status = result.get_status() if (status.eq(STATUS.OK)): inventory = result.get_data() assert (isinstance(inventory, Inventory)) else: print("\n") print("!!!Error, failed to obtain inventory info, reason: %s" % status.brief().lower()) exit(0) result = ctrl.get_topology_ids() status = result.get_status() if (status.eq(STATUS.OK)): topology_ids = result.get_data() assert (isinstance(topology_ids, list)) else: print("\n") print("!!!Error, failed to obtain topology info, reason: %s" % status.brief().lower()) exit(0) print "\n" print("<<< Network topologies") for topo_id in topology_ids: print " '%s'" % topo_id of_topo_id = 'flow:1' for topo_id in topology_ids: if (topo_id != of_topo_id): continue result = ctrl.build_topology_object(topo_id) status = result.get_status() if (status.eq(STATUS.OK)): topo = result.get_data() topologies.append(topo) assert (isinstance(topo, Topology)) else: print("\n") print("!!!Error, failed to parse '%s' topology info, reason: %s" % (topo_id, status.brief().lower())) exit(0) for topo in topologies: if topo.get_id() != of_topo_id: continue time.sleep(rundelay) print "\n" print("<<< Information for '%s' network topology:") % topo.get_id() print "\n".strip() flows_cnt = 0 sids = topo.get_switch_ids() for sid in sids: flows_cnt += inventory.get_openflow_node_flows_cnt(sid) print(" Number of flows : %s" % flows_cnt) print(" Number of switches : %s" % topo.get_switches_cnt()) print(" Number of inter-switch links : %s" % topo.get_inter_switch_links_cnt()) print(" Number of hosts : %s" % topo.get_hosts_cnt()) time.sleep(rundelay) print "\n" print("<<< OpenFlow switches in '%s' topology") % topo.get_id() s1 = 'IP Address' s2 = 'OpenFlow Id' sym = '-' print "\n".strip() print " {0:<15} {1:<30}".format(s1, s2) print " {0:<15} {1:<30}".format(sym * 15, sym * 30) switch_ids = topo.get_switch_ids() for switch_id in switch_ids: inv_node = inventory.get_openflow_node(switch_id) addr = inv_node.get_ip_address() node_id = inv_node.get_id() print " {0:<15} {1:<30}".format(addr, node_id) switches = topo.get_switches() for switch in switches: assert (isinstance(switch, Node)) print "\n".strip() time.sleep(rundelay) print("<<< Neighborhood information for '%s' switch ports" % switch.get_id()) pnums = switch.get_port_numbers() for pnum in pnums: if pnum == 'LOCAL': continue print "\n".strip() print " Port '%s'" % pnum peer_list = topo.get_peer_list_for_node_port_(switch, pnum) if len(peer_list): for item in peer_list: assert (isinstance(item, Node)) if (item.is_switch()): print(" Device Type : %s" % "switch") print(" OpenFlow Id : %s" % item.get_openflow_id()) elif (item.is_host()): print(" Device Type : %s" % "host") mac_addr = item.get_mac_address() print(" MAC Address : %s" % mac_addr) ip_addr = item.get_ip_address_for_mac(mac_addr) print(" IP Address : %s" % ip_addr) else: print " None" time.sleep(rundelay) print("\n") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print(">>> Demo End") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def of_demo_9(): f = "cfg.yml" d = {} if(load_dict_from_file(f, d) is False): print("Config file '%s' read error: " % f) exit() try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] nodeName = d['nodeName'] rundelay = d['rundelay'] except: print ("Failed to get Controller device attributes") exit(0) print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print ("<<< Demo 9 Start") print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) ofswitch = OFSwitch(ctrl, nodeName) # --- Flow Match: Ethernet Source Address # Ethernet Destination Address # IPv4 Source Address # IPv4 Destination Address # TCP Source Port Number # TCP Destination Port Number # IP DSCP # Input Port # NOTE: Ethernet type MUST be 2048 (0x800) -> IPv4 protocol eth_type = ETH_TYPE_IPv4 eth_src = "00:00:00:11:23:ae" eth_dst = "ff:ff:29:01:19:61" ipv4_src = "17.1.2.3/8" ipv4_dst = "172.168.5.6/16" ip_proto = IP_PROTO_TCP # Assured Forwarding ('class'=1, 'drop precedence'=2) ip_dscp = IP_DSCP_AF12 tcp_src_port = 25364 tcp_dst_port = 8080 input_port = 13 print ("<<< 'Controller': %s, 'OpenFlow' switch: '%s'" % (ctrlIpAddr, nodeName)) print "\n" print ("<<< Set OpenFlow flow on the Controller") print (" Match: Ethernet Type (%s)\n" " Ethernet Source Address (%s)\n" " Ethernet Destination Address (%s)\n" " IPv4 Source Address (%s)\n" " IPv4 Destination Address (%s)\n" " IP Protocol Number (%s)\n" " IP DSCP (%s)\n" " TCP Source Port Number (%s)\n" " TCP Destination Port Number (%s)\n" " Input Port (%s)" % (hex(eth_type), eth_src, eth_dst, ipv4_src, ipv4_dst, ip_proto, ip_dscp, tcp_src_port, tcp_dst_port, input_port)) print (" Action: Output (NORMAL)") time.sleep(rundelay) flow_entry = FlowEntry() table_id = 0 flow_entry.set_flow_table_id(table_id) flow_id = 16 flow_entry.set_flow_id(flow_id) flow_entry.set_flow_priority(flow_priority=1007) flow_entry.set_flow_cookie(cookie=101) flow_entry.set_flow_cookie_mask(cookie_mask=255) # --- Instruction: 'Apply-actions' # Action: 'Output' NORMAL instruction = Instruction(instruction_order=0) action = OutputAction(order=0, port="NORMAL") instruction.add_apply_action(action) flow_entry.add_instruction(instruction) # --- Match Fields: Ethernet Type # Ethernet Source Address # Ethernet Destination Address # IPv4 Source Address # IPv4 Destination Address # IP Protocol Number # IP DSCP # IP ECN # TCP Source Port Number # TCP Destination Port Number # Input Port match = Match() match.set_eth_type(eth_type) match.set_eth_src(eth_src) match.set_eth_dst(eth_dst) match.set_ipv4_src(ipv4_src) match.set_ipv4_dst(ipv4_dst) match.set_ip_proto(ip_proto) match.set_ip_dscp(ip_dscp) match.set_tcp_src(tcp_src_port) match.set_tcp_dst(tcp_dst_port) match.set_in_port(input_port) flow_entry.add_match(match) print ("\n") print ("<<< Flow to send:") print flow_entry.get_payload() time.sleep(rundelay) result = ofswitch.add_modify_flow(flow_entry) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully added to the Controller") else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print ("<<< Get configured flow from the Controller") time.sleep(rundelay) result = ofswitch.get_configured_flow(table_id, flow_id) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully read from the Controller") print ("Flow info:") flow = result.get_data() print json.dumps(flow, indent=4) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print ("<<< Delete flow with id of '%s' from the Controller's cache " "and from the table '%s' on the '%s' node" % (flow_id, table_id, nodeName)) time.sleep(rundelay) result = ofswitch.delete_flow(flow_entry.get_flow_table_id(), flow_entry.get_flow_id()) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully removed from the Controller") else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print (">>> Demo End") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def vr_demo_12(): f = "cfg4.yml" d = {} if(load_dict_from_file(f, d) is False): print("Config file '%s' read error: " % f) exit() try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] nodeName = d['nodeName'] nodeIpAddr = d['nodeIpAddr'] nodePortNum = d['nodePortNum'] nodeUname = d['nodeUname'] nodePswd = d['nodePswd'] rundelay = d['rundelay'] except: print ("Failed to get Controller device attributes") exit(0) print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print ("<<< Demo Start") print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) vrouter = VRouter5600(ctrl, nodeName, nodeIpAddr, nodePortNum, nodeUname, nodePswd) print ("<<< 'Controller': %s, '%s': %s" % (ctrlIpAddr, nodeName, nodeIpAddr)) print ("\n") time.sleep(rundelay) node_configured = False result = ctrl.check_node_config_status(nodeName) status = result.get_status() if(status.eq(STATUS.NODE_CONFIGURED)): node_configured = True print ("<<< '%s' is configured on the Controller" % nodeName) elif(status.eq(STATUS.DATA_NOT_FOUND)): node_configured = False else: print ("\n") print "Failed to get configuration status for the '%s'" % nodeName print ("!!!Demo terminated, reason: %s" % status.detailed()) exit(0) if node_configured is False: result = ctrl.add_netconf_node(vrouter) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< '%s' added to the Controller" % nodeName) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.detailed()) exit(0) print ("\n") time.sleep(rundelay) result = ctrl.check_node_conn_status(nodeName) status = result.get_status() if(status.eq(STATUS.NODE_CONNECTED)): print ("<<< '%s' is connected to the Controller" % nodeName) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print("\n") print ("<<< Show VPN configuration on the '%s'" % nodeName) result = vrouter.get_vpn_cfg() time.sleep(rundelay) status = result.get_status() if (status.eq(STATUS.OK)): print ("'%s' VPN configuration:" % nodeName) cfg = result.get_data() data = json.loads(cfg) print json.dumps(data, indent=4, sort_keys=True) elif (status.eq(STATUS.DATA_NOT_FOUND)): print ("No VPN configuration found") else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.detailed()) ctrl.delete_netconf_node(vrouter) exit(0) print "\n" print (">>> Create new VPN configuration on the '%s'" % (nodeName)) ca_cert_file = '/config/auth/ca.crt' srv_cert_file = '/config/auth/r1.crt' srv_key_file = '/config/auth/r1.key' crl_file = '/config/auth/r1.crl' print (" NOTE: For this demo to succeed the following files " "must exist on the '%s'\n" " (empty files can be created for the sake of the demo):\n" " %s\n" " %s\n" " %s\n" " %s" % (nodeName, ca_cert_file, srv_cert_file, crl_file, srv_key_file)) time.sleep(rundelay) # ------------------------------------------------------------------------- # Encode VPN configuration options by using 'Vpn' object # ------------------------------------------------------------------------- vpn = Vpn() # ------------------------------------------------------------------------- # Create and configure Internet Key Exchange (IKE) group # ------------------------------------------------------------------------- ike_grp_name = "IKE-1W" proposal_num = 1 # Set the encryption cipher for proposal 1 # (enumeration: 'aes128', 'aes256', '3des') encryption_cipher = 'aes256' vpn.set_ipsec_ike_group_proposal_encryption(ike_grp_name, proposal_num, encryption_cipher) # Set the hash algorithm for proposal 1 # (enumeration: 'md5', 'sha1') hash_algorithm = 'sha1' vpn.set_ipsec_ike_group_proposal_hash(ike_grp_name, proposal_num, hash_algorithm) # Set the encryption cipher for proposal 2 # (enumeration: 'aes128', 'aes256', '3des') proposal_num = 2 encryption_cipher = 'aes128' vpn.set_ipsec_ike_group_proposal_encryption(ike_grp_name, proposal_num, encryption_cipher) # Set the hash algorithm for proposal 2 # (enumeration: 'md5', 'sha1') hash_algorithm = 'sha1' vpn.set_ipsec_ike_group_proposal_hash(ike_grp_name, proposal_num, hash_algorithm) # Set the lifetime for the whole IKE group lifetime = 3600 vpn.set_ipsec_ike_group_lifetime(ike_grp_name, lifetime) # ------------------------------------------------------------------------- # Create and configure Encapsulating Security Payload (ESP) group # ------------------------------------------------------------------------- esp_grp_name = "ESP-1W" # Set the encryption cipher for proposal 1 # (enumeration: 'aes128', 'aes256', '3des') proposal_num = 1 encryption_cipher = 'aes256' vpn.set_ipsec_esp_group_proposal_encryption(esp_grp_name, proposal_num, encryption_cipher) # Set the hash algorithm for proposal 1 # (enumeration: 'md5', 'sha1') hash_algorithm = 'sha1' vpn.set_ipsec_esp_group_proposal_hash(esp_grp_name, proposal_num, hash_algorithm) # Set the encryption cipher for proposal 2 # (enumeration: 'aes128', 'aes256', '3des') proposal_num = 2 encryption_cipher = '3des' vpn.set_ipsec_esp_group_proposal_encryption(esp_grp_name, proposal_num, encryption_cipher) # Set the hash algorithm for proposal 2 # (enumeration: 'md5', 'sha1') hash_algorithm = 'md5' vpn.set_ipsec_esp_group_proposal_hash(esp_grp_name, proposal_num, hash_algorithm) # Set the lifetime for the whole ESP group lifetime = 1800 vpn.set_ipsec_esp_group_lifetime(esp_grp_name, lifetime) # ------------------------------------------------------------------------- # Configure connection to a remote peer # ------------------------------------------------------------------------- peer_node = "192.0.2.33" description = ("Site-to-Site VPN Configuration Example - " "X.509 Certificate Authentication") vpn.set_ipsec_site_to_site_peer_description(peer_node, description) # Set authentication mode to 'x509' auth_mode = 'x509' vpn.set_ipsec_site_to_site_peer_auth_mode(peer_node, auth_mode) # Specify the 'distinguished name' of the certificate for the peer remote_id = "C=US, ST=CA, O=ABC Company, CN=east, [email protected]" vpn.set_ipsec_site_to_site_peer_auth_remote_id(peer_node, remote_id) # Specify the location of the CA certificate on the vRouter vpn.set_ipsec_site_to_site_peer_auth_ca_cert_file(peer_node, ca_cert_file) # Specify the location of the server certificate on the vRouter vpn.set_ipsec_site_to_site_peer_auth_srv_cert_file(peer_node, srv_cert_file) # Specify the location of the server key file on the vRouter vpn.set_ipsec_site_to_site_peer_auth_srv_key_file(peer_node, srv_key_file) # Specify the password for the server key file srv_key_pswd = 'testpassword' vpn.set_ipsec_site_to_site_peer_auth_srv_key_pswd(peer_node, srv_key_pswd) # Specify the default ESP group for all tunnels esp_group_name = 'ESP-1W' vpn.set_ipsec_site_to_site_peer_default_esp_group(peer_node, esp_group_name) # Specify the IKE group ike_group_name = 'IKE-1W' vpn.set_ipsec_site_to_site_peer_ike_group(peer_node, ike_group_name) # Identify the IP address on the vRouter to be used for this connection local_address = '192.0.2.1' vpn.set_ipsec_site_to_site_peer_local_address(peer_node, local_address) # Create a tunnel configuration and provide local and remote subnets # for this tunnel tunnel = 1 local_prefix = '192.168.40.0/24' remote_prefix = '192.168.60.0/24' vpn.set_ipsec_site_to_site_peer_tunnel_local_prefix(peer_node, tunnel, local_prefix) vpn.set_ipsec_site_to_site_peer_tunnel_remote_prefix(peer_node, tunnel, remote_prefix) print "\n" print (">>> VPN configuration to be applied to the '%s'" % (nodeName)) print vpn.get_payload() time.sleep(rundelay) result = vrouter.set_vpn_cfg(vpn) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< VPN configuration was successfully created") else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) print status.detailed() ctrl.delete_netconf_node(vrouter) exit(0) print "\n" print ("<<< Show VPN configuration on the '%s'" % (nodeName)) time.sleep(rundelay) result = vrouter.get_vpn_cfg() status = result.get_status() if (status.eq(STATUS.OK)): print ("'%s' VPN configuration:" % nodeName) cfg = result.get_data() data = json.loads(cfg) print json.dumps(data, indent=4, sort_keys=True) print ("<<< VPN configuration was successfully read") else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.detailed()) ctrl.delete_netconf_node(vrouter) exit(0) time.sleep(rundelay) print "\n" print ("<<< Delete VPN configuration on the '%s'" % (nodeName)) time.sleep(rundelay) result = vrouter.delete_vpn_cfg() status = result.get_status() if(status.eq(STATUS.OK)): print ("VPN configuration successfully removed from '%s'" % (nodeName)) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) print status.detailed() ctrl.delete_netconf_node(vrouter) exit(0) print "\n" print ("<<< Show VPN configuration on the '%s'" % (nodeName)) time.sleep(rundelay) result = vrouter.get_vpn_cfg() status = result.get_status() if (status.eq(STATUS.OK)): print ("'%s' VPN configuration:" % nodeName) cfg = result.get_data() data = json.loads(cfg) print json.dumps(data, indent=4, sort_keys=True) elif (status.eq(STATUS.DATA_NOT_FOUND)): print ("No VPN configuration found") else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.detailed()) ctrl.delete_netconf_node(vrouter) exit(0) print "\n" print (">>> Remove '%s' NETCONF node from the Controller" % nodeName) time.sleep(rundelay) result = ctrl.delete_netconf_node(vrouter) status = result.get_status() if(status.eq(STATUS.OK)): print ("'%s' NETCONF node was successfully removed " "from the Controller" % nodeName) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief()) exit(0) print ("\n") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print (">>> Demo End") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def nc_demo_11(): f = "cfg3.yml" d = {} if(load_dict_from_file(f, d) is False): print("Config file '%s' read error: " % f) exit(0) try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] nodeName = d['nodeName'] nodeIpAddr = d['nodeIpAddr'] nodePortNum = d['nodePortNum'] nodeUname = d['nodeUname'] nodePswd = d['nodePswd'] rundelay = d['rundelay'] except: print ("Failed to get Controller or NETCONF device attributes") exit(0) print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print ("<<< Demo Start") print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print ("\n") print ("<<< Creating Controller instance") ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) print ("'Controller':") print ctrl.to_json() print "\n" print ("<<< Show NETCONF nodes configured on the Controller") time.sleep(rundelay) result = ctrl.get_netconf_nodes_in_config() status = result.get_status() if(status.eq(STATUS.OK)): print "Nodes configured:" nlist = result.get_data() for item in nlist: print " '{}'".format(item) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief()) exit(0) node_configured = False result = ctrl.check_node_config_status(nodeName) status = result.get_status() if(status.eq(STATUS.NODE_CONFIGURED)): node_configured = True elif(status.eq(STATUS.DATA_NOT_FOUND)): node_configured = False else: print ("\n") print "Failed to get configuration status for the '%s'" % nodeName print ("!!!Demo terminated, reason: %s" % status.detailed()) exit(0) if node_configured: print ("\n") print ("<<< '%s' is already configured on the Controller" % nodeName) print ("Unmounting '%s' from the Controller" % nodeName) time.sleep(rundelay) result = ctrl.delete_netconf_node(nodename=nodeName) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< '%s' NETCONF node was successfully removed " "from the Controller" % nodeName) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief()) exit(0) print ("\n") time.sleep(rundelay) print ("<<< Creating new '%s' NETCONF node" % nodeName) node = NetconfNode(ctrl, nodeName, nodeIpAddr, nodePortNum, nodeUname, nodePswd) print ("'%s':" % nodeName) print node.to_json() print ("\n") print ("<<< Check '%s' NETCONF node availability " "on the network" % nodeName) time.sleep(rundelay) response = os.system("ping -c 1 " + nodeIpAddr) if response == 0: print nodeIpAddr, 'is up!' else: print nodeIpAddr, 'is down!' print ("!!!Demo terminated") exit(0) print ("\n") print ("<<< Add '%s' NETCONF node to the Controller" % nodeName) time.sleep(rundelay) result = ctrl.add_netconf_node(node) status = result.get_status() if(status.eq(STATUS.OK)): print ("'%s' NETCONF node was successfully added " "to the Controller" % nodeName) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief()) exit(0) print "\n" print ("<<< Show NETCONF nodes configured on the Controller") time.sleep(rundelay) result = ctrl.get_netconf_nodes_in_config() status = result.get_status() if(status.eq(STATUS.OK)): print "Nodes configured:" nlist = result.get_data() for item in nlist: print " '{}'".format(item) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief()) exit(0) print "\n" print ("<<< Find the '%s' NETCONF node on the Controller" % nodeName) time.sleep(rundelay) result = ctrl.check_node_config_status(nodeName) status = result.get_status() if(status.eq(STATUS.NODE_CONFIGURED)): print ("'%s' node is configured" % nodeName) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief()) exit(0) print "\n" print ("<<< Show connection status for all NETCONF nodes " "configured on the Controller") time.sleep(rundelay) result = ctrl.get_netconf_nodes_conn_status() status = result.get_status() if(status.eq(STATUS.OK)): print "Nodes connection status:" nlist = result.get_data() for item in nlist: status = "" if (item['connected'] is True): status = "connected" else: status = "not connected" print " '{}' is {}".format(item['node'], status) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief()) exit(0) print "\n" print ("<<< Show connection status for the '%s' NETCONF node" % nodeName) time.sleep(rundelay) result = ctrl.check_node_conn_status(nodeName) status = result.get_status() if(status.eq(STATUS.NODE_CONNECTED)): print ("'%s' node is connected" % nodeName) elif (status.eq(STATUS.NODE_DISONNECTED)): print ("'%s' node is not connected" % nodeName) elif (status.eq(STATUS.NODE_NOT_FOUND)): print ("'%s' node is not found" % nodeName) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief()) exit(0) print "\n" print (">>> Remove '%s' NETCONF node from the Controller" % nodeName) time.sleep(rundelay) result = ctrl.delete_netconf_node(node) status = result.get_status() if(status.eq(STATUS.OK)): print ("'%s' NETCONF node was successfully removed " "from the Controller" % nodeName) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief()) exit(0) print "\n" print ("<<< Show NETCONF nodes configured on the Controller") time.sleep(rundelay) result = ctrl.get_netconf_nodes_in_config() status = result.get_status() if(status.eq(STATUS.OK)): print "Nodes configured:" nlist = result.get_data() for item in nlist: print " '{}'".format(item) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief()) exit(0) print "\n" print ("<<< Show connection status for the '%s' NETCONF node" % nodeName) time.sleep(rundelay) result = ctrl.check_node_conn_status(nodeName) status = result.get_status() if(status.eq(STATUS.NODE_CONNECTED)): print ("'%s' node is connected" % nodeName) elif (status.eq(STATUS.NODE_DISONNECTED)): print ("'%s' node is not connected" % nodeName) elif (status.eq(STATUS.NODE_NOT_FOUND)): print ("'%s' node is not found" % nodeName) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief()) exit(0) print ("\n") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print (">>> Demo End") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def of_demo_23(): f = "cfg.yml" d = {} if(load_dict_from_file(f, d) is False): print("Config file '%s' read error: " % f) exit() try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] nodeName = d['nodeName'] rundelay = d['rundelay'] except: print ("Failed to get Controller device attributes") exit(0) print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print ("<<< Demo 23 Start") print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) ofswitch = OFSwitch(ctrl, nodeName) # --- Flow Match: Ethernet Type # Input Port # IPv4 Destination Address eth_type = ETH_TYPE_MPLS_UCAST in_port = 13 mpls_label = 27 # --- Flow Actions: Set Field # Output new_mpls_label = 44 output_port = 14 print ("<<< 'Controller': %s, 'OpenFlow' switch: '%s'" % (ctrlIpAddr, nodeName)) print "\n" print ("<<< Set OpenFlow flow on the Controller") print (" Match: Ethernet Type (%s)\n" " Input Port (%s)\n" " MPLS Label (%s)" % (hex(eth_type), in_port, mpls_label)) print (" Action: Set Field (MPLS Label %s)\n" " Output (Physical Port number %s)" % (new_mpls_label, output_port)) time.sleep(rundelay) flow_entry = FlowEntry() table_id = 0 flow_id = 29 flow_entry.set_flow_table_id(table_id) flow_entry.set_flow_id(flow_id) flow_entry.set_flow_name(flow_name="Change MPLS Label") flow_entry.set_flow_hard_timeout(hard_timeout=0) flow_entry.set_flow_idle_timeout(idle_timeout=0) flow_entry.set_flow_priority(flow_priority=1022) flow_entry.set_flow_cookie(cookie=401) flow_entry.set_flow_cookie_mask(cookie_mask=255) # --- Instruction: 'Apply-actions' # Actions: 'Set Field' # 'Output' instruction = Instruction(instruction_order=0) action = SetFieldAction(order=0) action.set_mpls_label(new_mpls_label) instruction.add_apply_action(action) action = OutputAction(order=1, port=2) instruction.add_apply_action(action) flow_entry.add_instruction(instruction) # --- Match Fields: Ethernet Type # Input Port # MPLS Label match = Match() match.set_eth_type(eth_type) match.set_in_port(in_port) match.set_mpls_label(mpls_label) flow_entry.add_match(match) print ("\n") print ("<<< Flow to send:") print flow_entry.get_payload() time.sleep(rundelay) result = ofswitch.add_modify_flow(flow_entry) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully added to the Controller") else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.detailed()) exit(0) print ("\n") print ("<<< Get configured flow from the Controller") time.sleep(rundelay) result = ofswitch.get_configured_flow(table_id, flow_id) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully read from the Controller") print ("Flow info:") flow = result.get_data() print json.dumps(flow, indent=4) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print ("<<< Delete flow with id of '%s' from the Controller's cache " "and from the table '%s' on the '%s' node" % (flow_id, table_id, nodeName)) time.sleep(rundelay) result = ofswitch.delete_flow(flow_entry.get_flow_table_id(), flow_entry.get_flow_id()) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully removed from the Controller") else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print (">>> Demo End") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def of_demo_6(): f = "cfg.yml" d = {} if(load_dict_from_file(f, d) is False): print("Config file '%s' read error: " % f) exit() try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] nodeName = d['nodeName'] rundelay = d['rundelay'] except: print ("Failed to get Controller device attributes") exit(0) print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print ("<<< Demo 6 Start") print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) ofswitch = OFSwitch(ctrl, nodeName) # --- Flow Match: Ethernet Type # Ethernet Source Address # Ethernet Destination Addresses eth_type = 45 # (0x002D) eth_src = "00:01:02:03:04:05" eth_dst = "aa:bb:cc:dd:ee:ff" print ("<<< 'Controller': %s, 'OpenFlow' switch: '%s'" % (ctrlIpAddr, nodeName)) print "\n" print ("<<< Set OpenFlow flow on the Controller") print (" Match: Ethernet Type (%s)\n" " Ethernet Source Address (%s)\n" " Ethernet Destination Address (%s)" % (hex(eth_type), eth_src, eth_dst)) print (" Action: Drop") time.sleep(rundelay) flow_entry = FlowEntry() table_id = 0 flow_entry.set_flow_table_id(table_id) flow_id = 14 flow_entry.set_flow_id(flow_id) flow_entry.set_flow_priority(flow_priority=1000) # --- Instruction: 'Apply-actions' # Action: 'Drop' instruction = Instruction(instruction_order=0) action = DropAction(order=0) instruction.add_apply_action(action) flow_entry.add_instruction(instruction) # --- Match Fields: Ethernet Type # Ethernet Source Address # Ethernet Destination Address match = Match() match.set_eth_type(eth_type) match.set_eth_src(eth_src) match.set_eth_dst(eth_dst) flow_entry.add_match(match) print ("\n") print ("<<< Flow to send:") print flow_entry.get_payload() time.sleep(rundelay) result = ofswitch.add_modify_flow(flow_entry) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully added to the Controller") else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print ("<<< Get configured flow from the Controller") time.sleep(rundelay) result = ofswitch.get_configured_flow(table_id, flow_id) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully read from the Controller") print ("Flow info:") flow = result.get_data() print json.dumps(flow, indent=4) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print ("<<< Delete flow with id of '%s' from the Controller's cache " "and from the table '%s' on the '%s' node" % (flow_id, table_id, nodeName)) time.sleep(rundelay) result = ofswitch.delete_flow(flow_entry.get_flow_table_id(), flow_entry.get_flow_id()) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully removed from the Controller") else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print (">>> Demo End") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def nc_demo_13(): f = "cfg1.yml" d = {} if (load_dict_from_file(f, d) is False): print("Config file '%s' read error: " % f) exit() try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] rundelay = d['rundelay'] except: print("Failed to get Controller device attributes") exit(0) netconf_ids = [] netconf_nodes = [] print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print("<<< Demo Start") print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print "\n" ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) print("<<< Controller '%s:%s'" % (ctrlIpAddr, ctrlPortNum)) time.sleep(rundelay) print "\n" print("<<< Get NETCONF Inventory Information") time.sleep(rundelay) result = ctrl.get_netconf_nodes_in_config() status = result.get_status() if (status.eq(STATUS.OK)): netconf_ids = result.get_data() else: print("\n") print( "!!!Demo terminated, " "failed to get list of NETCONF devices, " "reason: %s" % status.brief()) exit(0) print "\n" print("<<< NETCONF devices") print "\n".strip() for node_id in netconf_ids: print " %s" % node_id for node_id in netconf_ids: result = ctrl.build_netconf_node_inventory_object(node_id) status = result.get_status() if (status.eq(STATUS.OK)): node = result.get_data() assert (isinstance(node, NetconfCapableNode)) netconf_nodes.append(node) else: print("\n") print( "!!!Demo terminated, " "failed to build object for NETCONF device '%s', " "reason: %s" % (node_id, status.brief())) exit(0) for node in netconf_nodes: time.sleep(rundelay) print "\n".strip() print "<<< Information for '{}' device".format(node.get_id()) print "\n".strip() print " Device Name : {}".format(node.get_id()) print " Connection status : {}".format(node.get_conn_status()) print "\n".strip() print " Initial Capabilities" print " {}".format('-' * 60) clist = node.get_initial_capabilities() for item in clist: print " {}".format(item) print("\n") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print(">>> Demo End") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def of_demo_22(): f = "cfg.yml" d = {} if (load_dict_from_file(f, d) is False): print("Config file '%s' read error: " % f) exit() try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] nodeName = d['nodeName'] rundelay = d['rundelay'] except: print("Failed to get Controller device attributes") exit(0) print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print("<<< Demo 22 Start") print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) ofswitch = OFSwitch(ctrl, nodeName) # --- Flow Match: Ethernet Type # Input Port # IPv4 Destination Address eth_type = ETH_TYPE_IPv4 in_port = 13 ipv4_dst = "10.12.5.4/32" # --- Flow Actions: Push MPLS # Set Field # Output push_ether_type = ETH_TYPE_MPLS_UCAST mpls_label = 27 output_port = 14 print("<<< 'Controller': %s, 'OpenFlow' switch: '%s'" % (ctrlIpAddr, nodeName)) print "\n" print("<<< Set OpenFlow flow on the Controller") print( " Match: Ethernet Type (%s)\n" " Input Port (%s)\n" " IPv4 Destination Address (%s)" % (hex(eth_type), in_port, ipv4_dst)) print( " Action: Push MPLS Header (Ethernet Type %s)\n" " Set Field (MPLS label %s)\n" " Output (Physical Port number %s)" % (hex(push_ether_type), mpls_label, output_port)) time.sleep(rundelay) flow_entry = FlowEntry() table_id = 0 flow_id = 28 flow_entry.set_flow_table_id(table_id) flow_entry.set_flow_name(flow_name="Push MPLS Label") flow_entry.set_flow_id(flow_id) flow_entry.set_flow_hard_timeout(hard_timeout=0) flow_entry.set_flow_idle_timeout(idle_timeout=0) flow_entry.set_flow_priority(flow_priority=1021) flow_entry.set_flow_cookie(cookie=654) flow_entry.set_flow_cookie_mask(cookie_mask=255) # --- Instruction: 'Apply-actions' # Actions: 'Push MPLS Header' # 'Set Field' # 'Output' instruction = Instruction(instruction_order=0) action = PushMplsHeaderAction(order=0) action.set_eth_type(push_ether_type) instruction.add_apply_action(action) action = SetFieldAction(order=1) action.set_mpls_label(mpls_label) instruction.add_apply_action(action) action = OutputAction(order=2, port=output_port) instruction.add_apply_action(action) flow_entry.add_instruction(instruction) # --- Match Fields: Ethernet Type # Input Port # IPv4 Destination Address match = Match() match.set_eth_type(eth_type) match.set_in_port(in_port) match.set_ipv4_dst(ipv4_dst) flow_entry.add_match(match) print("\n") print("<<< Flow to send:") print flow_entry.get_payload() time.sleep(rundelay) result = ofswitch.add_modify_flow(flow_entry) status = result.get_status() if (status.eq(STATUS.OK)): print("<<< Flow successfully added to the Controller") else: print("\n") print("!!!Demo terminated, reason: %s" % status.detailed()) exit(0) print("\n") print("<<< Get configured flow from the Controller") time.sleep(rundelay) result = ofswitch.get_configured_flow(table_id, flow_id) status = result.get_status() if (status.eq(STATUS.OK)): print("<<< Flow successfully read from the Controller") print("Flow info:") flow = result.get_data() print json.dumps(flow, indent=4) else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print("\n") print( "<<< Delete flow with id of '%s' from the Controller's cache " "and from the table '%s' on the '%s' node" % (flow_id, table_id, nodeName)) time.sleep(rundelay) result = ofswitch.delete_flow(flow_entry.get_flow_table_id(), flow_entry.get_flow_id()) status = result.get_status() if (status.eq(STATUS.OK)): print("<<< Flow successfully removed from the Controller") else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print("\n") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print(">>> Demo End") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def of_demo_29(): f = "cfg.yml" d = {} if (load_dict_from_file(f, d) is False): print("Config file '%s' read error: " % f) exit() try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] rundelay = d['rundelay'] except: print("Failed to get Controller device attributes") exit(0) description = ( "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n" " This demo illustrates how to use Controller's notification \n" " subscription service for tracing dynamic changes in the\n" " network topology data tree maintained by the Controller.\n" "\n" " It is implied that core network services (Forwarding Rules\n" " Manager, Topology Manager, Switch Manager, Host Tracker)\n" " are functioning on the Controller\n" "\n" " This script creates an event listener on the Controller and\n" " establishes permanent connection to the events notification\n" " stream. Once a data change event in the topology tree (such\n" " as add/remove switch, host or link) is detected it will be\n" " reported to the screen.\n" "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n") print "\n".strip() print description print "\n".strip() time.sleep(rundelay) print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print("<<< Demo 29 Start") print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) # Identifier of the network topology to be traced # (name used by Controller for default topology instance) topo_id = 'flow:1' print "\n".strip() print("<<< 'Controller': %s, Topology Identifier: '%s'" % (ctrlIpAddr, topo_id)) time.sleep(rundelay) # Data store for the changes # Can be one of: # - CONFIGURATION: Logical data store representing configuration # state of the system and it's components. # - OPERATIONAL: Logical data store representing operational # state of the system and it's components datastore = "OPERATIONAL" # Scope of the data changes # Can be one of: # - BASE: Represents only a direct change of the node, such as # replacement, addition or deletion of the node. # - ONE: Represent a change (addition, replacement, deletion) # of the node or one of its direct children. # This scope is a superset of BASE. # - SUBTREE: Represents a change of the node or any of its child # nodes, direct and nested. # This scope is superset of ONE and BASE. scope = "SUBTREE" # Path to the network topology node in the YANG data tree path = ctrl.get_network_topology_yang_schema_path(topo_id) # Create listener on the Controller (if it does already exist Controller # just returns the stream name to subscribe to) result = ctrl.create_data_change_event_subscription(datastore, scope, path) status = result.get_status() if not status.eq(STATUS.OK): print("\n") print("!!!Demo terminated, reason: %s" % status.detailed()) exit(1) stream_name = result.get_data() # Subscribe to the stream result = ctrl.subscribe_to_stream(stream_name) status = result.get_status() if not status.eq(STATUS.OK): print("\n") print("!!!Demo terminated, reason: %s" % status.detailed()) exit(1) print "\n".strip() print " Successfully subscribed for data change notifications" print " Stream location:" stream_location = result.get_data() print " %s" % stream_location print "\n".strip() print " Listening ... (CTRL-C to exit)" print "\n".strip() # Connect to the notification stream on the Controller # and start listening for the data change notifications # (report only events that we are really interested in) websock = create_connection(stream_location) try: while True: event = websock.recv() tcn = NetworkTopologyChangeNotification(event) timestamp = tcn.get_time() l = tcn.switches_added() if l and len(l): for i in l: print " [%s] added switch: %s" % (timestamp, i) l = tcn.switches_removed() if l and len(l): for i in l: print " [%s] removed switch: %s" % (timestamp, i) l = tcn.hosts_added() if l and len(l): for i in l: print " [%s] added host: %s" % (timestamp, i) l = tcn.hosts_removed() if l and len(l): for i in l: print " [%s] removed host: %s" % (timestamp, i) l = tcn.links_added() if l and len(l): for i in l: print " [%s] added link: %s" % (timestamp, i) l = tcn.links_removed() if l and len(l): for i in l: print " [%s] removed link: %s" % (timestamp, i) except (KeyboardInterrupt): print "Interrupted from keyboard, exit\n" websock.close() print("\n") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print(">>> Demo End") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def of_demo_32(): f = "cfg.yml" d = {} if(load_dict_from_file(f, d) is False): print("Config file '%s' read error: " % f) exit(0) try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] rundelay = d['rundelay'] except: print ("Failed to get Controller device attributes") exit(0) openflow_nodes = [] print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print ("<<< Demo 32 Start") print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print "\n" ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) print ("<<< Controller '%s:%s'" % (ctrlIpAddr, ctrlPortNum)) time.sleep(rundelay) print "\n".strip() print ("<<< Get OpenFlow switches information") time.sleep(rundelay) inv_obj = None result = ctrl.build_inventory_object() status = result.get_status() if(status.eq(STATUS.OK)): inv_obj = result.get_data() assert(isinstance(inv_obj, Inventory)) else: print ("\n") print ("!!!Error, failed to obtain inventory info, reason: %s" % status.brief().lower()) exit(0) assert(inv_obj) openflow_node_ids = inv_obj.get_openflow_node_ids() for node_id in openflow_node_ids: node = inv_obj.get_openflow_node(node_id) assert(isinstance(node, OpenFlowCapableNode)) openflow_nodes.append(node) print "\n".strip() print ("<<< OpenFlow switches in the inventory store") s1 = 'IP Address' s2 = 'OpenFlow Id' sym = '-' print "\n".strip() print " {0:<15} {1:<30}".format(s1, s2) print " {0:<15} {1:<30}".format(sym * 15, sym * 30) for node in openflow_nodes: addr = node.get_ip_address() node_id = node.get_id() print " {0:<15} {1:<30}".format(addr, node_id) print "\n".strip() print ("<<< Get Group Features Information") time.sleep(rundelay) for node in openflow_nodes: assert(isinstance(node, OpenFlowCapableNode)) print "\n".strip() switch_id = node.get_id() print (" Switch '%s'") % switch_id print "\n".strip() group_features = node.get_group_features() assert(isinstance(group_features, GroupFeatures)) q = 2 # number of list items to be in a single chunk (output string) s = 'Max groups' alist = group_features.get_max_groups() if alist: chunks = [alist[x:x + q] for x in xrange(0, len(alist), q)] print " %s :" % s, for i in range(0, len(chunks)): n = 0 if i == 0 else len(s) + 19 print "%s%s" % (" " * n, ", ".join(map(str, chunks[i]))) else: print " %s : %s" % (s, "n/a") s = 'Group types' alist = group_features.get_types() if alist: chunks = [alist[x:x + q] for x in xrange(0, len(alist), q)] print " %s :" % s, for i in range(0, len(chunks)): n = 0 if i == 0 else len(s) + 18 print "%s%s" % (" " * n, ", ".join(chunks[i])) else: print " %s : %s" % (s, "n/a") s = 'Capabilities' alist = group_features.get_capabilities() if alist: chunks = [alist[x:x + q] for x in xrange(0, len(alist), q)] print " %s :" % s, for i in range(0, len(chunks)): n = 0 if i == 0 else len(s) + 17 print "%s%s" % (" " * n, ", ".join(chunks[i])) else: print " %s : %s" % (s, "n/a") s = 'Actions' actions = group_features.get_actions() if actions: print " %s :" % s, for i, alist in enumerate(actions): n = 0 if i == 0 else len(s) + 12 chunks = [alist[x:x + q] for x in xrange(0, len(alist), q)] for j in range(0, len(chunks)): n = 0 if i == 0 and j == 0 else len(s) + 22 print "%s%s" % (" " * n, ", ".join(chunks[j])) print "\n".strip() else: print " %s : %s" % (s, "n/a") print "\n".strip() total_num = node.get_groups_total_num() s = 'Num of groups' print " %s : %s" % (s, total_num) s = 'Group IDs' alist = node.get_group_ids() if alist: chunks = [alist[x:x + q] for x in xrange(0, len(alist), q)] print " %s :" % s, for i in range(0, len(chunks)): n = 0 if i == 0 else len(s) + 13 print "%s%s" % (" " * n, ", ".join(map(str, chunks[i]))) else: print " %s : %s" % (s, "") print ("\n") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print (">>> Demo End") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
""" import json from pybvc.controller.controller import Controller from pybvc.netconfdev.vrouter.vrouter5600 import VRouter5600 from pybvc.common.status import STATUS from pybvc.common.utils import load_dict_from_file if __name__ == "__main__": f = "cfg.yml" d = {} if (load_dict_from_file(f, d) is False): print("Config file '%s' read error: " % f) exit() try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] nodeName = d['nodeName'] nodeIpAddr = d['nodeIpAddr'] nodePortNum = d['nodePortNum'] nodeUname = d['nodeUname'] nodePswd = d['nodePswd'] except:
def of_demo_8(): f = "cfg.yml" d = {} if(load_dict_from_file(f, d) is False): print("Config file '%s' read error: " % f) exit() try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] nodeName = d['nodeName'] rundelay = d['rundelay'] except: print ("Failed to get Controller device attributes") exit(0) print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print ("<<< Demo 8 Start") print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) ofswitch = OFSwitch(ctrl, nodeName) # --- Flow Match: Ethernet Source Address # Ethernet Destination Address # IPv4 Source Address # IPv4 Destination Address # IP Protocol Number # IP DSCP # Input Port # NOTE: Ethernet type MUST be 2048 (0x800) -> IPv4 protocol eth_type = ETH_TYPE_IPv4 eth_src = "00:1c:01:00:23:aa" eth_dst = "00:02:02:60:ff:fe" ipv4_src = "10.0.245.1/24" ipv4_dst = "192.168.1.123/16" ip_proto = IP_PROTO_TLSP ip_dscp = IP_DSCP_CS3 # 'Class Selector' = 'Flash' input_port = 13 print ("<<< 'Controller': %s, 'OpenFlow' switch: '%s'" % (ctrlIpAddr, nodeName)) print "\n" print ("<<< Set OpenFlow flow on the Controller") print (" Match: Ethernet Type (%s)\n" " Ethernet Source Address (%s)\n" " Ethernet Destination Address (%s)\n" " IPv4 Source Address (%s)\n" " IPv4 Destination Address (%s)\n" " IP Protocol Number (%s)\n" " IP DSCP (%s)\n" " Input Port (%s)" % (hex(eth_type), eth_src, eth_dst, ipv4_src, ipv4_dst, ip_proto, ip_dscp, input_port)) print (" Action: Output (CONTROLLER)") time.sleep(rundelay) flow_entry = FlowEntry() table_id = 0 flow_entry.set_flow_table_id(table_id) flow_id = 15 flow_entry.set_flow_id(flow_id) flow_entry.set_flow_priority(flow_priority=1006) flow_entry.set_flow_cookie(cookie=100) flow_entry.set_flow_cookie_mask(cookie_mask=255) # --- Instruction: 'Apply-actions' # Action: 'Output' to CONTROLLER instruction = Instruction(instruction_order=0) action = OutputAction(order=0, port="CONTROLLER", max_len=60) instruction.add_apply_action(action) flow_entry.add_instruction(instruction) # --- Match Fields: Ethernet Type # Ethernet Source Address # Ethernet Destination Address # IPv4 Source Address # IPv4 Destination Address # IP Protocol Number # IP DSCP # Input Port match = Match() match.set_eth_type(eth_type) match.set_eth_src(eth_src) match.set_eth_dst(eth_dst) match.set_ipv4_src(ipv4_src) match.set_ipv4_dst(ipv4_dst) match.set_ip_proto(ip_proto) match.set_ip_dscp(ip_dscp) match.set_in_port(input_port) flow_entry.add_match(match) print ("\n") print ("<<< Flow to send:") print flow_entry.get_payload() time.sleep(rundelay) result = ofswitch.add_modify_flow(flow_entry) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully added to the Controller") else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print ("<<< Get configured flow from the Controller") time.sleep(rundelay) result = ofswitch.get_configured_flow(table_id, flow_id) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully read from the Controller") print ("Flow info:") flow = result.get_data() print json.dumps(flow, indent=4) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print ("<<< Delete flow with id of '%s' from the Controller's cache " "and from the table '%s' on the '%s' node" % (flow_id, table_id, nodeName)) time.sleep(rundelay) result = ofswitch.delete_flow(flow_entry.get_flow_table_id(), flow_entry.get_flow_id()) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully removed from the Controller") else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print (">>> Demo End") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def of_demo_34(): f = "cfg.yml" d = {} if(load_dict_from_file(f, d) is False): print("Config file '%s' read error: " % f) exit() try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] nodeName = d['nodeName'] rundelay = d['rundelay'] except: print ("Failed to get Controller device attributes") exit(0) openflow_node_ids = [] openflow_nodes = [] print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print ("<<< Demo 34 Start") print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) ofswitch = OFSwitch(ctrl, nodeName) print "\n".strip() print ("<<< 'Controller': %s, 'OpenFlow' switch: '%s'" % (ctrlIpAddr, nodeName)) grp_ids_cfg = [] grp_ids_oper = [] print "\n".strip() print ("<<< Get OpenFlow Groups Information") time.sleep(rundelay) result = ofswitch.get_configured_group_ids() status = result.get_status() if(status.eq(STATUS.OK)): grp_ids_cfg = result.get_data() elif(status.eq(STATUS.DATA_NOT_FOUND)): grp_ids_cfg = [] else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.detailed()) exit(0) result = ofswitch.get_operational_group_ids() status = result.get_status() if(status.eq(STATUS.OK)): grp_ids_oper = result.get_data() elif(status.eq(STATUS.DATA_NOT_FOUND)): grp_ids_oper = [] else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.detailed()) exit(0) # Show current state of the Group Table in the Controller's # configuration and operational data stores print_groups(grp_ids_cfg, grp_ids_oper) # Create new group group_id = 13 group_type = OFPGT_SELECT group_name = "Example of 'load balancing' group" weight1 = 60 weight2 = 30 weight3 = 10 out_port1 = 110 out_port2 = 111 out_port3 = 112 print "\n".strip() print ("<<< Create Group") print "\n".strip() print (" Group Type : %s\n" " Group ID : %s\n" " Group Name : \"%s\"" % (group_type.strip('group-').upper(), group_id, group_name)) print (" Buckets :") print (" [0] weight : %s" % weight1) print (" actions: Output (%s)" % out_port1) print (" [1] weight : %s" % weight2) print (" actions: Output (%s)" % out_port2) print (" [2] weight : %s" % weight3) print (" actions: Output (%s)" % out_port3) time.sleep(rundelay) # Allocate a placeholder for the group entry group_entry = GroupEntry(group_id, group_type) group_entry.set_group_name(group_name) # Fill in group entry with action buckets # --------- bucket_id = 0 bucket1 = GroupBucket(bucket_id) bucket1.set_weight(weight1) action = OutputAction(order=0, port=out_port1) bucket1.add_action(action) group_entry.add_bucket(bucket1) # --------- bucket_id += 1 bucket2 = GroupBucket(bucket_id) bucket2.set_weight(weight2) action = OutputAction(order=0, port=out_port2) bucket2.add_action(action) group_entry.add_bucket(bucket2) # --------- bucket_id += 1 bucket3 = GroupBucket(bucket_id) bucket3.set_weight(weight3) action = OutputAction(order=0, port=out_port3) bucket3.add_action(action) group_entry.add_bucket(bucket3) # Request Controller to create the group print "\n".strip() print ("<<< Group to create:") print group_entry.get_payload() time.sleep(rundelay) result = ofswitch.add_modify_group(group_entry) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Group successfully added") grp_ids_oper = result.get_data() else: print ("\n").strip() print ("!!!Demo terminated, reason: %s" % status.detailed()) exit(0) print ("\n").strip() print ("<<< Get group '%s' configuration status") % group_id time.sleep(rundelay) result = ofswitch.get_configured_group(group_id) status = result.get_status() if(status.eq(STATUS.OK)): grp = result.get_data() print ("Group configuration info:") group = result.get_data() print json.dumps(group, indent=4) else: print ("\n").strip() print ("!!!Demo terminated, reason: %s" % status.detailed()) exit(0) print ("\n").strip() print ("<<< Get group '%s' operational status") % group_id time.sleep(rundelay) result = ofswitch.get_group_description(group_id) status = result.get_status() if(status.eq(STATUS.OK)): grp = result.get_data() print ("Group operational info:") group = result.get_data() print json.dumps(group, indent=4) else: print ("\n").strip() print ("!!!Error, reason: %s" % status.detailed()) print ("\n").strip() print ("<<< Get group '%s' statistics information") % group_id time.sleep(rundelay) result = ofswitch.get_group_statistics(group_id) status = result.get_status() if(status.eq(STATUS.OK)): grp = result.get_data() print ("Group statistics info:") group = result.get_data() print json.dumps(group, indent=4) else: print ("\n").strip() print ("!!!Error, reason: %s" % status.detailed()) print ("\n").strip() print ("<<< Get OpenFlow Groups Information") time.sleep(rundelay) result = ofswitch.get_configured_group_ids() status = result.get_status() if(status.eq(STATUS.OK)): grp_ids_cfg = result.get_data() elif(status.eq(STATUS.DATA_NOT_FOUND)): grp_ids_cfg = [] else: print ("\n").strip() print ("!!!Error, reason: %s" % status.detailed()) result = ofswitch.get_operational_group_ids() status = result.get_status() if(status.eq(STATUS.OK)): grp_ids_oper = result.get_data() elif(status.eq(STATUS.DATA_NOT_FOUND)): grp_ids_oper = [] else: print ("\n").strip() print ("!!!Error, reason: %s" % status.detailed()) # Show current state of the Group Table in the Controller's # configuration and operational data stores print_groups(grp_ids_cfg, grp_ids_oper) print "\n".strip() print ("<<< Remove all groups from the Controller") for group_id in grp_ids_cfg: result = ofswitch.delete_group(group_id) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Group '%s' successfully removed from the Controller" % group_id) else: print ("\n").strip() print ("!!!Error, failed to remove group '%s', reason: %s" % (group_id, status.detailed())) print ("\n").strip() print ("<<< Get OpenFlow Groups Information") time.sleep(rundelay) result = ofswitch.get_configured_group_ids() status = result.get_status() if(status.eq(STATUS.OK)): grp_ids_cfg = result.get_data() elif(status.eq(STATUS.DATA_NOT_FOUND)): grp_ids_cfg = [] else: print ("\n").strip() print ("!!!Error, reason: %s" % status.detailed()) result = ofswitch.get_operational_group_ids() status = result.get_status() if(status.eq(STATUS.OK)): grp_ids_oper = result.get_data() elif(status.eq(STATUS.DATA_NOT_FOUND)): grp_ids_oper = [] else: print ("\n") print ("!!!Error, reason: %s" % status.detailed()) # Show current state of the Group Table in the Controller's # configuration and operational data stores print_groups(grp_ids_cfg, grp_ids_oper) print ("\n").strip() print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print (">>> Demo End") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def of_demo_1(): f = "cfg.yml" d = {} if(load_dict_from_file(f, d) is False): print("Config file '%s' read error: " % f) exit() try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] # nodeName = d['nodeName'] rundelay = d['rundelay'] except: print ("Failed to get Controller device attributes") exit(0) print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print ("<<< Demo 1 Start") print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print ("\n") print ("<<< Creating Controller instance") time.sleep(rundelay) ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd, None) print ("'Controller':") print ctrl.brief_json() print "\n" print ("<<< Get list of OpenFlow nodes connected to the Controller") time.sleep(rundelay) result = ctrl.get_openflow_nodes_operational_list() status = result.get_status() if(status.eq(STATUS.OK)): print ("OpenFlow node names (composed as \"openflow:datapathid\"):") nodenames = result.get_data() print json.dumps(nodenames, indent=4) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print "\n" print ("<<< Get generic information about OpenFlow nodes") time.sleep(rundelay) for name in nodenames: ofswitch = OFSwitch(ctrl, name) result = ofswitch.get_switch_info() status = result.get_status() if(status.eq(STATUS.OK)): print ("'%s' info:" % name) info = result.get_data() print json.dumps(info, indent=4) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print (">>> Demo End") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def vr_demo_8(): f = "cfg4.yml" d = {} if (load_dict_from_file(f, d) is False): print("Config file '%s' read error: " % f) exit() try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] nodeName = d['nodeName'] nodeIpAddr = d['nodeIpAddr'] nodePortNum = d['nodePortNum'] nodeUname = d['nodeUname'] nodePswd = d['nodePswd'] rundelay = d['rundelay'] except: print("Failed to get Controller device attributes") exit(0) print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print("<<< Demo Start") print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) vrouter = VRouter5600(ctrl, nodeName, nodeIpAddr, nodePortNum, nodeUname, nodePswd) print("<<< 'Controller': %s, '%s': %s" % (ctrlIpAddr, nodeName, nodeIpAddr)) print("\n") time.sleep(rundelay) node_configured = False result = ctrl.check_node_config_status(nodeName) status = result.get_status() if (status.eq(STATUS.NODE_CONFIGURED)): node_configured = True print("<<< '%s' is configured on the Controller" % nodeName) elif (status.eq(STATUS.DATA_NOT_FOUND)): node_configured = False else: print("\n") print "Failed to get configuration status for the '%s'" % nodeName print("!!!Demo terminated, reason: %s" % status.detailed()) exit(0) if node_configured is False: result = ctrl.add_netconf_node(vrouter) status = result.get_status() if (status.eq(STATUS.OK)): print("<<< '%s' added to the Controller" % nodeName) else: print("\n") print("!!!Demo terminated, reason: %s" % status.detailed()) exit(0) print("\n") time.sleep(rundelay) result = ctrl.check_node_conn_status(nodeName) status = result.get_status() if (status.eq(STATUS.NODE_CONNECTED)): print("<<< '%s' is connected to the Controller" % nodeName) else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print("\n") print("<<< Show VPN configuration on the '%s'" % nodeName) result = vrouter.get_vpn_cfg() time.sleep(rundelay) status = result.get_status() if (status.eq(STATUS.OK)): print("'%s' VPN configuration:" % nodeName) cfg = result.get_data() data = json.loads(cfg) print json.dumps(data, indent=4, sort_keys=True) elif (status.eq(STATUS.DATA_NOT_FOUND)): print("No VPN configuration found") else: print("\n") print("!!!Demo terminated, reason: %s" % status.detailed()) ctrl.delete_netconf_node(vrouter) exit(0) print "\n" print(">>> Create new VPN configuration on the '%s'" % (nodeName)) description = ("Remote Access VPN Configuration Example - " "L2TP/IPsec with Pre-Shared Key") external_ipaddr = "12.34.56.78" nexthop_ipaddr = "12.34.56.254" nat_traversal = True nat_allow_network = "192.168.100.0/24" client_ip_pool_start = "192.168.100.11" client_ip_pool_end = "192.168.100.210" ipsec_auth_mode = "pre-shared-secret" ipsec_auth_secret = "!secrettext!" l2tp_auth_mode = "local" uname1 = "user1" upswd1 = "user1_password" uname2 = "user2" upswd2 = "user2_password" uname3 = "user3" upswd3 = "user3_password" dns_srv1 = "192.168.100.1" dns_srv2 = "192.168.100.2" wins_srv1 = "192.168.100.3" wins_srv2 = "192.168.100.4" mtu = "16384" print( " VPN options to be set:\n" " - Configuration description : '%s'\n" " - Server external address : '%s'\n" " - Next hop router address : '%s'\n" " - NAT_traversal : '%s'\n" " - NAT allowed networks : '%s'\n" " - Client addresses pool (start/end) : '%s'/'%s'\n" " - IPsec authentication (mode/secret) : '%s'/'%s'\n" " - L2TP authentication mode : '%s'\n" " - Allowed users (name/password) : '%s'/'%s'\n" " '%s'/'%s'\n" " '%s'/'%s'\n" " - DNS servers (primary/secondary) : '%s'/'%s'\n" " - WINS servers (primary/secondary) : '%s'/'%s'\n" " - Maximum Transmission Unit : '%s'\n" % (description, external_ipaddr, nexthop_ipaddr, "enabled" if nat_traversal else "disabled", nat_allow_network, client_ip_pool_start, client_ip_pool_end, ipsec_auth_mode, ipsec_auth_secret, l2tp_auth_mode, uname1, upswd1, uname2, upswd2, uname3, upswd3, dns_srv1, dns_srv2, wins_srv1, wins_srv2, mtu)) time.sleep(rundelay) # ------------------------------------------------------------------------- # Encode VPN configuration options by using 'Vpn' object # ------------------------------------------------------------------------- vpn = Vpn() # This VPN configuration description vpn.set_l2tp_remote_access_description(description) # Enable NAT traversal vpn.set_nat_traversal(nat_traversal) # Set the allowed subnets vpn.set_nat_allow_network(nat_allow_network) # Bind the L2TP server to the external IP address vpn.set_l2tp_remote_access_outside_address(external_ipaddr) # Set the next hop IP address for reaching the VPN clients vpn.set_l2tp_remote_access_outside_nexthop(nexthop_ipaddr) # Set up the pool of IP addresses that remote VPN connections will assume. # In this example we make 100 addresses available (from .11 to .210) on # subnet 192.168.100.0/24 vpn.set_l2tp_remote_access_client_ip_pool(start=client_ip_pool_start, end=client_ip_pool_end) # Set the IPsec authentication mode to 'pre-shared-secret' vpn.set_l2tp_remote_access_ipsec_auth_mode(mode=ipsec_auth_mode) # Set the 'pre-shared-secret' value func = vpn.set_l2tp_remote_access_ipsec_auth_pre_shared_secret func(secret=ipsec_auth_secret) # Set the L2TP remote access user authentication mode to 'local' vpn.set_l2tp_remote_access_user_auth_mode(l2tp_auth_mode) # Set the L2TP remote access user credentials ('username'/'password') vpn.set_l2tp_remote_access_user(name=uname1, pswd=upswd1) vpn.set_l2tp_remote_access_user(name=uname2, pswd=upswd2) vpn.set_l2tp_remote_access_user(name=uname3, pswd=upswd3) # Set 'primary' and 'secondary' DNS servers vpn.set_l2tp_remote_access_primary_dns_server(dns_srv1) vpn.set_l2tp_remote_access_secondary_dns_server(dns_srv2) # Set 'primary' and 'secondary' WINS servers vpn.set_l2tp_remote_access_primary_wins_server(wins_srv1) vpn.set_l2tp_remote_access_secondary_wins_server(wins_srv2) # Set Maximum Transmission Unit (MTU <128..16384>) vpn.set_l2tp_remote_access_mtu(mtu) print "\n" print(">>> VPN configuration to be applied to the '%s'" % (nodeName)) print vpn.get_payload() time.sleep(rundelay) result = vrouter.set_vpn_cfg(vpn) status = result.get_status() if (status.eq(STATUS.OK)): print("<<< VPN configuration was successfully created") else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) print status.detailed() ctrl.delete_netconf_node(vrouter) exit(0) print "\n" print("<<< Show VPN configuration on the '%s'" % (nodeName)) time.sleep(rundelay) result = vrouter.get_vpn_cfg() status = result.get_status() if (status.eq(STATUS.OK)): print("'%s' VPN configuration:" % nodeName) cfg = result.get_data() data = json.loads(cfg) print json.dumps(data, indent=4, sort_keys=True) print("<<< VPN configuration was successfully read") else: print("\n") print("!!!Demo terminated, reason: %s" % status.detailed()) ctrl.delete_netconf_node(vrouter) exit(0) print "\n" print("<<< Delete VPN configuration from the '%s'" % (nodeName)) time.sleep(rundelay) result = vrouter.delete_vpn_cfg() status = result.get_status() if (status.eq(STATUS.OK)): print("VPN configuration successfully removed from '%s'" % (nodeName)) else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) print status.detailed() ctrl.delete_netconf_node(vrouter) exit(0) print "\n" print("<<< Show VPN configuration on the '%s'" % (nodeName)) time.sleep(rundelay) result = vrouter.get_vpn_cfg() status = result.get_status() if (status.eq(STATUS.OK)): print("'%s' VPN configuration:" % nodeName) cfg = result.get_data() data = json.loads(cfg) print json.dumps(data, indent=4, sort_keys=True) elif (status.eq(STATUS.DATA_NOT_FOUND)): print("No VPN configuration found") else: print("\n") print("!!!Demo terminated, reason: %s" % status.detailed()) ctrl.delete_netconf_node(vrouter) exit(0) print "\n" print(">>> Remove '%s' NETCONF node from the Controller" % nodeName) time.sleep(rundelay) result = ctrl.delete_netconf_node(vrouter) status = result.get_status() if (status.eq(STATUS.OK)): print( "'%s' NETCONF node was successfully removed " "from the Controller" % nodeName) else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief()) exit(0) print("\n") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print(">>> Demo End")
def of_demo_40(): f = "cfg.yml" d = {} if(load_dict_from_file(f, d) is False): print("Config file '%s' read error: " % f) exit(0) try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] nodeName = d['nodeName'] rundelay = d['rundelay'] except: print ("Failed to get Controller device attributes") exit(0) print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print ("<<< Demo 40 Start") print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) ofswitch = OFSwitch(ctrl, nodeName) print ("<<< 'Controller': %s, 'OpenFlow' switch: '%s'" % (ctrlIpAddr, nodeName)) first_flow_id = 110 # --------------------------------------------------- # First flow entry # --------------------------------------------------- table_id = 0 flow_id = first_flow_id flow_name = "Modify IP packet example1" priority = 900 cookie = 1300 match_in_port = 10 match_eth_type = ETH_TYPE_IPv4 match_ip_proto = IP_PROTO_TCP match_ipv4_src_addr = "192.1.2.0/24" match_ipv4_dst_addr = "173.194.123.40/32" match_tcp_dst_port = 8080 act_mod_ipv4_src_addr = "212.16.1.8/32" act_mod_ipv4_dst_addr = "52.87.12.11/32" act_mod_tcp_src_port = 8888 act_mod_tcp_dst_port = 9999 act_out_port = 119 print "\n" print ("<<< Set OpenFlow flow on the Controller") print (" Match: Input Port (%s)\n" " Ethernet Type (%s)\n" " IP Protocol (%s)\n" " IPv4 Source Address (%s)\n" " IPv4 Destination Address (%s)\n" " TCP Destination Port (%s)" % (match_in_port, hex(match_eth_type), match_ip_proto, match_ipv4_src_addr, match_ipv4_dst_addr, match_tcp_dst_port)) print (" Actions: Modify IPv4 Source Address (%s)\n" " Modify IPv4 Destination Address (%s)\n" " Modify TCP Source Port (%s)\n" " Modify TCP Destination Port (%s)\n" " Output (%s)" % (act_mod_ipv4_src_addr, act_mod_ipv4_dst_addr, act_mod_tcp_src_port, act_mod_tcp_dst_port, act_out_port)) time.sleep(rundelay) # Allocate a placeholder for the Flow Entry flow_entry1 = FlowEntry() # Generic attributes of the Flow Entry flow_entry1.set_flow_table_id(table_id) flow_entry1.set_flow_name(flow_name) flow_entry1.set_flow_id(flow_id) flow_entry1.set_flow_cookie(cookie) flow_entry1.set_flow_priority(priority) flow_entry1.set_flow_hard_timeout(0) flow_entry1.set_flow_idle_timeout(0) # Instructions/Actions for the Flow Entry instruction = Instruction(instruction_order=0) action_order = 0 action = SetNwSrcAction(action_order) action.set_nw_src(act_mod_ipv4_src_addr) instruction.add_apply_action(action) action_order += 1 action = SetNwDstAction(action_order) action.set_nw_dst(act_mod_ipv4_dst_addr) instruction.add_apply_action(action) action_order += 1 action = SetTpSrcAction(action_order) action.set_tp_src(act_mod_tcp_src_port) instruction.add_apply_action(action) action_order += 1 action = SetTpDstAction(action_order) action.set_tp_dst(act_mod_tcp_dst_port) instruction.add_apply_action(action) action_order += 1 action = OutputAction(action_order) action.set_outport(act_out_port) instruction.add_apply_action(action) flow_entry1.add_instruction(instruction) # Match Fields for the Flow Entry match = Match() match.set_in_port(match_in_port) match.set_eth_type(match_eth_type) match.set_ip_proto(match_ip_proto) match.set_ipv4_src(match_ipv4_src_addr) match.set_ipv4_dst(match_ipv4_dst_addr) match.set_tcp_dst_port(match_tcp_dst_port) flow_entry1.add_match(match) print ("\n") print ("<<< Flow to send:") print flow_entry1.get_payload() time.sleep(rundelay) result = ofswitch.add_modify_flow(flow_entry1) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully added to the Controller") else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.detailed()) delete_flows(ofswitch, table_id, range(first_flow_id, flow_id + 1)) exit(0) # --------------------------------------------------- # Second flow entry # --------------------------------------------------- table_id = 0 flow_id += 1 flow_name = "Modify IP packet example2" priority = 900 cookie = 1300 match_in_port = 110 match_eth_type = ETH_TYPE_IPv4 match_ip_proto = IP_PROTO_UDP match_ipv4_src_addr = "10.1.0.0/16" match_ipv4_dst_addr = "168.1.1.101/32" match_udp_dst_port = 1812 act_mod_ipv4_src_addr = "172.101.1.9/32" act_mod_ipv4_dst_addr = "172.101.1.1/32" act_mod_udp_src_port = 5555 act_mod_udp_dst_port = 7777 act_out_port = 120 print "\n" print ("<<< Set OpenFlow flow on the Controller") print (" Match: Input Port (%s)\n" " Ethernet Type (%s)\n" " IP Protocol (%s)\n" " IPv4 Source Address (%s)\n" " IPv4 Destination Address (%s)\n" " UDP Destination Port (%s)" % (match_in_port, hex(match_eth_type), match_ip_proto, match_ipv4_src_addr, match_ipv4_dst_addr, match_udp_dst_port)) print (" Actions: Set Field (IPv4 Source Address %s)\n" " Set Field (IPv4 Destination Address %s)\n" " Set Field (UDP Source Port %s)\n" " Set Field (UDP Destination Port %s)\n" " Output (%s)" % (act_mod_ipv4_src_addr, act_mod_ipv4_dst_addr, act_mod_udp_src_port, act_mod_udp_dst_port, act_out_port)) time.sleep(rundelay) # Allocate a placeholder for the Flow Entry flow_entry2 = FlowEntry() # Generic attributes of the Flow Entry flow_entry2.set_flow_table_id(table_id) flow_entry2.set_flow_name(flow_name) flow_entry2.set_flow_id(flow_id) flow_entry2.set_flow_cookie(cookie) flow_entry2.set_flow_priority(priority) flow_entry2.set_flow_hard_timeout(0) flow_entry2.set_flow_idle_timeout(0) # Instructions/Actions for the Flow Entry instruction = Instruction(instruction_order=0) action_order = 0 action = SetFieldAction(action_order) action.set_ipv4_src(act_mod_ipv4_src_addr) instruction.add_apply_action(action) action_order += 1 action = SetFieldAction(action_order) action.set_ipv4_dst(act_mod_ipv4_dst_addr) instruction.add_apply_action(action) action_order += 1 action = SetFieldAction(action_order) action.set_udp_src_port(act_mod_udp_src_port) instruction.add_apply_action(action) action_order += 1 action = SetFieldAction(action_order) action.set_udp_dst_port(act_mod_udp_dst_port) instruction.add_apply_action(action) action_order += 1 action = OutputAction(action_order) action.set_outport(act_out_port) instruction.add_apply_action(action) flow_entry2.add_instruction(instruction) # Match Fields for the Flow Entry match = Match() match.set_in_port(match_in_port) match.set_eth_type(match_eth_type) match.set_ip_proto(match_ip_proto) match.set_ipv4_src(match_ipv4_src_addr) match.set_ipv4_dst(match_ipv4_dst_addr) match.set_udp_dst_port(match_udp_dst_port) flow_entry2.add_match(match) print ("\n") print ("<<< Flow to send:") print flow_entry2.get_payload() time.sleep(rundelay) result = ofswitch.add_modify_flow(flow_entry2) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully added to the Controller") else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.detailed()) delete_flows(ofswitch, table_id, range(first_flow_id, flow_id + 1)) exit(0) print ("\n") print ("<<< Delete flows from the Controller's cache " "and from the table '%s' on the '%s' node" % (table_id, nodeName)) time.sleep(rundelay) delete_flows(ofswitch, table_id, range(first_flow_id, flow_id + 1)) print ("\n") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print (">>> Demo End") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def of_demo_25(): f = "cfg.yml" d = {} if(load_dict_from_file(f, d) is False): print("Config file '%s' read error: " % f) exit() try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] nodeName = d['nodeName'] rundelay = d['rundelay'] except: print ("Failed to get Controller device attributes") exit(0) print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print ("<<< Demo 25 Start") print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) ofswitch = OFSwitch(ctrl, nodeName) table_id = 0 priority = 500 cookie = 1000 cookie_mask = 255 customer_port = 110 provider_port = 111 qinq_eth_type = ETH_TYPE_STAG # 802.1ad (QinQ) VLAN tagged frame dot1q_eth_type = ETH_TYPE_CTAG # 802.1q VLAN tagged frame arp_eth_type = ETH_TYPE_ARP ip_eth_type = ETH_TYPE_IPv4 provider_vlan_id = 100 # Provider VLAN customer_vlan_id = 998 # Customer VLAN first_flow_id = 31 print ("<<< 'Controller': %s, 'OpenFlow' switch: '%s'" % (ctrlIpAddr, nodeName)) # --------------------------------------------------- # First flow entry # --------------------------------------------------- print "\n" print ("<<< Set OpenFlow flow on the Controller") print (" Match: Ethernet Type (%s)\n" " VLAN ID (%s)\n" " Input Port (%s)" % (hex(arp_eth_type), customer_vlan_id, customer_port)) print (" Action: Push VLAN (Ethernet Type %s)\n" " Set Field (VLAN ID %s)\n" " Push VLAN (Ethernet Type %s)\n" " Set Field (VLAN ID %s)\n" " Output (Physical Port number %s)" % (hex(qinq_eth_type), provider_vlan_id, hex(dot1q_eth_type), customer_vlan_id, provider_port)) time.sleep(rundelay) flow_id = first_flow_id flow_entry1 = FlowEntry() flow_entry1.set_flow_table_id(table_id) fname = "[MLX1-A] Test flow (match:inport=110,arp;" + \ "actions:push-QINQ-tag,mod_vlan=100," + \ "push-DOT1Q-tag,mod_vlan=998,output:111)" flow_entry1.set_flow_name(flow_name=fname) flow_entry1.set_flow_id(flow_id) flow_entry1.set_flow_hard_timeout(hard_timeout=600) flow_entry1.set_flow_idle_timeout(idle_timeout=300) flow_entry1.set_flow_priority(priority) flow_entry1.set_flow_cookie(cookie) flow_entry1.set_flow_cookie_mask(cookie_mask) instruction = Instruction(instruction_order=0) action_order = 0 action = PushVlanHeaderAction(action_order) action.set_eth_type(qinq_eth_type) instruction.add_apply_action(action) action_order += 1 action = SetFieldAction(action_order) action.set_vlan_id(provider_vlan_id) instruction.add_apply_action(action) action_order += 1 action = PushVlanHeaderAction(action_order) action.set_eth_type(dot1q_eth_type) instruction.add_apply_action(action) action_order += 1 action = SetFieldAction(action_order) action.set_vlan_id(customer_vlan_id) instruction.add_apply_action(action) action_order += 1 action = OutputAction(action_order, provider_port) instruction.add_apply_action(action) flow_entry1.add_instruction(instruction) match = Match() match.set_eth_type(arp_eth_type) match.set_vlan_id(customer_vlan_id) match.set_in_port(in_port=customer_port) flow_entry1.add_match(match) print ("\n") print ("<<< Flow to send:") print flow_entry1.get_payload() time.sleep(rundelay) result = ofswitch.add_modify_flow(flow_entry1) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully added to the Controller") else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.detailed()) delete_flows(ofswitch, table_id, range(first_flow_id, flow_id+1)) exit(0) # --------------------------------------------------- # Second flow entry # --------------------------------------------------- print "\n" print ("<<< Set OpenFlow flow on the Controller") print (" Match: Ethernet Type (%s)\n" " VLAN ID (%s)\n" " Input Port (%s)" % (hex(ip_eth_type), customer_vlan_id, customer_port)) print (" Action: Push VLAN (Ethernet Type %s)\n" " Set Field (VLAN ID %s)\n" " Push VLAN (Ethernet Type %s)\n" " Set Field (VLAN ID %s)\n" " Output (Physical Port number %s)" % (hex(qinq_eth_type), provider_vlan_id, hex(dot1q_eth_type), customer_vlan_id, provider_port)) time.sleep(rundelay) flow_id += 1 flow_entry2 = FlowEntry() flow_entry2.set_flow_table_id(table_id) fname = "[MLX1-A] Test flow (match:inport=110,ip;" + \ "actions:push-QINQ-tag,mod_vlan=100,output:111)" flow_entry2.set_flow_name(flow_name=fname) flow_entry2.set_flow_id(flow_id) flow_entry2.set_flow_hard_timeout(hard_timeout=600) flow_entry2.set_flow_idle_timeout(idle_timeout=300) flow_entry2.set_flow_priority(priority) flow_entry2.set_flow_cookie(cookie) flow_entry2.set_flow_cookie_mask(cookie_mask) instruction = Instruction(instruction_order=0) action_order = 0 action = PushVlanHeaderAction(action_order) action.set_eth_type(qinq_eth_type) instruction.add_apply_action(action) action_order += 1 action = SetFieldAction(action_order) action.set_vlan_id(provider_vlan_id) instruction.add_apply_action(action) action_order += 1 action = PushVlanHeaderAction(action_order) action.set_eth_type(dot1q_eth_type) instruction.add_apply_action(action) action_order += 1 action = SetFieldAction(action_order) action.set_vlan_id(customer_vlan_id) instruction.add_apply_action(action) action_order += 1 action = OutputAction(action_order, provider_port) instruction.add_apply_action(action) flow_entry2.add_instruction(instruction) match = Match() match.set_eth_type(ip_eth_type) match.set_vlan_id(customer_vlan_id) match.set_in_port(in_port=customer_port) flow_entry2.add_match(match) print ("\n") print ("<<< Flow to send:") print flow_entry2.get_payload() time.sleep(rundelay) result = ofswitch.add_modify_flow(flow_entry2) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully added to the Controller") else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.detailed()) delete_flows(ofswitch, table_id, range(first_flow_id, flow_id+1)) exit(0) # --------------------------------------------------- # Third flow entry # --------------------------------------------------- print "\n" print ("<<< Set OpenFlow flow on the Controller") print (" Match: Ethernet Type (%s)\n" " VLAN ID (%s)\n" " Input Port (%s)" % (hex(arp_eth_type), provider_vlan_id, provider_port)) print (" Action: Pop VLAN\n" " Output (Physical Port number %s)" % (customer_port)) time.sleep(rundelay) flow_id += 1 flow_entry3 = FlowEntry() flow_entry3.set_flow_table_id(table_id) fname = "[MLX1-A] Test flow (match:inport=111,arp,vid=100;" + \ "actions:pop-vlan-tag,output=110)" flow_entry3.set_flow_name(flow_name=fname) flow_entry3.set_flow_id(flow_id) flow_entry3.set_flow_hard_timeout(hard_timeout=600) flow_entry3.set_flow_idle_timeout(idle_timeout=300) flow_entry3.set_flow_priority(priority) flow_entry3.set_flow_cookie(cookie) flow_entry3.set_flow_cookie_mask(cookie_mask) instruction = Instruction(instruction_order=0) action_order = 0 action = PopVlanHeaderAction(action_order) instruction.add_apply_action(action) action_order += 1 action = OutputAction(action_order, customer_port) instruction.add_apply_action(action) flow_entry3.add_instruction(instruction) match = Match() match.set_eth_type(arp_eth_type) match.set_vlan_id(provider_vlan_id) match.set_in_port(provider_port) flow_entry3.add_match(match) print ("\n") print ("<<< Flow to send:") print flow_entry3.get_payload() time.sleep(rundelay) result = ofswitch.add_modify_flow(flow_entry3) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully added to the Controller") else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.detailed()) delete_flows(ofswitch, table_id, range(first_flow_id, flow_id+1)) exit(0) # --------------------------------------------------- # Fourth flow entry # --------------------------------------------------- print "\n" print ("<<< Set OpenFlow flow on the Controller") print (" Match: Ethernet Type (%s)\n" " VLAN ID (%s)\n" " Input Port (%s)" % (hex(ip_eth_type), provider_vlan_id, provider_port)) print (" Action: Pop VLAN\n" " Output (Physical Port number %s)" % (customer_port)) time.sleep(rundelay) flow_id += 1 flow_entry4 = FlowEntry() flow_entry4.set_flow_table_id(table_id) flow_entry4.set_flow_id(flow_id) fname = "[MLX1-A] Test flow (match:inport=111,ip,vid=100;" + \ "actions:pop-vlan-tag,output=110)" flow_entry4.set_flow_name(flow_name=fname) flow_entry4.set_flow_hard_timeout(hard_timeout=600) flow_entry4.set_flow_idle_timeout(idle_timeout=300) flow_entry4.set_flow_priority(priority) flow_entry4.set_flow_cookie(cookie) flow_entry4.set_flow_cookie_mask(cookie_mask) instruction = Instruction(instruction_order=0) action_order = 0 action = PopVlanHeaderAction(action_order) instruction.add_apply_action(action) action_order += 1 action = OutputAction(action_order, customer_port) instruction.add_apply_action(action) flow_entry4.add_instruction(instruction) match = Match() match.set_eth_type(ip_eth_type) match.set_vlan_id(provider_vlan_id) match.set_in_port(provider_port) flow_entry4.add_match(match) print ("\n") print ("<<< Flow to send:") print flow_entry4.get_payload() time.sleep(rundelay) result = ofswitch.add_modify_flow(flow_entry4) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully added to the Controller") else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.detailed()) delete_flows(ofswitch, table_id, range(first_flow_id, flow_id+1)) exit(0) print ("\n") print ("<<< Get configured flows from the Controller") time.sleep(rundelay) for i in range(first_flow_id, flow_id+1): result = ofswitch.get_configured_flow(table_id, i) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow '%s' successfully read from the Controller" % i) print ("Flow info:") flow = result.get_data() print json.dumps(flow, indent=4) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.detailed()) delete_flows(ofswitch, table_id, range(first_flow_id, flow_id+1)) exit(0) print ("\n") print ("<<< Delete flows from the Controller's cache " "and from the table '%s' on the '%s' node" % (table_id, nodeName)) time.sleep(rundelay) delete_flows(ofswitch, table_id, range(first_flow_id, flow_id+1)) print ("\n") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print (">>> Demo End") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def of_demo_26(): f = "cfg.yml" d = {} if(load_dict_from_file(f, d) is False): print("Config file '%s' read error: " % f) exit() try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] nodeName = d['nodeName'] rundelay = d['rundelay'] except: print ("Failed to get Controller device attributes") exit(0) print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print ("<<< Demo 26 Start") print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) ofswitch = OFSwitch(ctrl, nodeName) print ("<<< 'Controller': %s, 'OpenFlow' switch: '%s'" % (ctrlIpAddr, nodeName)) flow_table_id = 0 flow_id_base = 12 flow_id = flow_id_base flowEntries = [] # Sample flow entry flow_entry = FlowEntry() flow_entry.set_flow_cookie(6001) flow_entry.set_flow_table_id(flow_table_id) flow_entry.set_flow_id(flow_id) flow_id += 1 flow_entry.set_flow_idle_timeout(12000) flow_entry.set_flow_hard_timeout(12000) flow_entry.set_flow_priority(1000) instruction = Instruction(instruction_order=0) action = DropAction(order=0) instruction.add_apply_action(action) flow_entry.add_instruction(instruction) match = Match() match.set_eth_type(ETH_TYPE_ARP) match.set_eth_src("00:11:22:33:44:55") match.set_eth_dst("aa:bb:cc:dd:ee:ff") flow_entry.add_match(match) flowEntries.append(flow_entry) # Sample flow entry flow_entry = FlowEntry() flow_entry.set_flow_cookie(7001) flow_entry.set_flow_table_id(flow_table_id) flow_entry.set_flow_id(flow_id) flow_id += 1 flow_entry.set_flow_idle_timeout(2400) flow_entry.set_flow_hard_timeout(2400) flow_entry.set_flow_priority(2000) instruction = Instruction(instruction_order=0) action = OutputAction(order=0, port="CONTROLLER", max_len=60) instruction.add_apply_action(action) flow_entry.add_instruction(instruction) match = Match() match.set_eth_type(ETH_TYPE_IPv4) match.set_ipv4_src("1.2.3.4/32") match.set_ipv4_dst("192.168.1.11/32") flow_entry.add_match(match) flowEntries.append(flow_entry) # Sample flow entry flow_entry = FlowEntry() flow_entry.set_flow_cookie(800) flow_entry.set_flow_table_id(flow_table_id) flow_entry.set_flow_id(flow_id) flow_id += 1 flow_entry.set_flow_hard_timeout(1800) flow_entry.set_flow_idle_timeout(1800) flow_entry.set_flow_priority(3000) instruction = Instruction(instruction_order=0) action = OutputAction(order=0, port=5) instruction.add_apply_action(action) action = OutputAction(order=1, port=6) instruction.add_apply_action(action) action = OutputAction(order=2, port=7) instruction.add_apply_action(action) flow_entry.add_instruction(instruction) match = Match() match.set_in_port(1) flow_entry.add_match(match) flowEntries.append(flow_entry) # Sample flow entry flow_entry = FlowEntry() flow_entry.set_flow_cookie(1234) flow_entry.set_flow_table_id(flow_table_id) flow_entry.set_flow_id(flow_id) flow_id += 1 flow_entry.set_flow_hard_timeout(0) flow_entry.set_flow_idle_timeout(0) flow_entry.set_flow_priority(4000) instruction = Instruction(instruction_order=0) action = PushVlanHeaderAction(order=0) action.set_eth_type(ETH_TYPE_QINQ) instruction.add_apply_action(action) action = SetFieldAction(order=1) action.set_vlan_id(100) instruction.add_apply_action(action) action = PushVlanHeaderAction(order=2) action.set_eth_type(ETH_TYPE_DOT1Q) instruction.add_apply_action(action) action = SetFieldAction(order=3) action.set_vlan_id(998) instruction.add_apply_action(action) action = OutputAction(order=4, port=111) instruction.add_apply_action(action) flow_entry.add_instruction(instruction) match = Match() match.set_eth_type(ETH_TYPE_ARP) match.set_vlan_id(998) match.set_in_port(in_port=110) flow_entry.add_match(match) flowEntries.append(flow_entry) # Sample flow entry flow_entry = FlowEntry() flow_entry.set_flow_cookie(1234) flow_entry.set_flow_table_id(flow_table_id) flow_entry.set_flow_id(flow_id) flow_id += 1 flow_entry.set_flow_hard_timeout(0) flow_entry.set_flow_idle_timeout(0) flow_entry.set_flow_priority(4000) instruction = Instruction(instruction_order=0) action = PushVlanHeaderAction(order=0) action.set_eth_type(ETH_TYPE_QINQ) instruction.add_apply_action(action) action = SetFieldAction(order=1) action.set_vlan_id(100) instruction.add_apply_action(action) action = PushVlanHeaderAction(order=2) action.set_eth_type(ETH_TYPE_DOT1Q) instruction.add_apply_action(action) action = SetFieldAction(order=3) action.set_vlan_id(998) instruction.add_apply_action(action) action = OutputAction(order=4, port=111) instruction.add_apply_action(action) flow_entry.add_instruction(instruction) match = Match() match.set_eth_type(ETH_TYPE_IPv4) match.set_vlan_id(998) match.set_in_port(in_port=110) flow_entry.add_match(match) flowEntries.append(flow_entry) # Sample flow entry flow_entry = FlowEntry() flow_entry.set_flow_cookie(1234) flow_entry.set_flow_table_id(flow_table_id) flow_entry.set_flow_id(flow_id) flow_id += 1 flow_entry.set_flow_hard_timeout(0) flow_entry.set_flow_idle_timeout(0) flow_entry.set_flow_priority(4000) instruction = Instruction(instruction_order=0) action = PopVlanHeaderAction(order=0) instruction.add_apply_action(action) action = OutputAction(order=1, port=110) instruction.add_apply_action(action) flow_entry.add_instruction(instruction) match = Match() match.set_eth_type(ETH_TYPE_ARP) match.set_vlan_id(100) match.set_in_port(111) flow_entry.add_match(match) flowEntries.append(flow_entry) # Sample flow entry flow_entry = FlowEntry() flow_entry.set_flow_cookie(1234) flow_entry.set_flow_table_id(flow_table_id) flow_entry.set_flow_id(flow_id) flow_id += 1 flow_entry.set_flow_hard_timeout(0) flow_entry.set_flow_idle_timeout(0) flow_entry.set_flow_priority(4000) instruction = Instruction(instruction_order=0) action = PopVlanHeaderAction(order=0) instruction.add_apply_action(action) action = OutputAction(order=1, port=110) instruction.add_apply_action(action) flow_entry.add_instruction(instruction) match = Match() match.set_eth_type(ETH_TYPE_IPv4) match.set_vlan_id(100) match.set_in_port(111) flow_entry.add_match(match) flowEntries.append(flow_entry) print ("\n") print ("<<< Remove configured flows from the Controller") ofswitch.delete_flows(flow_table_id) print ("\n") print ("<<< Set OpenFlow flows on the Controller") print ("\n") print ("<<< Flows to be configured:") flowEntries = sorted(flowEntries, key=lambda fe: fe.get_flow_priority()) for fe in flowEntries: print (" %s" % fe.to_ofp_oxm_syntax()) time.sleep(rundelay) success = True for fe in flowEntries: result = ofswitch.add_modify_flow(fe) status = result.get_status() if(status.eq(STATUS.OK)): pass else: success = False print ("\n") print ("!!!Demo terminated, failed to add flow:\n '%s'" % fe.to_ofp_oxm_syntax()) print (" Failure reason: %s" % status.detailed()) if success: print "\n" print ("<<< Flows successfully added to the Controller") else: print "\n" print ("<<< Removing all flows from the Controller") ofswitch.delete_flows(flow_table_id) exit(0) print ("\n") print ("<<< Get configured flows from the Controller") time.sleep(rundelay) print ("\n") print ("<<< Configured flows:") result = ofswitch.get_configured_FlowEntries(flow_table_id=0) status = result.get_status() if(status.eq(STATUS.OK)): data = result.get_data() flowEntries = sorted(data, key=lambda fe: fe.get_flow_priority()) for fe in flowEntries: print " %s" % fe.to_ofp_oxm_syntax() else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print ("<<< Get configured flows by IDs from the Controller:") time.sleep(rundelay) for i in range(flow_id_base, flow_id): result = ofswitch.get_configured_FlowEntry(flow_table_id, i) status = result.get_status() if(status.eq(STATUS.OK)): print (" -- Flow id '%s'" % i) fe = result.get_data() print " %s" % fe.to_ofp_oxm_syntax() else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) print ("<<< Removing all flows from the Controller") ofswitch.delete_flows(flow_table_id) exit(0) time.sleep(rundelay) print ("\n") print ("<<< Remove configured flows from the Controller") ofswitch.delete_flows(flow_table_id) time.sleep(rundelay) print ("\n") print ("<<< Get configured flows from the Controller") result = ofswitch.get_configured_FlowEntries(flow_table_id=0) status = result.get_status() if(status.eq(STATUS.DATA_NOT_FOUND)): print ("\n") print "<<< No configured flows" else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.detailed()) exit(0) print ("\n") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print (">>> Demo End") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def of_demo_26(): f = "cfg.yml" d = {} if (load_dict_from_file(f, d) is False): print("Config file '%s' read error: " % f) exit() try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] nodeName = d['nodeName'] rundelay = d['rundelay'] except: print("Failed to get Controller device attributes") exit(0) print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print("<<< Demo 26 Start") print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) ofswitch = OFSwitch(ctrl, nodeName) print("<<< 'Controller': %s, 'OpenFlow' switch: '%s'" % (ctrlIpAddr, nodeName)) flow_table_id = 0 flow_id_base = 12 flow_id = flow_id_base flowEntries = [] # Sample flow entry flow_entry = FlowEntry() flow_entry.set_flow_cookie(6001) flow_entry.set_flow_table_id(flow_table_id) flow_entry.set_flow_id(flow_id) flow_id += 1 flow_entry.set_flow_idle_timeout(12000) flow_entry.set_flow_hard_timeout(12000) flow_entry.set_flow_priority(1000) instruction = Instruction(instruction_order=0) action = DropAction(order=0) instruction.add_apply_action(action) flow_entry.add_instruction(instruction) match = Match() match.set_eth_type(ETH_TYPE_ARP) match.set_eth_src("00:11:22:33:44:55") match.set_eth_dst("aa:bb:cc:dd:ee:ff") flow_entry.add_match(match) flowEntries.append(flow_entry) # Sample flow entry flow_entry = FlowEntry() flow_entry.set_flow_cookie(7001) flow_entry.set_flow_table_id(flow_table_id) flow_entry.set_flow_id(flow_id) flow_id += 1 flow_entry.set_flow_idle_timeout(2400) flow_entry.set_flow_hard_timeout(2400) flow_entry.set_flow_priority(2000) instruction = Instruction(instruction_order=0) action = OutputAction(order=0, port="CONTROLLER", max_len=60) instruction.add_apply_action(action) flow_entry.add_instruction(instruction) match = Match() match.set_eth_type(ETH_TYPE_IPv4) match.set_ipv4_src("1.2.3.4/32") match.set_ipv4_dst("192.168.1.11/32") flow_entry.add_match(match) flowEntries.append(flow_entry) # Sample flow entry flow_entry = FlowEntry() flow_entry.set_flow_cookie(800) flow_entry.set_flow_table_id(flow_table_id) flow_entry.set_flow_id(flow_id) flow_id += 1 flow_entry.set_flow_hard_timeout(1800) flow_entry.set_flow_idle_timeout(1800) flow_entry.set_flow_priority(3000) instruction = Instruction(instruction_order=0) action = OutputAction(order=0, port=5) instruction.add_apply_action(action) action = OutputAction(order=1, port=6) instruction.add_apply_action(action) action = OutputAction(order=2, port=7) instruction.add_apply_action(action) flow_entry.add_instruction(instruction) match = Match() match.set_in_port(1) flow_entry.add_match(match) flowEntries.append(flow_entry) # Sample flow entry flow_entry = FlowEntry() flow_entry.set_flow_cookie(1234) flow_entry.set_flow_table_id(flow_table_id) flow_entry.set_flow_id(flow_id) flow_id += 1 flow_entry.set_flow_hard_timeout(0) flow_entry.set_flow_idle_timeout(0) flow_entry.set_flow_priority(4000) instruction = Instruction(instruction_order=0) action = PushVlanHeaderAction(order=0) action.set_eth_type(ETH_TYPE_QINQ) instruction.add_apply_action(action) action = SetFieldAction(order=1) action.set_vlan_id(100) instruction.add_apply_action(action) action = PushVlanHeaderAction(order=2) action.set_eth_type(ETH_TYPE_DOT1Q) instruction.add_apply_action(action) action = SetFieldAction(order=3) action.set_vlan_id(998) instruction.add_apply_action(action) action = OutputAction(order=4, port=111) instruction.add_apply_action(action) flow_entry.add_instruction(instruction) match = Match() match.set_eth_type(ETH_TYPE_ARP) match.set_vlan_id(998) match.set_in_port(in_port=110) flow_entry.add_match(match) flowEntries.append(flow_entry) # Sample flow entry flow_entry = FlowEntry() flow_entry.set_flow_cookie(1234) flow_entry.set_flow_table_id(flow_table_id) flow_entry.set_flow_id(flow_id) flow_id += 1 flow_entry.set_flow_hard_timeout(0) flow_entry.set_flow_idle_timeout(0) flow_entry.set_flow_priority(4000) instruction = Instruction(instruction_order=0) action = PushVlanHeaderAction(order=0) action.set_eth_type(ETH_TYPE_QINQ) instruction.add_apply_action(action) action = SetFieldAction(order=1) action.set_vlan_id(100) instruction.add_apply_action(action) action = PushVlanHeaderAction(order=2) action.set_eth_type(ETH_TYPE_DOT1Q) instruction.add_apply_action(action) action = SetFieldAction(order=3) action.set_vlan_id(998) instruction.add_apply_action(action) action = OutputAction(order=4, port=111) instruction.add_apply_action(action) flow_entry.add_instruction(instruction) match = Match() match.set_eth_type(ETH_TYPE_IPv4) match.set_vlan_id(998) match.set_in_port(in_port=110) flow_entry.add_match(match) flowEntries.append(flow_entry) # Sample flow entry flow_entry = FlowEntry() flow_entry.set_flow_cookie(1234) flow_entry.set_flow_table_id(flow_table_id) flow_entry.set_flow_id(flow_id) flow_id += 1 flow_entry.set_flow_hard_timeout(0) flow_entry.set_flow_idle_timeout(0) flow_entry.set_flow_priority(4000) instruction = Instruction(instruction_order=0) action = PopVlanHeaderAction(order=0) instruction.add_apply_action(action) action = OutputAction(order=1, port=110) instruction.add_apply_action(action) flow_entry.add_instruction(instruction) match = Match() match.set_eth_type(ETH_TYPE_ARP) match.set_vlan_id(100) match.set_in_port(111) flow_entry.add_match(match) flowEntries.append(flow_entry) # Sample flow entry flow_entry = FlowEntry() flow_entry.set_flow_cookie(1234) flow_entry.set_flow_table_id(flow_table_id) flow_entry.set_flow_id(flow_id) flow_id += 1 flow_entry.set_flow_hard_timeout(0) flow_entry.set_flow_idle_timeout(0) flow_entry.set_flow_priority(4000) instruction = Instruction(instruction_order=0) action = PopVlanHeaderAction(order=0) instruction.add_apply_action(action) action = OutputAction(order=1, port=110) instruction.add_apply_action(action) flow_entry.add_instruction(instruction) match = Match() match.set_eth_type(ETH_TYPE_IPv4) match.set_vlan_id(100) match.set_in_port(111) flow_entry.add_match(match) flowEntries.append(flow_entry) print("\n") print("<<< Remove configured flows from the Controller") ofswitch.delete_flows(flow_table_id) print("\n") print("<<< Set OpenFlow flows on the Controller") print("\n") print("<<< Flows to be configured:") flowEntries = sorted(flowEntries, key=lambda fe: fe.get_flow_priority()) for fe in flowEntries: print(" %s" % fe.to_ofp_oxm_syntax()) time.sleep(rundelay) success = True for fe in flowEntries: result = ofswitch.add_modify_flow(fe) status = result.get_status() if (status.eq(STATUS.OK)): pass else: success = False print("\n") print("!!!Demo terminated, failed to add flow:\n '%s'" % fe.to_ofp_oxm_syntax()) print(" Failure reason: %s" % status.detailed()) if success: print "\n" print("<<< Flows successfully added to the Controller") else: print "\n" print("<<< Removing all flows from the Controller") ofswitch.delete_flows(flow_table_id) exit(0) print("\n") print("<<< Get configured flows from the Controller") time.sleep(rundelay) print("\n") print("<<< Configured flows:") result = ofswitch.get_configured_FlowEntries(flow_table_id=0) status = result.get_status() if (status.eq(STATUS.OK)): data = result.get_data() flowEntries = sorted(data, key=lambda fe: fe.get_flow_priority()) for fe in flowEntries: print " %s" % fe.to_ofp_oxm_syntax() else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print("\n") print("<<< Get configured flows by IDs from the Controller:") time.sleep(rundelay) for i in range(flow_id_base, flow_id): result = ofswitch.get_configured_FlowEntry(flow_table_id, i) status = result.get_status() if (status.eq(STATUS.OK)): print(" -- Flow id '%s'" % i) fe = result.get_data() print " %s" % fe.to_ofp_oxm_syntax() else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) print("<<< Removing all flows from the Controller") ofswitch.delete_flows(flow_table_id) exit(0) time.sleep(rundelay) print("\n") print("<<< Remove configured flows from the Controller") ofswitch.delete_flows(flow_table_id) time.sleep(rundelay) print("\n") print("<<< Get configured flows from the Controller") result = ofswitch.get_configured_FlowEntries(flow_table_id=0) status = result.get_status() if (status.eq(STATUS.DATA_NOT_FOUND)): print("\n") print "<<< No configured flows" else: print("\n") print("!!!Demo terminated, reason: %s" % status.detailed()) exit(0) print("\n") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print(">>> Demo End") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def of_demo_5(): f = "cfg.yml" d = {} if(load_dict_from_file(f, d) is False): print("Config file '%s' read error: " % f) exit() try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] nodeName = d['nodeName'] rundelay = d['rundelay'] except: print ("Failed to get Controller device attributes") exit(0) print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print ("<<< Demo 5 Start") print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) ofswitch = OFSwitch(ctrl, nodeName) # --- Flow Match: IPv4 Source Address # NOTE: Ethernet type MUST be 2048 (0x800) -> IPv4 protocol eth_type = ETH_TYPE_IPv4 ipv4_src = "10.11.12.13/24" print ("<<< 'Controller': %s, 'OpenFlow' switch: %s" % (ctrlIpAddr, nodeName)) print "\n" print ("<<< Set OpenFlow flow on the Controller") print (" Match: Ethernet Type (%s)\n" " IPv4 Source Address (%s)" % (hex(eth_type), ipv4_src)) print (" Action: Drop") time.sleep(rundelay) flow_entry = FlowEntry() table_id = 0 flow_entry.set_flow_table_id(table_id) flow_id = 12 flow_entry.set_flow_id(flow_id) flow_entry.set_flow_priority(flow_priority=1000) # --- Instruction: 'Apply-actions' # Action: 'Drop' instruction = Instruction(instruction_order=0) action = DropAction(order=0) instruction.add_apply_action(action) flow_entry.add_instruction(instruction) # --- Match Fields: Ethernet Type # IPv4 Source Address match = Match() match.set_eth_type(eth_type) match.set_ipv4_src(ipv4_src) flow_entry.add_match(match) print ("\n") print ("<<< Flow to send:") print flow_entry.get_payload() time.sleep(rundelay) result = ofswitch.add_modify_flow(flow_entry) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully added to the Controller") else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print ("<<< Get configured flow from the Controller") time.sleep(rundelay) result = ofswitch.get_configured_flow(table_id, flow_id) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully read from the Controller") print ("Flow info:") flow = result.get_data() print json.dumps(flow, indent=4) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print ("<<< Delete flow with id of '%s' from the Controller's cache " "and from the table '%s' on the '%s' node" % (flow_id, table_id, nodeName)) time.sleep(rundelay) result = ofswitch.delete_flow(flow_entry.get_flow_table_id(), flow_entry.get_flow_id()) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully removed from the Controller") else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print (">>> Demo End") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def vr_demo_13(): f = "cfg4.yml" d = {} if (load_dict_from_file(f, d) is False): print("Config file '%s' read error: " % f) exit() try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] nodeName = d['nodeName'] nodeIpAddr = d['nodeIpAddr'] nodePortNum = d['nodePortNum'] nodeUname = d['nodeUname'] nodePswd = d['nodePswd'] rundelay = d['rundelay'] except: print("Failed to get Controller device attributes") exit(0) print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print("<<< Demo Start") print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print("\n") print( "<<< OpenVPN configuration example: " "Site-to-Site Mode with Preshared Secret") print("\n") ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) vrouter = VRouter5600(ctrl, nodeName, nodeIpAddr, nodePortNum, nodeUname, nodePswd) print("<<< 'Controller': %s, '%s': %s" % (ctrlIpAddr, nodeName, nodeIpAddr)) print("\n") time.sleep(rundelay) node_configured = False result = ctrl.check_node_config_status(nodeName) status = result.get_status() if (status.eq(STATUS.NODE_CONFIGURED)): node_configured = True print("<<< '%s' is configured on the Controller" % nodeName) elif (status.eq(STATUS.DATA_NOT_FOUND)): node_configured = False else: print("\n") print "Failed to get configuration status for the '%s'" % nodeName print("!!!Demo terminated, reason: %s" % status.detailed()) exit(0) if node_configured is False: result = ctrl.add_netconf_node(vrouter) status = result.get_status() if (status.eq(STATUS.OK)): print("<<< '%s' added to the Controller" % nodeName) else: print("\n") print("!!!Demo terminated, reason: %s" % status.detailed()) exit(0) print("\n") time.sleep(rundelay) result = ctrl.check_node_conn_status(nodeName) status = result.get_status() if (status.eq(STATUS.NODE_CONNECTED)): print("<<< '%s' is connected to the Controller" % nodeName) else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print("\n") print("<<< Show OpenVPN interfaces configuration on the '%s'" % nodeName) result = vrouter.get_openvpn_interfaces_cfg() time.sleep(rundelay) status = result.get_status() if (status.eq(STATUS.OK)): print("'%s' OpenVPN interfaces configuration:" % nodeName) iflist = result.get_data() assert (isinstance(iflist, list)) for item in iflist: print json.dumps(item, indent=4, sort_keys=True) elif (status.eq(STATUS.DATA_NOT_FOUND)): print("No OpenVPN interfaces configuration found") else: print("\n") print("!!!Demo terminated, reason: %s" % status.detailed()) ctrl.delete_netconf_node(vrouter) exit(0) print "\n" ifname = 'vtun0' print(">>> Configure new '%s' OpenVPN tunnel interface on the '%s'" % (ifname, nodeName)) time.sleep(rundelay) # Create OpenVPN interface vpnif = OpenVpnInterface(ifname) # Set the OpenVPN mode to 'site-to-site' mode = 'site-to-site' vpnif.set_mode(mode) # Specify the location of the file containing the preshared secret secret_file = '/config/auth/secret' vpnif.set_shared_secret_key_file(secret_file) # Set the tunnel IP address for the local endpoint local_address = '192.168.200.1' vpnif.set_local_address(local_address) # Set the tunnel IP address of the remote endpoint remote_address = '192.168.200.2' vpnif.set_remote_address(remote_address) # Specify the physical IP address of the remote host remote_host = '87.65.43.21' vpnif.set_remote_host(remote_host) result = vrouter.set_openvpn_interface_cfg(vpnif) status = result.get_status() if (status.eq(STATUS.OK)): print("<<< '%s' interface configuration was successfully created" % ifname) else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) print status.detailed() ctrl.delete_netconf_node(vrouter) exit(0) print "\n" print("<<< Show '%s' interface configuration on the '%s'" % (ifname, nodeName)) time.sleep(rundelay) result = vrouter.get_openvpn_interface_cfg(ifname) status = result.get_status() if (status.eq(STATUS.OK)): print("'%s' interface configuration:" % ifname) cfg = result.get_data() data = json.loads(cfg) print json.dumps(data, indent=4, sort_keys=True) print("<<< '%s' interface configuration was successfully read" % ifname) else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) print status.detailed() ctrl.delete_netconf_node(vrouter) exit(0) print "\n" ip_prefix = '192.168.101.0/24' print( "<<< Create static route to access the remote subnet '%s' " "through the '%s' interface " % (ip_prefix, ifname)) time.sleep(rundelay) static_route = StaticRoute() static_route.set_interface_route(ip_prefix) static_route.set_interface_route_next_hop_interface(ip_prefix, ifname) result = vrouter.set_protocols_static_route_cfg(static_route) status = result.get_status() if (status.eq(STATUS.OK)): print("<<< Static route was successfully created") else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) print status.detailed() ctrl.delete_netconf_node(vrouter) exit(0) print "\n" print("<<< Show subnet '%s' static route configuration on the '%s'" % (ip_prefix, nodeName)) time.sleep(rundelay) result = vrouter.get_protocols_static_interface_route_cfg(ip_prefix) status = result.get_status() if (status.eq(STATUS.OK)): print("Static route configuration:") cfg = result.get_data() data = json.loads(cfg) print json.dumps(data, indent=4, sort_keys=True) print("<<< Static route configuration was successfully read") else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) print status.detailed() ctrl.delete_netconf_node(vrouter) exit(0) print "\n" print("<<< Delete '%s' interface configuration from the '%s'" % (ifname, nodeName)) time.sleep(rundelay) result = vrouter.delete_openvpn_interface_cfg(ifname) status = result.get_status() if (status.eq(STATUS.OK)): print( "<<< '%s' interface configuration successfully " "removed from the '%s'" % (ifname, nodeName)) else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) print status.detailed() ctrl.delete_netconf_node(vrouter) exit(0) print "\n" print("<<< Show '%s' interface configuration on the '%s'" % (ifname, nodeName)) time.sleep(rundelay) result = vrouter.get_openvpn_interface_cfg(ifname) status = result.get_status() if (status.eq(STATUS.OK)): print("\n") print("!!!Demo terminated, reason: %s" % "Interface configuration still exists") elif (status.eq(STATUS.DATA_NOT_FOUND)): print("No '%s' interface configuration found" % (ifname)) else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) print status.detailed() ctrl.delete_netconf_node(vrouter) exit(0) print "\n" print("<<< Delete '%s' subnet static route configuration from the '%s'" % (ip_prefix, nodeName)) time.sleep(rundelay) result = vrouter.delete_protocols_static_interface_route_cfg(ip_prefix) status = result.get_status() if (status.eq(STATUS.OK)): print( "<<< Static route configuration successfully removed " "from the '%s'" % (nodeName)) else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) print status.detailed() ctrl.delete_netconf_node(vrouter) exit(0) print "\n" print("<<< Show '%s' subnet static route configuration on the '%s'" % (ip_prefix, nodeName)) time.sleep(rundelay) result = vrouter.get_protocols_static_interface_route_cfg(ip_prefix) status = result.get_status() if (status.eq(STATUS.OK)): print("\n") print("!!!Demo terminated, reason: %s" % "Static route configuration still found") elif (status.eq(STATUS.DATA_NOT_FOUND)): print("No static route configuration found") else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) print status.detailed() ctrl.delete_netconf_node(vrouter) exit(0) print "\n" print(">>> Remove '%s' NETCONF node from the Controller" % nodeName) time.sleep(rundelay) result = ctrl.delete_netconf_node(vrouter) status = result.get_status() if (status.eq(STATUS.OK)): print( "'%s' NETCONF node was successfully removed " "from the Controller" % nodeName) else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief()) exit(0) print("\n") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print(">>> Demo End") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def vr_demo_2(): f = "cfg4.yml" d = {} if(load_dict_from_file(f, d) is False): print("Config file '%s' read error: " % f) exit() try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] nodeName = d['nodeName'] nodeIpAddr = d['nodeIpAddr'] nodePortNum = d['nodePortNum'] nodeUname = d['nodeUname'] nodePswd = d['nodePswd'] rundelay = d['rundelay'] except: print ("Failed to get Controller device attributes") exit(0) print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print ("<<< Demo Start") print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print ("\n") ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) vrouter = VRouter5600(ctrl, nodeName, nodeIpAddr, nodePortNum, nodeUname, nodePswd) print ("<<< 'Controller': %s, '%s': %s" % (ctrlIpAddr, nodeName, nodeIpAddr)) print ("\n") time.sleep(rundelay) node_configured = False result = ctrl.check_node_config_status(nodeName) status = result.get_status() if(status.eq(STATUS.NODE_CONFIGURED)): node_configured = True print ("<<< '%s' is configured on the Controller" % nodeName) elif(status.eq(STATUS.DATA_NOT_FOUND)): node_configured = False else: print ("\n") print "Failed to get configuration status for the '%s'" % nodeName print ("!!!Demo terminated, reason: %s" % status.detailed()) exit(0) if node_configured is False: result = ctrl.add_netconf_node(vrouter) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< '%s' added to the Controller" % nodeName) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.detailed()) exit(0) print ("\n") time.sleep(rundelay) result = ctrl.check_node_conn_status(nodeName) status = result.get_status() if(status.eq(STATUS.NODE_CONNECTED)): print ("<<< '%s' is connected to the Controller" % nodeName) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print "\n" yangModelName = "vyatta-security-firewall" yangModelVerson = "2014-11-07" print ("<<< Retrieve '%s' YANG model definition from the '%s'" % (yangModelName, nodeName)) time.sleep(rundelay) result = vrouter.get_schema(yangModelName, yangModelVerson) status = result.get_status() if(status.eq(STATUS.OK)): print "YANG model definition:" schema = result.get_data() print schema else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print "\n" print (">>> Remove '%s' NETCONF node from the Controller" % nodeName) time.sleep(rundelay) result = ctrl.delete_netconf_node(vrouter) status = result.get_status() if(status.eq(STATUS.OK)): print ("'%s' NETCONF node was successfully removed " "from the Controller" % nodeName) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief()) exit(0) print "\n" print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print (">>> Demo End") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def of_demo_16(): f = "cfg.yml" d = {} if(load_dict_from_file(f, d) is False): print("Config file '%s' read error: " % f) exit() try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] nodeName = d['nodeName'] rundelay = d['rundelay'] except: print ("Failed to get Controller device attributes") exit(0) print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print ("<<< Demo 16 Start") print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) ofswitch = OFSwitch(ctrl, nodeName) # --- Flow Match: Ethernet Type # IPv6 Source Address # IPv6 Destination Address eth_type = ETH_TYPE_IPv6 ipv6_src = "fe80::2acf:e9ff:fe21:6431/128" ipv6_dst = "aabb:1234:2acf:e9ff::fe21:6431/64" # --- Flow Actions: Output (CONTROLLER) output_port = "CONTROLLER" print ("<<< 'Controller': %s, 'OpenFlow' switch: '%s'" % (ctrlIpAddr, nodeName)) print "\n" print ("<<< Set OpenFlow flow on the Controller") print (" Match: Ethernet Type (%s)\n" " IPv6 Source Address (%s)\n" " IPv6 Destination Address (%s)" % (hex(eth_type), ipv6_src, ipv6_dst)) print (" Action: Output (to %s)" % (output_port)) time.sleep(rundelay) flow_entry = FlowEntry() fname = "match=ipv6_src,ipv6_dst;actions=output:Controller" flow_entry.set_flow_name(flow_name=fname) table_id = 0 flow_id = 23 flow_entry.set_flow_table_id(table_id) flow_entry.set_flow_id(flow_id) flow_entry.set_flow_priority(flow_priority=1014) flow_entry.set_flow_cookie(cookie=408) flow_entry.set_flow_cookie_mask(cookie_mask=255) flow_entry.set_flow_hard_timeout(hard_timeout=3400) flow_entry.set_flow_idle_timeout(idle_timeout=3400) # --- Instruction: 'Apply-actions' # Actions: 'Output' instruction = Instruction(instruction_order=0) action = OutputAction(order=0, port=output_port) instruction.add_apply_action(action) flow_entry.add_instruction(instruction) # --- Match Fields: Ethernet Type # IPv6 Source Address # IPv6 Destination Address match = Match() match.set_eth_type(eth_type) match.set_ipv6_src(ipv6_src) match.set_ipv6_dst(ipv6_dst) flow_entry.add_match(match) print ("\n") print ("<<< Flow to send:") print flow_entry.get_payload() time.sleep(rundelay) result = ofswitch.add_modify_flow(flow_entry) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully added to the Controller") else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print ("<<< Get configured flow from the Controller") time.sleep(rundelay) result = ofswitch.get_configured_flow(table_id, flow_id) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully read from the Controller") print ("Flow info:") flow = result.get_data() print json.dumps(flow, indent=4) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print ("<<< Delete flow with id of '%s' from the Controller's cache " "and from the table '%s' on the '%s' node" % (flow_id, table_id, nodeName)) time.sleep(rundelay) result = ofswitch.delete_flow(flow_entry.get_flow_table_id(), flow_entry.get_flow_id()) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully removed from the Controller") else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print (">>> Demo End") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def of_demo_29(): f = "cfg.yml" d = {} if(load_dict_from_file(f, d) is False): print("Config file '%s' read error: " % f) exit() try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] rundelay = d['rundelay'] except: print ("Failed to get Controller device attributes") exit(0) description = ( "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n" " This demo illustrates how to use Controller's notification \n" " subscription service for tracing dynamic changes in the\n" " network topology data tree maintained by the Controller.\n" "\n" " It is implied that core network services (Forwarding Rules\n" " Manager, Topology Manager, Switch Manager, Host Tracker)\n" " are functioning on the Controller\n" "\n" " This script creates an event listener on the Controller and\n" " establishes permanent connection to the events notification\n" " stream. Once a data change event in the topology tree (such\n" " as add/remove switch, host or link) is detected it will be\n" " reported to the screen.\n" "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n" ) print "\n".strip() print description print "\n".strip() time.sleep(rundelay) print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print ("<<< Demo 29 Start") print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) # Identifier of the network topology to be traced # (name used by Controller for default topology instance) topo_id = 'flow:1' print "\n".strip() print ("<<< 'Controller': %s, Topology Identifier: '%s'" % (ctrlIpAddr, topo_id)) time.sleep(rundelay) # Data store for the changes # Can be one of: # - CONFIGURATION: Logical data store representing configuration # state of the system and it's components. # - OPERATIONAL: Logical data store representing operational # state of the system and it's components datastore = "OPERATIONAL" # Scope of the data changes # Can be one of: # - BASE: Represents only a direct change of the node, such as # replacement, addition or deletion of the node. # - ONE: Represent a change (addition, replacement, deletion) # of the node or one of its direct children. # This scope is a superset of BASE. # - SUBTREE: Represents a change of the node or any of its child # nodes, direct and nested. # This scope is superset of ONE and BASE. scope = "SUBTREE" # Path to the network topology node in the YANG data tree path = ctrl.get_network_topology_yang_schema_path(topo_id) # Create listener on the Controller (if it does already exist Controller # just returns the stream name to subscribe to) print path result = ctrl.create_data_change_event_subscription(datastore, scope, path) status = result.get_status() if not status.eq(STATUS.OK): print ("\n") print ("!!!Demo terminated, reason: %s" % status.detailed()) exit(1) print "Here1" stream_name = result.get_data() print "here2" # Subscribe to the stream result = ctrl.subscribe_to_stream(stream_name) print "here 3" status = result.get_status() if not status.eq(STATUS.OK): print ("\n") print ("!!!Demo terminated, reason: %s" % status.detailed()) exit(1) print "\n".strip() print " Successfully subscribed for data change notifications" print " Stream location:" stream_location = result.get_data() print " %s" % stream_location print "\n".strip() print " Listening ... (CTRL-C to exit)" print "\n".strip() # Connect to the notification stream on the Controller # and start listening for the data change notifications # (report only events that we are really interested in) websock = create_connection(stream_location) try: while True: event = websock.recv() tcn = NetworkTopologyChangeNotification(event) timestamp = tcn.get_time() l = tcn.switches_added() if l and len(l): for i in l: print " [%s] added switch: %s" % (timestamp, i) l = tcn.switches_removed() if l and len(l): for i in l: print " [%s] removed switch: %s" % (timestamp, i) l = tcn.hosts_added() if l and len(l): for i in l: print " [%s] added host: %s" % (timestamp, i) l = tcn.hosts_removed() if l and len(l): for i in l: print " [%s] removed host: %s" % (timestamp, i) l = tcn.links_added() if l and len(l): for i in l: print " [%s] added link: %s" % (timestamp, i) l = tcn.links_removed() if l and len(l): for i in l: print " [%s] removed link: %s" % (timestamp, i) except(KeyboardInterrupt) as e: print "Interrupted from keyboard, exit\n" websock.close() print ("\n") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print (">>> Demo End") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
#!/usr/bin/python import sys import pybvc from pybvc.controller.netconfnode import NetconfNode from pybvc.common.status import STATUS from pybvc.controller.controller import Controller from pybvc.common.utils import load_dict_from_file if __name__ == "__main__": f = "cfg.yml" d = {} if (load_dict_from_file(f, d) == False): print("Config file '%s' read error: " % f) exit() try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] nodeName = d['nodeName'] nodeIpAddr = d['nodeIpAddr'] nodePortNum = d['nodePortNum'] nodeUname = d['nodeUname'] nodePswd = d['nodePswd'] except: print("Failed to get Controller device attributes")
def vr_demo_12(): f = "cfg4.yml" d = {} if (load_dict_from_file(f, d) is False): print("Config file '%s' read error: " % f) exit() try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] nodeName = d['nodeName'] nodeIpAddr = d['nodeIpAddr'] nodePortNum = d['nodePortNum'] nodeUname = d['nodeUname'] nodePswd = d['nodePswd'] rundelay = d['rundelay'] except: print("Failed to get Controller device attributes") exit(0) print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print("<<< Demo Start") print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) vrouter = VRouter5600(ctrl, nodeName, nodeIpAddr, nodePortNum, nodeUname, nodePswd) print("<<< 'Controller': %s, '%s': %s" % (ctrlIpAddr, nodeName, nodeIpAddr)) print("\n") time.sleep(rundelay) node_configured = False result = ctrl.check_node_config_status(nodeName) status = result.get_status() if (status.eq(STATUS.NODE_CONFIGURED)): node_configured = True print("<<< '%s' is configured on the Controller" % nodeName) elif (status.eq(STATUS.DATA_NOT_FOUND)): node_configured = False else: print("\n") print "Failed to get configuration status for the '%s'" % nodeName print("!!!Demo terminated, reason: %s" % status.detailed()) exit(0) if node_configured is False: result = ctrl.add_netconf_node(vrouter) status = result.get_status() if (status.eq(STATUS.OK)): print("<<< '%s' added to the Controller" % nodeName) else: print("\n") print("!!!Demo terminated, reason: %s" % status.detailed()) exit(0) print("\n") time.sleep(rundelay) result = ctrl.check_node_conn_status(nodeName) status = result.get_status() if (status.eq(STATUS.NODE_CONNECTED)): print("<<< '%s' is connected to the Controller" % nodeName) else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print("\n") print("<<< Show VPN configuration on the '%s'" % nodeName) result = vrouter.get_vpn_cfg() time.sleep(rundelay) status = result.get_status() if (status.eq(STATUS.OK)): print("'%s' VPN configuration:" % nodeName) cfg = result.get_data() data = json.loads(cfg) print json.dumps(data, indent=4, sort_keys=True) elif (status.eq(STATUS.DATA_NOT_FOUND)): print("No VPN configuration found") else: print("\n") print("!!!Demo terminated, reason: %s" % status.detailed()) ctrl.delete_netconf_node(vrouter) exit(0) print "\n" print(">>> Create new VPN configuration on the '%s'" % (nodeName)) ca_cert_file = '/config/auth/ca.crt' srv_cert_file = '/config/auth/r1.crt' srv_key_file = '/config/auth/r1.key' crl_file = '/config/auth/r1.crl' print( " NOTE: For this demo to succeed the following files " "must exist on the '%s'\n" " (empty files can be created for the sake of the demo):\n" " %s\n" " %s\n" " %s\n" " %s" % (nodeName, ca_cert_file, srv_cert_file, crl_file, srv_key_file)) time.sleep(rundelay) # ------------------------------------------------------------------------- # Encode VPN configuration options by using 'Vpn' object # ------------------------------------------------------------------------- vpn = Vpn() # ------------------------------------------------------------------------- # Create and configure Internet Key Exchange (IKE) group # ------------------------------------------------------------------------- ike_grp_name = "IKE-1W" proposal_num = 1 # Set the encryption cipher for proposal 1 # (enumeration: 'aes128', 'aes256', '3des') encryption_cipher = 'aes256' vpn.set_ipsec_ike_group_proposal_encryption(ike_grp_name, proposal_num, encryption_cipher) # Set the hash algorithm for proposal 1 # (enumeration: 'md5', 'sha1') hash_algorithm = 'sha1' vpn.set_ipsec_ike_group_proposal_hash(ike_grp_name, proposal_num, hash_algorithm) # Set the encryption cipher for proposal 2 # (enumeration: 'aes128', 'aes256', '3des') proposal_num = 2 encryption_cipher = 'aes128' vpn.set_ipsec_ike_group_proposal_encryption(ike_grp_name, proposal_num, encryption_cipher) # Set the hash algorithm for proposal 2 # (enumeration: 'md5', 'sha1') hash_algorithm = 'sha1' vpn.set_ipsec_ike_group_proposal_hash(ike_grp_name, proposal_num, hash_algorithm) # Set the lifetime for the whole IKE group lifetime = 3600 vpn.set_ipsec_ike_group_lifetime(ike_grp_name, lifetime) # ------------------------------------------------------------------------- # Create and configure Encapsulating Security Payload (ESP) group # ------------------------------------------------------------------------- esp_grp_name = "ESP-1W" # Set the encryption cipher for proposal 1 # (enumeration: 'aes128', 'aes256', '3des') proposal_num = 1 encryption_cipher = 'aes256' vpn.set_ipsec_esp_group_proposal_encryption(esp_grp_name, proposal_num, encryption_cipher) # Set the hash algorithm for proposal 1 # (enumeration: 'md5', 'sha1') hash_algorithm = 'sha1' vpn.set_ipsec_esp_group_proposal_hash(esp_grp_name, proposal_num, hash_algorithm) # Set the encryption cipher for proposal 2 # (enumeration: 'aes128', 'aes256', '3des') proposal_num = 2 encryption_cipher = '3des' vpn.set_ipsec_esp_group_proposal_encryption(esp_grp_name, proposal_num, encryption_cipher) # Set the hash algorithm for proposal 2 # (enumeration: 'md5', 'sha1') hash_algorithm = 'md5' vpn.set_ipsec_esp_group_proposal_hash(esp_grp_name, proposal_num, hash_algorithm) # Set the lifetime for the whole ESP group lifetime = 1800 vpn.set_ipsec_esp_group_lifetime(esp_grp_name, lifetime) # ------------------------------------------------------------------------- # Configure connection to a remote peer # ------------------------------------------------------------------------- peer_node = "192.0.2.33" description = ("Site-to-Site VPN Configuration Example - " "X.509 Certificate Authentication") vpn.set_ipsec_site_to_site_peer_description(peer_node, description) # Set authentication mode to 'x509' auth_mode = 'x509' vpn.set_ipsec_site_to_site_peer_auth_mode(peer_node, auth_mode) # Specify the 'distinguished name' of the certificate for the peer remote_id = "C=US, ST=CA, O=ABC Company, CN=east, [email protected]" vpn.set_ipsec_site_to_site_peer_auth_remote_id(peer_node, remote_id) # Specify the location of the CA certificate on the vRouter vpn.set_ipsec_site_to_site_peer_auth_ca_cert_file(peer_node, ca_cert_file) # Specify the location of the server certificate on the vRouter vpn.set_ipsec_site_to_site_peer_auth_srv_cert_file(peer_node, srv_cert_file) # Specify the location of the server key file on the vRouter vpn.set_ipsec_site_to_site_peer_auth_srv_key_file(peer_node, srv_key_file) # Specify the password for the server key file srv_key_pswd = 'testpassword' vpn.set_ipsec_site_to_site_peer_auth_srv_key_pswd(peer_node, srv_key_pswd) # Specify the default ESP group for all tunnels esp_group_name = 'ESP-1W' vpn.set_ipsec_site_to_site_peer_default_esp_group(peer_node, esp_group_name) # Specify the IKE group ike_group_name = 'IKE-1W' vpn.set_ipsec_site_to_site_peer_ike_group(peer_node, ike_group_name) # Identify the IP address on the vRouter to be used for this connection local_address = '192.0.2.1' vpn.set_ipsec_site_to_site_peer_local_address(peer_node, local_address) # Create a tunnel configuration and provide local and remote subnets # for this tunnel tunnel = 1 local_prefix = '192.168.40.0/24' remote_prefix = '192.168.60.0/24' vpn.set_ipsec_site_to_site_peer_tunnel_local_prefix( peer_node, tunnel, local_prefix) vpn.set_ipsec_site_to_site_peer_tunnel_remote_prefix( peer_node, tunnel, remote_prefix) print "\n" print(">>> VPN configuration to be applied to the '%s'" % (nodeName)) print vpn.get_payload() time.sleep(rundelay) result = vrouter.set_vpn_cfg(vpn) status = result.get_status() if (status.eq(STATUS.OK)): print("<<< VPN configuration was successfully created") else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) print status.detailed() ctrl.delete_netconf_node(vrouter) exit(0) print "\n" print("<<< Show VPN configuration on the '%s'" % (nodeName)) time.sleep(rundelay) result = vrouter.get_vpn_cfg() status = result.get_status() if (status.eq(STATUS.OK)): print("'%s' VPN configuration:" % nodeName) cfg = result.get_data() data = json.loads(cfg) print json.dumps(data, indent=4, sort_keys=True) print("<<< VPN configuration was successfully read") else: print("\n") print("!!!Demo terminated, reason: %s" % status.detailed()) ctrl.delete_netconf_node(vrouter) exit(0) time.sleep(rundelay) print "\n" print("<<< Delete VPN configuration on the '%s'" % (nodeName)) time.sleep(rundelay) result = vrouter.delete_vpn_cfg() status = result.get_status() if (status.eq(STATUS.OK)): print("VPN configuration successfully removed from '%s'" % (nodeName)) else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) print status.detailed() ctrl.delete_netconf_node(vrouter) exit(0) print "\n" print("<<< Show VPN configuration on the '%s'" % (nodeName)) time.sleep(rundelay) result = vrouter.get_vpn_cfg() status = result.get_status() if (status.eq(STATUS.OK)): print("'%s' VPN configuration:" % nodeName) cfg = result.get_data() data = json.loads(cfg) print json.dumps(data, indent=4, sort_keys=True) elif (status.eq(STATUS.DATA_NOT_FOUND)): print("No VPN configuration found") else: print("\n") print("!!!Demo terminated, reason: %s" % status.detailed()) ctrl.delete_netconf_node(vrouter) exit(0) print "\n" print(">>> Remove '%s' NETCONF node from the Controller" % nodeName) time.sleep(rundelay) result = ctrl.delete_netconf_node(vrouter) status = result.get_status() if (status.eq(STATUS.OK)): print( "'%s' NETCONF node was successfully removed " "from the Controller" % nodeName) else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief()) exit(0) print("\n") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print(">>> Demo End") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def of_demo_36(): f = "cfg.yml" d = {} if (load_dict_from_file(f, d) is False): print("Config file '%s' read error: " % f) exit() try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] nodeName = d['nodeName'] rundelay = d['rundelay'] except: print("Failed to get Controller device attributes") exit(0) print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print("<<< Demo 36 Start") print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) ofswitch = OFSwitch(ctrl, nodeName) print "\n".strip() print("<<< 'Controller': %s, 'OpenFlow' switch: '%s'" % (ctrlIpAddr, nodeName)) grp_ids_cfg = [] grp_ids_oper = [] print "\n".strip() print("<<< Get OpenFlow Groups Information") time.sleep(rundelay) result = ofswitch.get_configured_group_ids() status = result.get_status() if (status.eq(STATUS.OK)): grp_ids_cfg = result.get_data() elif (status.eq(STATUS.DATA_NOT_FOUND)): grp_ids_cfg = [] else: print("\n") print("!!!Demo terminated, reason: %s" % status.detailed()) exit(0) result = ofswitch.get_operational_group_ids() status = result.get_status() if (status.eq(STATUS.OK)): grp_ids_oper = result.get_data() elif (status.eq(STATUS.DATA_NOT_FOUND)): grp_ids_oper = [] else: print("\n") print("!!!Demo terminated, reason: %s" % status.detailed()) exit(0) # Show current state of the Group Table in the Controller's # configuration and operational data stores print_groups(grp_ids_cfg, grp_ids_oper) # Create new group group_id = 15 group_type = OFPGT_FF group_name = "Example of 'link fast failover' group" watch_port1 = 110 watch_port2 = 111 watch_port3 = 112 out_port1 = 110 out_port2 = 111 out_port3 = 112 print "\n".strip() print("<<< Create Group") print "\n".strip() print( " Group Type : %s\n" " Group ID : %s\n" " Group Name : \"%s\"" % (group_type.strip('group-').upper(), group_id, group_name)) print(" Buckets :") print(" [0] watch-port: %s" % watch_port1) print(" actions: Output (%s)" % out_port1) print(" [1] watch-port: %s" % watch_port2) print(" actions: Output (%s)" % out_port2) print(" [2] watch-port: %s" % watch_port3) print(" actions: Output (%s)" % out_port3) time.sleep(rundelay) # Allocate a placeholder for the group entry group_entry = GroupEntry(group_id, group_type) group_entry.set_group_name(group_name) # Fill in group entry with action buckets # --------- bucket_id = 0 bucket1 = GroupBucket(bucket_id) bucket1.set_watch_port(watch_port1) action = OutputAction(order=0, port=out_port1) bucket1.add_action(action) group_entry.add_bucket(bucket1) # --------- bucket_id += 1 bucket2 = GroupBucket(bucket_id) bucket2.set_watch_port(watch_port2) action = OutputAction(order=0, port=out_port2) bucket2.add_action(action) group_entry.add_bucket(bucket2) # --------- bucket_id += 1 bucket3 = GroupBucket(bucket_id) bucket3.set_watch_port(watch_port3) action = OutputAction(order=0, port=out_port3) bucket3.add_action(action) group_entry.add_bucket(bucket3) # Request Controller to create the group print "\n".strip() print("<<< Group to create:") print group_entry.get_payload() time.sleep(rundelay) result = ofswitch.add_modify_group(group_entry) status = result.get_status() if (status.eq(STATUS.OK)): print("<<< Group successfully added") grp_ids_oper = result.get_data() else: print("\n").strip() print("!!!Demo terminated, reason: %s" % status.detailed()) exit(0) print("\n").strip() print("<<< Get group '%s' configuration status") % group_id time.sleep(rundelay) result = ofswitch.get_configured_group(group_id) status = result.get_status() if (status.eq(STATUS.OK)): print("Group configuration info:") group = result.get_data() print json.dumps(group, indent=4) else: print("\n").strip() print("!!!Demo terminated, reason: %s" % status.detailed()) exit(0) print("\n").strip() print("<<< Get group '%s' operational status") % group_id time.sleep(rundelay) result = ofswitch.get_group_description(group_id) status = result.get_status() if (status.eq(STATUS.OK)): print("Group operational info:") group = result.get_data() print json.dumps(group, indent=4) else: print("\n").strip() print("!!!Error, reason: %s" % status.detailed()) print("\n").strip() print("<<< Get group '%s' statistics information") % group_id time.sleep(rundelay) result = ofswitch.get_group_statistics(group_id) status = result.get_status() if (status.eq(STATUS.OK)): print("Group statistics info:") group = result.get_data() print json.dumps(group, indent=4) else: print("\n").strip() print("!!!Error, reason: %s" % status.detailed()) print("\n").strip() print("<<< Get OpenFlow Groups Information") time.sleep(rundelay) result = ofswitch.get_configured_group_ids() status = result.get_status() if (status.eq(STATUS.OK)): grp_ids_cfg = result.get_data() elif (status.eq(STATUS.DATA_NOT_FOUND)): grp_ids_cfg = [] else: print("\n").strip() print("!!!Error, reason: %s" % status.detailed()) result = ofswitch.get_operational_group_ids() status = result.get_status() if (status.eq(STATUS.OK)): grp_ids_oper = result.get_data() elif (status.eq(STATUS.DATA_NOT_FOUND)): grp_ids_oper = [] else: print("\n").strip() print("!!!Error, reason: %s" % status.detailed()) # Show current state of the Group Table in the Controller's # configuration and operational data stores print_groups(grp_ids_cfg, grp_ids_oper) first_flow_id = 110 # --------------------------------------------------- # First flow entry # --------------------------------------------------- table_id = 0 flow_id = first_flow_id flow_name = "Group action example" priority = 1000 cookie = 1400 match_in_port = 109 match_eth_type = ETH_TYPE_IPv4 print "\n".strip() print("<<< Set OpenFlow flow on the Controller") print( " Match: Input Port (%s)\n" " Ethernet Type (%s)" % (match_in_port, hex(match_eth_type))) print(" Actions: Apply Group (%s)\n" % group_id) time.sleep(rundelay) # Allocate a placeholder for the Flow Entry flow_entry1 = FlowEntry() # Generic attributes of the Flow Entry flow_entry1.set_flow_table_id(table_id) flow_entry1.set_flow_name(flow_name) flow_entry1.set_flow_id(flow_id) flow_entry1.set_flow_cookie(cookie) flow_entry1.set_flow_priority(priority) flow_entry1.set_flow_hard_timeout(0) flow_entry1.set_flow_idle_timeout(0) # Instructions/Actions for the Flow Entry instruction = Instruction(instruction_order=0) action_order = 0 action = GroupAction(action_order) action.set_group_id(group_id) instruction.add_apply_action(action) flow_entry1.add_instruction(instruction) # Match Fields for the Flow Entry match = Match() match.set_in_port(match_in_port) match.set_eth_type(match_eth_type) flow_entry1.add_match(match) print("<<< Flow to send:") print flow_entry1.get_payload() time.sleep(rundelay) result = ofswitch.add_modify_flow(flow_entry1) status = result.get_status() if (status.eq(STATUS.OK)): print("<<< Flow successfully added to the Controller") else: print("\n") print("!!!Demo terminated, reason: %s" % status.detailed()) delete_groups(ofswitch, grp_ids_cfg) delete_flows(ofswitch, table_id, range(first_flow_id, flow_id + 1)) exit(0) print "\n".strip() print("<<< Remove all flows from the Controller") time.sleep(rundelay) delete_flows(ofswitch, table_id, range(first_flow_id, flow_id + 1)) print "\n".strip() print("<<< Remove all groups from the Controller") for group_id in grp_ids_cfg: result = ofswitch.delete_group(group_id) status = result.get_status() if (status.eq(STATUS.OK)): print("<<< Group '%s' successfully removed from the Controller" % group_id) else: print("\n").strip() print("!!!Error, failed to remove group '%s', reason: %s" % (group_id, status.detailed())) print("\n").strip() print("<<< Get OpenFlow Groups Information") time.sleep(rundelay) result = ofswitch.get_configured_group_ids() status = result.get_status() if (status.eq(STATUS.OK)): grp_ids_cfg = result.get_data() elif (status.eq(STATUS.DATA_NOT_FOUND)): grp_ids_cfg = [] else: print("\n").strip() print("!!!Error, reason: %s" % status.detailed()) result = ofswitch.get_operational_group_ids() status = result.get_status() if (status.eq(STATUS.OK)): grp_ids_oper = result.get_data() elif (status.eq(STATUS.DATA_NOT_FOUND)): grp_ids_oper = [] else: print("\n") print("!!!Error, reason: %s" % status.detailed()) # Show current state of the Group Table in the Controller's # configuration and operational data stores print_groups(grp_ids_cfg, grp_ids_oper) print("\n").strip() print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print(">>> Demo End") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def of_demo_38(): f = "cfg.yml" d = {} if(load_dict_from_file(f, d) is False): print("Config file '%s' read error: " % f) exit(0) try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] nodeName = d['nodeName'] rundelay = d['rundelay'] except: print ("Failed to get Controller device attributes") exit(0) print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print ("<<< Demo 38 Start") print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) ofswitch = OFSwitch(ctrl, nodeName) print ("<<< 'Controller': %s, 'OpenFlow' switch: '%s'" % (ctrlIpAddr, nodeName)) first_flow_id = 110 # --------------------------------------------------- # First flow entry # --------------------------------------------------- table_id = 0 flow_id = first_flow_id flow_name = "Modify source and destination MAC addresses example1" priority = 700 cookie = 1100 match_in_port = 109 match_eth_type = ETH_TYPE_IPv4 match_ipv4_src_addr = "10.0.0.4/32" act_mod_src_mac_addr = "00:00:00:11:23:ae" act_mod_dst_mac_addr = "a0:ff:29:01:19:61" act_out_port = 112 print "\n" print ("<<< Set OpenFlow flow on the Controller") print (" Match: Input Port (%s)\n" " Ethernet Type (%s)\n" " IPv4 Source Address (%s)" % (match_in_port, hex(match_eth_type), match_ipv4_src_addr)) print (" Actions: Modify Ethernet Source MAC Address (%s)\n" " Modify Ethernet Destination MAC Address (%s)\n" " Output (%s)" % (act_mod_src_mac_addr, act_mod_dst_mac_addr, act_out_port)) time.sleep(rundelay) # Allocate a placeholder for the Flow Entry flow_entry1 = FlowEntry() # Generic attributes of the Flow Entry flow_entry1.set_flow_table_id(table_id) flow_entry1.set_flow_name(flow_name) flow_entry1.set_flow_id(flow_id) flow_entry1.set_flow_cookie(cookie) flow_entry1.set_flow_priority(priority) flow_entry1.set_flow_hard_timeout(0) flow_entry1.set_flow_idle_timeout(0) # Instructions/Actions for the Flow Entry instruction = Instruction(instruction_order=0) action_order = 0 action = SetDlSrcAction(action_order) action.set_dl_src(act_mod_src_mac_addr) instruction.add_apply_action(action) action_order += 1 action = SetDlDstAction(action_order) action.set_dl_dst(act_mod_dst_mac_addr) instruction.add_apply_action(action) action_order += 1 action = OutputAction(action_order) action.set_outport(act_out_port) instruction.add_apply_action(action) flow_entry1.add_instruction(instruction) # Match Fields for the Flow Entry match = Match() match.set_in_port(match_in_port) match.set_eth_type(match_eth_type) match.set_ipv4_src(match_ipv4_src_addr) flow_entry1.add_match(match) print ("\n") print ("<<< Flow to send:") print flow_entry1.get_payload() time.sleep(rundelay) result = ofswitch.add_modify_flow(flow_entry1) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully added to the Controller") else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.detailed()) delete_flows(ofswitch, table_id, range(first_flow_id, flow_id + 1)) exit(0) # --------------------------------------------------- # Second flow entry # --------------------------------------------------- table_id = 0 flow_id += 1 flow_name = "Modify source and destination MAC addresses example2" priority = 700 cookie = 1100 match_in_port = 109 match_eth_type = ETH_TYPE_IPv4 match_ipv4_src_addr = "192.1.0.11/32" act_mod_src_mac_addr = "00:1c:42:80:bd:66" act_mod_dst_mac_addr = "aa:1d:40:60:7c:9f" act_out_port = 112 print "\n" print ("<<< Set OpenFlow flow on the Controller") print (" Match: Input Port (%s)\n" " Ethernet Type (%s)\n" " IPv4 Source Address (%s)" % (match_in_port, hex(match_eth_type), match_ipv4_src_addr)) print (" Actions: Set Field (Ethernet Source MAC Address %s)\n" " Set Field (Ethernet Destination MAC Address %s)\n" " Output (%s)" % (act_mod_src_mac_addr, act_mod_dst_mac_addr, act_out_port)) time.sleep(rundelay) # Allocate a placeholder for the Flow Entry flow_entry2 = FlowEntry() # Generic attributes of the Flow Entry flow_entry2.set_flow_table_id(table_id) flow_entry2.set_flow_name(flow_name) flow_entry2.set_flow_id(flow_id) flow_entry2.set_flow_cookie(cookie) flow_entry2.set_flow_priority(priority) flow_entry2.set_flow_hard_timeout(0) flow_entry2.set_flow_idle_timeout(0) # Instructions/Actions for the Flow Entry instruction = Instruction(instruction_order=0) action_order = 0 action = SetFieldAction(action_order) action.set_eth_src(act_mod_src_mac_addr) instruction.add_apply_action(action) action_order += 1 action = SetFieldAction(action_order) action.set_eth_dst(act_mod_dst_mac_addr) instruction.add_apply_action(action) action_order += 1 action = OutputAction(action_order) action.set_outport(act_out_port) instruction.add_apply_action(action) flow_entry2.add_instruction(instruction) # Match Fields for the Flow Entry match = Match() match.set_in_port(match_in_port) match.set_eth_type(match_eth_type) match.set_ipv4_src(match_ipv4_src_addr) flow_entry2.add_match(match) print ("\n") print ("<<< Flow to send:") print flow_entry2.get_payload() time.sleep(rundelay) result = ofswitch.add_modify_flow(flow_entry2) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully added to the Controller") else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.detailed()) delete_flows(ofswitch, table_id, range(first_flow_id, flow_id + 1)) exit(0) print ("\n") print ("<<< Delete flows from the Controller's cache " "and from the table '%s' on the '%s' node" % (table_id, nodeName)) time.sleep(rundelay) delete_flows(ofswitch, table_id, range(first_flow_id, flow_id + 1)) print ("\n") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print (">>> Demo End") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def of_demo_44(): f = "cfg.yml" d = {} if(load_dict_from_file(f, d) is False): print("Config file '%s' read error: " % f) exit(0) try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] rundelay = d['rundelay'] except: print ("Failed to get Controller device attributes") exit(0) openflow_nodes = [] print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print ("<<< Demo 44 Start") print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print "\n" ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) print ("<<< Controller '%s:%s'" % (ctrlIpAddr, ctrlPortNum)) time.sleep(rundelay) print "\n".strip() print ("<<< Get OpenFlow switches information") time.sleep(rundelay) inv_obj = None result = ctrl.build_inventory_object() status = result.get_status() if(status.eq(STATUS.OK)): inv_obj = result.get_data() assert(isinstance(inv_obj, Inventory)) else: print ("\n") print ("!!!Error, failed to obtain inventory info, reason: %s" % status.brief().lower()) exit(0) assert(inv_obj) openflow_node_ids = inv_obj.get_openflow_node_ids() for node_id in openflow_node_ids: node = inv_obj.get_openflow_node(node_id) assert(isinstance(node, OpenFlowCapableNode)) openflow_nodes.append(node) print "\n".strip() print ("<<< OpenFlow switches in the inventory store") s1 = 'IP Address' s2 = 'OpenFlow Id' sym = '-' print "\n".strip() print " {0:<15} {1:<30}".format(s1, s2) print " {0:<15} {1:<30}".format(sym * 15, sym * 30) for node in openflow_nodes: addr = node.get_ip_address() node_id = node.get_id() print " {0:<15} {1:<30}".format(addr, node_id) print "\n".strip() print ("<<< Get Meter Features Information") time.sleep(rundelay) for node in openflow_nodes: assert(isinstance(node, OpenFlowCapableNode)) print "\n".strip() switch_id = node.get_id() print (" Switch '%s'") % switch_id print "\n".strip() meter_features = node.get_meter_features() assert(isinstance(meter_features, MeterFeatures)) s = 'Max meters' v = meter_features.get_max_meters() if v is not None: print " %s : %s" % (s, v) else: print " %s : %s" % (s, "n/a") s = "Max bands" v = meter_features.get_max_bands() if v is not None: print " %s : %s" % (s, v) else: print " %s : %s" % (s, "n/a") s = "Max colors" v = meter_features.get_max_colors() if v is not None: print " %s : %s" % (s, v) else: print " %s : %s" % (s, "n/a") q = 4 # number of list items to be in a single chunk (output string) s = 'Band types' alist = meter_features.get_band_types() if alist: chunks = [alist[x:x + q] for x in xrange(0, len(alist), q)] print " %s :" % s, for i in range(0, len(chunks)): n = 0 if i == 0 else len(s) + 18 print "%s%s" % (" " * n, ", ".join(chunks[i])) else: print " %s : %s" % (s, "n/a") s = 'Capabilities' alist = meter_features.get_capabilities() if alist: chunks = [alist[x:x + q] for x in xrange(0, len(alist), q)] print " %s :" % s, for i in range(0, len(chunks)): n = 0 if i == 0 else len(s) + 16 print "%s%s" % (" " * n, ", ".join(chunks[i])) else: print " %s : %s" % (s, "n/a") print ("\n") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print (">>> Demo End") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def of_demo_15(): f = "cfg.yml" d = {} if(load_dict_from_file(f, d) is False): print("Config file '%s' read error: " % f) exit() try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] nodeName = d['nodeName'] rundelay = d['rundelay'] except: print ("Failed to get Controller device attributes") exit(0) print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print ("<<< Demo 15 Start") print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) ofswitch = OFSwitch(ctrl, nodeName) # --- Flow Match: Ethernet Type # VLAN ID # Input Port eth_type = ETH_TYPE_IPv4 vlan_id = 100 input_port = 3 # --- Flow Actions: Push VLAN: Ethernet Type # Set Field: VLAN ID # Output: Port Number push_eth_type = ETH_TYPE_DOT1AD # 802.1ad VLAN tagged frame push_vlan_id = 200 output_port = 5 print ("<<< 'Controller': %s, 'OpenFlow' switch: '%s'" % (ctrlIpAddr, nodeName)) print "\n" print ("<<< Set OpenFlow flow on the Controller") print (" Match: Ethernet Type (%s)\n" " VLAN ID (%s)\n" " Input Port (%s)" % (hex(eth_type), vlan_id, input_port)) print (" Action: Push VLAN (Ethernet Type=%s)" % (hex(push_eth_type))) print (" Set Field (VLAN ID=%s)" % (push_vlan_id)) print (" Output (to Physical Port Number %s)" % (output_port)) time.sleep(rundelay) flow_entry = FlowEntry() flow_entry.set_flow_name(flow_name="Push VLAN") table_id = 0 flow_entry.set_flow_table_id(table_id) flow_id = 22 flow_entry.set_flow_id(flow_id) flow_entry.set_flow_priority(flow_priority=1013) flow_entry.set_flow_cookie(cookie=407) flow_entry.set_flow_cookie_mask(cookie_mask=255) flow_entry.set_flow_hard_timeout(hard_timeout=3400) flow_entry.set_flow_idle_timeout(idle_timeout=3400) # --- Instruction: 'Apply-actions' # Actions: 'PushVlan' # 'SetField' # 'Output' instruction = Instruction(instruction_order=0) action = PushVlanHeaderAction(order=0) action.set_eth_type(eth_type=push_eth_type) instruction.add_apply_action(action) action = SetFieldAction(order=1) action.set_vlan_id(vid=push_vlan_id) instruction.add_apply_action(action) action = OutputAction(order=2, port=output_port) instruction.add_apply_action(action) flow_entry.add_instruction(instruction) # --- Match Fields: Ethernet Type # Ethernet Source Address # Ethernet Destination Address # Input Port match = Match() match.set_eth_type(eth_type) match.set_vlan_id(vlan_id) match.set_in_port(in_port=input_port) flow_entry.add_match(match) print ("\n") print ("<<< Flow to send:") print flow_entry.get_payload() time.sleep(rundelay) result = ofswitch.add_modify_flow(flow_entry) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully added to the Controller") else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print ("<<< Get configured flow from the Controller") time.sleep(rundelay) result = ofswitch.get_configured_flow(table_id, flow_id) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully read from the Controller") print ("Flow info:") flow = result.get_data() print json.dumps(flow, indent=4) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print ("<<< Delete flow with id of '%s' from the Controller's cache " "and from the table '%s' on the '%s' node" % (flow_id, table_id, nodeName)) time.sleep(rundelay) result = ofswitch.delete_flow(flow_entry.get_flow_table_id(), flow_entry.get_flow_id()) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully removed from the Controller") else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print (">>> Demo End") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
""" import json from pybvc.controller.controller import Controller from pybvc.common.status import STATUS from pybvc.common.utils import load_dict_from_file if __name__ == "__main__": f = "cfg.yml" d = {} if(load_dict_from_file(f, d) is False): print("Config file '%s' read error: " % f) exit() try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] nodeId = "openflow:1" except: print ("Failed to get Controller device attributes") exit(0) print "\n"
def vr_demo_2(): f = "cfg4.yml" d = {} if load_dict_from_file(f, d) is False: print ("Config file '%s' read error: " % f) exit() try: ctrlIpAddr = d["ctrlIpAddr"] ctrlPortNum = d["ctrlPortNum"] ctrlUname = d["ctrlUname"] ctrlPswd = d["ctrlPswd"] nodeName = d["nodeName"] nodeIpAddr = d["nodeIpAddr"] nodePortNum = d["nodePortNum"] nodeUname = d["nodeUname"] nodePswd = d["nodePswd"] rundelay = d["rundelay"] except: print ("Failed to get Controller device attributes") exit(0) print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print ("<<< Demo Start") print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print ("\n") ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) vrouter = VRouter5600(ctrl, nodeName, nodeIpAddr, nodePortNum, nodeUname, nodePswd) print ("<<< 'Controller': %s, '%s': %s" % (ctrlIpAddr, nodeName, nodeIpAddr)) print ("\n") time.sleep(rundelay) node_configured = False result = ctrl.check_node_config_status(nodeName) status = result.get_status() if status.eq(STATUS.NODE_CONFIGURED): node_configured = True print ("<<< '%s' is configured on the Controller" % nodeName) elif status.eq(STATUS.DATA_NOT_FOUND): node_configured = False else: print ("\n") print "Failed to get configuration status for the '%s'" % nodeName print ("!!!Demo terminated, reason: %s" % status.detailed()) exit(0) if node_configured is False: result = ctrl.add_netconf_node(vrouter) status = result.get_status() if status.eq(STATUS.OK): print ("<<< '%s' added to the Controller" % nodeName) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.detailed()) exit(0) print ("\n") time.sleep(rundelay) result = ctrl.check_node_conn_status(nodeName) status = result.get_status() if status.eq(STATUS.NODE_CONNECTED): print ("<<< '%s' is connected to the Controller" % nodeName) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print "\n" yangModelName = "vyatta-security-firewall" yangModelVerson = "2014-11-07" print ("<<< Retrieve '%s' YANG model definition from the '%s'" % (yangModelName, nodeName)) time.sleep(rundelay) result = vrouter.get_schema(yangModelName, yangModelVerson) status = result.get_status() if status.eq(STATUS.OK): print "YANG model definition:" schema = result.get_data() print schema else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print "\n" print (">>> Remove '%s' NETCONF node from the Controller" % nodeName) time.sleep(rundelay) result = ctrl.delete_netconf_node(vrouter) status = result.get_status() if status.eq(STATUS.OK): print ("'%s' NETCONF node was successfully removed " "from the Controller" % nodeName) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief()) exit(0) print "\n" print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print (">>> Demo End") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def of_demo_15(): f = "cfg.yml" d = {} if (load_dict_from_file(f, d) is False): print("Config file '%s' read error: " % f) exit() try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] nodeName = d['nodeName'] rundelay = d['rundelay'] except: print("Failed to get Controller device attributes") exit(0) print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print("<<< Demo 15 Start") print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) ofswitch = OFSwitch(ctrl, nodeName) # --- Flow Match: Ethernet Type # VLAN ID # Input Port eth_type = ETH_TYPE_IPv4 vlan_id = 100 input_port = 3 # --- Flow Actions: Push VLAN: Ethernet Type # Set Field: VLAN ID # Output: Port Number push_eth_type = ETH_TYPE_DOT1AD # 802.1ad VLAN tagged frame push_vlan_id = 200 output_port = 5 print("<<< 'Controller': %s, 'OpenFlow' switch: '%s'" % (ctrlIpAddr, nodeName)) print "\n" print("<<< Set OpenFlow flow on the Controller") print( " Match: Ethernet Type (%s)\n" " VLAN ID (%s)\n" " Input Port (%s)" % (hex(eth_type), vlan_id, input_port)) print(" Action: Push VLAN (Ethernet Type=%s)" % (hex(push_eth_type))) print(" Set Field (VLAN ID=%s)" % (push_vlan_id)) print(" Output (to Physical Port Number %s)" % (output_port)) time.sleep(rundelay) flow_entry = FlowEntry() flow_entry.set_flow_name(flow_name="Push VLAN") table_id = 0 flow_entry.set_flow_table_id(table_id) flow_id = 22 flow_entry.set_flow_id(flow_id) flow_entry.set_flow_priority(flow_priority=1013) flow_entry.set_flow_cookie(cookie=407) flow_entry.set_flow_cookie_mask(cookie_mask=255) flow_entry.set_flow_hard_timeout(hard_timeout=3400) flow_entry.set_flow_idle_timeout(idle_timeout=3400) # --- Instruction: 'Apply-actions' # Actions: 'PushVlan' # 'SetField' # 'Output' instruction = Instruction(instruction_order=0) action = PushVlanHeaderAction(order=0) action.set_eth_type(eth_type=push_eth_type) instruction.add_apply_action(action) action = SetFieldAction(order=1) action.set_vlan_id(vid=push_vlan_id) instruction.add_apply_action(action) action = OutputAction(order=2, port=output_port) instruction.add_apply_action(action) flow_entry.add_instruction(instruction) # --- Match Fields: Ethernet Type # Ethernet Source Address # Ethernet Destination Address # Input Port match = Match() match.set_eth_type(eth_type) match.set_vlan_id(vlan_id) match.set_in_port(in_port=input_port) flow_entry.add_match(match) print("\n") print("<<< Flow to send:") print flow_entry.get_payload() time.sleep(rundelay) result = ofswitch.add_modify_flow(flow_entry) status = result.get_status() if (status.eq(STATUS.OK)): print("<<< Flow successfully added to the Controller") else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print("\n") print("<<< Get configured flow from the Controller") time.sleep(rundelay) result = ofswitch.get_configured_flow(table_id, flow_id) status = result.get_status() if (status.eq(STATUS.OK)): print("<<< Flow successfully read from the Controller") print("Flow info:") flow = result.get_data() print json.dumps(flow, indent=4) else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print("\n") print( "<<< Delete flow with id of '%s' from the Controller's cache " "and from the table '%s' on the '%s' node" % (flow_id, table_id, nodeName)) time.sleep(rundelay) result = ofswitch.delete_flow(flow_entry.get_flow_table_id(), flow_entry.get_flow_id()) status = result.get_status() if (status.eq(STATUS.OK)): print("<<< Flow successfully removed from the Controller") else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print("\n") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print(">>> Demo End") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def vr_demo_7(): f = "cfg4.yml" d = {} if (load_dict_from_file(f, d) is False): print("Config file '%s' read error: " % f) exit() try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] nodeName = d['nodeName'] nodeIpAddr = d['nodeIpAddr'] nodePortNum = d['nodePortNum'] nodeUname = d['nodeUname'] nodePswd = d['nodePswd'] ifName = d['interfaceName'] rundelay = d['rundelay'] except: print("Failed to get Controller device attributes") exit(0) print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print("<<< Demo Start") print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print("\n") ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) vrouter = VRouter5600(ctrl, nodeName, nodeIpAddr, nodePortNum, nodeUname, nodePswd) print("<<< 'Controller': %s, '%s': %s" % (ctrlIpAddr, nodeName, nodeIpAddr)) print("\n") time.sleep(rundelay) node_configured = False result = ctrl.check_node_config_status(nodeName) status = result.get_status() if (status.eq(STATUS.NODE_CONFIGURED)): node_configured = True print("<<< '%s' is configured on the Controller" % nodeName) elif (status.eq(STATUS.DATA_NOT_FOUND)): node_configured = False else: print("\n") print "Failed to get configuration status for the '%s'" % nodeName print("!!!Demo terminated, reason: %s" % status.detailed()) exit(0) if node_configured is False: result = ctrl.add_netconf_node(vrouter) status = result.get_status() if (status.eq(STATUS.OK)): print("<<< '%s' added to the Controller" % nodeName) else: print("\n") print("!!!Demo terminated, reason: %s" % status.detailed()) exit(0) print("\n") time.sleep(rundelay) result = ctrl.check_node_conn_status(nodeName) status = result.get_status() if (status.eq(STATUS.NODE_CONNECTED)): print("<<< '%s' is connected to the Controller" % nodeName) else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print("\n") print("<<< Show firewalls configuration on the '%s'" % nodeName) time.sleep(rundelay) result = vrouter.get_firewalls_cfg() status = result.get_status() if (status.eq(STATUS.OK)): print("'%s' firewalls config:" % nodeName) cfg = result.get_data() data = json.loads(cfg) print json.dumps(data, indent=4) elif (status.eq(STATUS.DATA_NOT_FOUND)): print("No firewalls configuration found") else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) ctrl.delete_netconf_node(vrouter) exit(0) print "\n" fwName1 = "ACCEPT-SRC-IPADDR" print(">>> Create new firewall instance '%s' on '%s'" % (fwName1, nodeName)) firewall1 = Firewall(fwName1) # Add a rule to the firewall instance rulenum = 30 rule = Rule(rulenum) rule.add_action("accept") rule.add_source_address("172.22.17.108") firewall1.add_rule(rule) print firewall1.get_payload() time.sleep(rundelay) result = vrouter.add_modify_firewall_instance(firewall1) status = result.get_status() if (status.eq(STATUS.OK)): print("Firewall instance '%s' was successfully created" % fwName1) else: print("\n") print("!!!Demo terminated, reason: %s" % status.detailed()) exit(0) print "\n" fwName2 = "DROP-ICMP" print(">>> Create new firewall instance '%s' on '%s'" % (fwName2, nodeName)) firewall2 = Firewall(fwName2) # Add a rule to the firewall instance rulenum = 40 rule = Rule(rulenum) rule.add_action("drop") rule.add_icmp_typename("ping") firewall2.add_rule(rule) print firewall2.get_payload() time.sleep(rundelay) result = vrouter.add_modify_firewall_instance(firewall2) status = result.get_status() if (status.eq(STATUS.OK)): print("Firewall instance '%s' was successfully created" % fwName2) else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) print status.detailed() exit(0) print("\n") print("<<< Show firewalls configuration on the '%s'" % nodeName) time.sleep(rundelay) result = vrouter.get_firewalls_cfg() status = result.get_status() if (status.eq(STATUS.OK)): print("'%s' firewalls config:" % nodeName) cfg = result.get_data() data = json.loads(cfg) print json.dumps(data, indent=4) else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print("\n") print( "<<< Apply firewall '%s' to inbound traffic " "and '%s' to outbound traffic on the '%s' " "dataplane interface" % (fwName1, fwName2, ifName)) time.sleep(rundelay) result = vrouter.set_dataplane_interface_firewall(ifName, fwName1, fwName2) status = result.get_status() if (status.eq(STATUS.OK)): print( "Firewall instances were successfully applied " "to the '%s' dataplane interface" % (ifName)) else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print("\n") print("<<< Show '%s' dataplane interface configuration on the '%s'" % (ifName, nodeName)) time.sleep(rundelay) result = vrouter.get_dataplane_interface_cfg(ifName) status = result.get_status() if (status.eq(STATUS.OK)): print("Interfaces '%s' config:" % ifName) cfg = result.get_data() data = json.loads(cfg) print json.dumps(data, indent=4) else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print("\n") print("<<< Remove firewall settings from the '%s' dataplane interface" % (ifName)) time.sleep(rundelay) result = vrouter.delete_dataplane_interface_firewall(ifName) status = result.get_status() if (status.eq(STATUS.OK)): print( "Firewall settings successfully removed " "from '%s' dataplane interface" % ifName) else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print("\n") print("<<< Show '%s' dataplane interface configuration on the '%s'" % (ifName, nodeName)) time.sleep(rundelay) result = vrouter.get_dataplane_interface_cfg(ifName) status = result.get_status() if (status.eq(STATUS.OK)): print("Interfaces '%s' config:" % ifName) cfg = result.get_data() data = json.loads(cfg) print json.dumps(data, indent=4) else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print "\n" print(">>> Remove firewall instance '%s' from '%s'" % (fwName1, nodeName)) time.sleep(rundelay) result = vrouter.delete_firewall_instance(firewall1) status = result.get_status() if (status.eq(STATUS.OK)): print("Firewall instance '%s' was successfully deleted" % fwName1) else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print "\n" print(">>> Remove firewall instance '%s' from '%s'" % (fwName2, nodeName)) time.sleep(rundelay) result = vrouter.delete_firewall_instance(firewall2) status = result.get_status() if (status.eq(STATUS.OK)): print("Firewall instance '%s' was successfully deleted" % fwName2) else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print("\n") print("<<< Show firewalls configuration on the '%s'" % nodeName) time.sleep(rundelay) result = vrouter.get_firewalls_cfg() status = result.get_status() if (status.eq(STATUS.OK)): print("'%s' firewalls config:" % nodeName) cfg = result.get_data() data = json.loads(cfg) print json.dumps(data, indent=4) else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print "\n" print(">>> Remove '%s' NETCONF node from the Controller" % nodeName) time.sleep(rundelay) result = ctrl.delete_netconf_node(vrouter) status = result.get_status() if (status.eq(STATUS.OK)): print( "'%s' NETCONF node was successfully removed " "from the Controller" % nodeName) else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief()) exit(0) print("\n") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print(">>> Demo End") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def of_demo_19(): f = "cfg.yml" d = {} if (load_dict_from_file(f, d) is False): print("Config file '%s' read error: " % f) exit() try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] nodeName = d['nodeName'] rundelay = d['rundelay'] except: print("Failed to get Controller device attributes") exit(0) print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print("<<< Demo 19 Start") print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) ofswitch = OFSwitch(ctrl, nodeName) # --- Flow Match: Ethernet Type # IPv6 Source Address # IPv6 Destination Address # IP DSCP # TCP Source Port # TCP Destination Port eth_type = ETH_TYPE_IPv6 ipv6_src = "4231::3210:3210:3210:3210/80" ipv6_dst = "1234:1234:1234:1234::5678:5678/64" ipv6_flabel = 33 ip_dscp = IP_DSCP_CS5 # 'Class Selector' = 'Critical' ip_proto = IP_PROTO_TCP tcp_src_port = 11111 tcp_dst_port = 22222 # --- Flow Actions: Output (CONTROLLER) output_port = "CONTROLLER" print("<<< 'Controller': %s, 'OpenFlow' switch: '%s'" % (ctrlIpAddr, nodeName)) print "\n" print("<<< Set OpenFlow flow on the Controller") print( " Match: Ethernet Type (%s)\n" " IPv6 Source Address (%s)\n" " IPv6 Destination Address (%s)\n" " IPv6 Flow Label (%s)\n" " IP DSCP (%s)\n" " TCP Source Port (%s)\n" " TCP Destination Port (%s)" % (hex(eth_type), ipv6_src, ipv6_dst, ipv6_flabel, ip_dscp, tcp_src_port, tcp_dst_port)) print(" Action: Output (to %s)" % (output_port)) time.sleep(rundelay) flow_entry = FlowEntry() flow_entry.set_flow_name(flow_name="demo19.py") table_id = 0 flow_id = 25 flow_entry.set_flow_table_id(table_id) flow_entry.set_flow_id(flow_id) flow_entry.set_flow_priority(flow_priority=1018) flow_entry.set_flow_cookie(cookie=23) flow_entry.set_flow_hard_timeout(hard_timeout=1200) flow_entry.set_flow_idle_timeout(idle_timeout=3400) # --- Instruction: 'Apply-actions' # Actions: 'Output' instruction = Instruction(instruction_order=0) action = OutputAction(order=0, port=output_port) instruction.add_apply_action(action) flow_entry.add_instruction(instruction) # --- Match Fields: Ethernet Type # IPv6 Source Address # IPv6 Destination Address # IPv6 Flow Label # IP protocol number (TCP) # IP DSCP # TCP Source Port # TCP Destination Port match = Match() match.set_eth_type(eth_type) match.set_ipv6_src(ipv6_src) match.set_ipv6_dst(ipv6_dst) match.set_ipv6_flabel(ipv6_flabel) match.set_ip_proto(ip_proto) match.set_ip_dscp(ip_dscp) match.set_tcp_src(tcp_src_port) match.set_tcp_dst(tcp_dst_port) flow_entry.add_match(match) print("\n") print("<<< Flow to send:") print flow_entry.get_payload() time.sleep(rundelay) result = ofswitch.add_modify_flow(flow_entry) status = result.get_status() if (status.eq(STATUS.OK)): print("<<< Flow successfully added to the Controller") else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print("\n") print("<<< Get configured flow from the Controller") time.sleep(rundelay) result = ofswitch.get_configured_flow(table_id, flow_id) status = result.get_status() if (status.eq(STATUS.OK)): print("<<< Flow successfully read from the Controller") print("Flow info:") flow = result.get_data() print json.dumps(flow, indent=4) else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print("\n") print( "<<< Delete flow with id of '%s' from the Controller's cache " "and from the table '%s' on the '%s' node" % (flow_id, table_id, nodeName)) time.sleep(rundelay) result = ofswitch.delete_flow(flow_entry.get_flow_table_id(), flow_entry.get_flow_id()) status = result.get_status() if (status.eq(STATUS.OK)): print("<<< Flow successfully removed from the Controller") else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print("\n") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print(">>> Demo End") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def of_demo_37(): f = "cfg.yml" d = {} if(load_dict_from_file(f, d) is False): print("Config file '%s' read error: " % f) exit(0) try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] nodeName = d['nodeName'] rundelay = d['rundelay'] except: print ("Failed to get Controller device attributes") exit(0) print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print ("<<< Demo 37 Start") print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) ofswitch = OFSwitch(ctrl, nodeName) print ("<<< 'Controller': %s, 'OpenFlow' switch: '%s'" % (ctrlIpAddr, nodeName)) first_flow_id = 110 # --------------------------------------------------- # First flow entry # --------------------------------------------------- table_id = 0 flow_id = first_flow_id flow_name = "Modify VLAN ID and VLAN priority example1" priority = 600 cookie = 1000 match_in_port = 109 match_eth_type = ETH_TYPE_IPv4 match_vlan_id = 100 act_mod_vlan_id = 172 act_mod_vlan_pcp = 2 act_out_port = 112 print "\n" print ("<<< Set OpenFlow flow on the Controller") print (" Match: Input Port (%s)\n" " Ethernet Type (%s)\n" " VLAN ID (%s)" % (match_in_port, hex(match_eth_type), match_vlan_id)) print (" Actions: Set VLAN ID (%s)\n" " Set VLAN priority (%s)\n" " Output (%s)" % (act_mod_vlan_id, act_mod_vlan_pcp, act_out_port)) time.sleep(rundelay) # Allocate a placeholder for the Flow Entry flow_entry1 = FlowEntry() # Generic attributes of the Flow Entry flow_entry1.set_flow_table_id(table_id) flow_entry1.set_flow_name(flow_name) flow_entry1.set_flow_id(flow_id) flow_entry1.set_flow_cookie(cookie) flow_entry1.set_flow_priority(priority) flow_entry1.set_flow_hard_timeout(0) flow_entry1.set_flow_idle_timeout(0) # Instructions/Actions for the Flow Entry instruction = Instruction(instruction_order=0) action_order = 0 action = SetVlanIdAction(action_order) action.set_vid(act_mod_vlan_id) instruction.add_apply_action(action) action_order += 1 action = SetVlanPCPAction(action_order) action.set_vlan_pcp(act_mod_vlan_pcp) instruction.add_apply_action(action) action_order += 1 action = OutputAction(action_order) action.set_outport(act_out_port) instruction.add_apply_action(action) flow_entry1.add_instruction(instruction) # Match Fields for the Flow Entry match = Match() match.set_in_port(match_in_port) match.set_eth_type(match_eth_type) match.set_vlan_id(match_vlan_id) flow_entry1.add_match(match) print ("\n") print ("<<< Flow to send:") print flow_entry1.get_payload() time.sleep(rundelay) result = ofswitch.add_modify_flow(flow_entry1) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully added to the Controller") else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.detailed()) delete_flows(ofswitch, table_id, range(first_flow_id, flow_id + 1)) exit(0) # --------------------------------------------------- # Second flow entry # --------------------------------------------------- table_id = 0 flow_id += 1 flow_name = "Modify VLAN ID and VLAN priority example2" priority = 600 cookie = 1000 match_in_port = 109 match_eth_type = ETH_TYPE_IPv4 match_vlan_id = 111 act_mod_vlan_id = 1024 act_mod_vlan_pcp = 3 act_out_port = 112 print "\n" print ("<<< Set OpenFlow flow on the Controller") print (" Match: Input Port (%s)\n" " Ethernet Type (%s)\n" " VLAN ID (%s)" % (match_in_port, hex(match_eth_type), match_vlan_id)) print (" Actions: Set Field (VLAN ID %s)\n" " Set Field (VLAN PCP %s)\n" " Output (Port number %s)" % (act_mod_vlan_id, act_mod_vlan_pcp, act_out_port)) time.sleep(rundelay) # Allocate a placeholder for the Flow Entry flow_entry2 = FlowEntry() # Generic attributes of the Flow Entry flow_entry2.set_flow_table_id(table_id) flow_entry2.set_flow_name(flow_name) flow_entry2.set_flow_id(flow_id) flow_entry2.set_flow_cookie(cookie) flow_entry2.set_flow_priority(priority) flow_entry2.set_flow_hard_timeout(0) flow_entry2.set_flow_idle_timeout(0) # Instructions/Actions for the Flow Entry instruction = Instruction(instruction_order=0) action_order = 0 action = SetFieldAction(action_order) action.set_vlan_id(act_mod_vlan_id) instruction.add_apply_action(action) action_order += 1 action = SetFieldAction(action_order) action.set_vlan_pcp(act_mod_vlan_pcp) instruction.add_apply_action(action) action_order += 1 action = OutputAction(action_order) action.set_outport(act_out_port) instruction.add_apply_action(action) flow_entry2.add_instruction(instruction) # Match Fields for the Flow Entry match = Match() match.set_in_port(match_in_port) match.set_eth_type(match_eth_type) match.set_vlan_id(match_vlan_id) flow_entry2.add_match(match) print ("\n") print ("<<< Flow to send:") print flow_entry2.get_payload() time.sleep(rundelay) result = ofswitch.add_modify_flow(flow_entry2) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully added to the Controller") else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.detailed()) delete_flows(ofswitch, table_id, range(first_flow_id, flow_id + 1)) exit(0) # --------------------------------------------------- # Third flow entry # --------------------------------------------------- table_id = 0 flow_id += 1 flow_name = "Strip VLAN header action example" priority = 600 cookie = 1000 match_in_port = 112 match_eth_type = ETH_TYPE_IPv4 match_vlan_id = 172 act_out_port = 109 print "\n" print ("<<< Set OpenFlow flow on the Controller") print (" Match: Input Port (%s)\n" " Ethernet Type (%s)\n" " VLAN ID (%s)" % (match_in_port, hex(match_eth_type), match_vlan_id)) print (" Actions: Strip VLAN header\n" " Output (Port number %s)" % (act_out_port)) time.sleep(rundelay) # Allocate a placeholder for the Flow Entry flow_entry3 = FlowEntry() # Generic attributes of the Flow Entry flow_entry3.set_flow_table_id(table_id) flow_entry3.set_flow_name(flow_name) flow_entry3.set_flow_id(flow_id) flow_entry3.set_flow_cookie(cookie) flow_entry3.set_flow_priority(priority) flow_entry3.set_flow_hard_timeout(0) flow_entry3.set_flow_idle_timeout(0) # Instructions/Actions for the Flow Entry instruction = Instruction(instruction_order=0) action_order = 0 action = StripVlanAction(action_order) instruction.add_apply_action(action) action_order += 1 action = OutputAction(action_order) action.set_outport(act_out_port) instruction.add_apply_action(action) flow_entry3.add_instruction(instruction) # Match Fields for the Flow Entry match = Match() match.set_in_port(match_in_port) match.set_eth_type(match_eth_type) match.set_vlan_id(match_vlan_id) flow_entry3.add_match(match) print ("\n") print ("<<< Flow to send:") print flow_entry3.get_payload() time.sleep(rundelay) result = ofswitch.add_modify_flow(flow_entry3) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully added to the Controller") else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.detailed()) delete_flows(ofswitch, table_id, range(first_flow_id, flow_id + 1)) exit(0) print ("\n") print ("<<< Delete flows from the Controller's cache " "and from the table '%s' on the '%s' node" % (table_id, nodeName)) time.sleep(rundelay) delete_flows(ofswitch, table_id, range(first_flow_id, flow_id + 1)) print ("\n") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print (">>> Demo End") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
""" import time import json from pybvc.controller.controller import Controller from pybvc.netconfdev.vrouter.vrouter5600 import VRouter5600 from pybvc.netconfdev.vrouter.vpn import Vpn from pybvc.common.status import STATUS from pybvc.common.utils import load_dict_from_file if __name__ == "__main__": f = "cfg4.yml" d = {} if(load_dict_from_file(f, d) == False): print("Config file '%s' read error: " % f) exit() try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] nodeName = d['nodeName'] nodeIpAddr = d['nodeIpAddr'] nodePortNum = d['nodePortNum'] nodeUname = d['nodeUname'] nodePswd = d['nodePswd'] except:
def of_demo_11(): f = "cfg.yml" d = {} if (load_dict_from_file(f, d) is False): print("Config file '%s' read error: " % f) exit() try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] nodeName = d['nodeName'] rundelay = d['rundelay'] except: print("Failed to get Controller device attributes") exit(0) print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print("<<< Demo 11 Start") print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) ofswitch = OFSwitch(ctrl, nodeName) # --- Flow Match: Ethernet Source Address # Ethernet Destination Address # IPv4 Source Address # IPv4 Destination Address # ICMPv4 Type # ICMPv4 Code # IP DSCP # IP ECN # Input Port # NOTE: Ethernet type MUST be 2048 (0x800) -> IPv4 protocol # IP Protocol Type MUST be 1 -> ICMP eth_type = ETH_TYPE_IPv4 eth_src = "00:00:00:11:23:ae" eth_dst = "00:ff:20:01:1a:3d" ipv4_src = "17.1.2.3/8" ipv4_dst = "172.168.5.6/18" ip_proto = IP_PROTO_ICMP ip_dscp = IP_DSCP_CS2 # 'Class Selector' = 'Immediate' ip_ecn = IP_ECN_CE # Congestion Encountered icmpv4_type = 6 # Alternate Host Address icmpv4_code = 3 # Alternate Address for Host input_port = 10 print("<<< 'Controller': %s, 'OpenFlow' switch: '%s'" % (ctrlIpAddr, nodeName)) print "\n" print("<<< Set OpenFlow flow on the Controller") print( " Match: Ethernet Type (%s)\n" " Ethernet Source Address (%s)\n" " Ethernet Destination Address (%s)\n" " IPv4 Source Address (%s)\n" " IPv4 Destination Address (%s)\n" " IP Protocol Number (%s)\n" " IP DSCP (%s)\n" " IP ECN (%s)\n" " ICMPv4 Type (%s)\n" " ICMPv4 Code (%s)\n" " Input Port (%s)" % (hex(eth_type), eth_src, eth_dst, ipv4_src, ipv4_dst, ip_proto, ip_dscp, ip_ecn, icmpv4_type, icmpv4_code, input_port)) print(" Action: Output (NORMAL)") time.sleep(rundelay) flow_entry = FlowEntry() table_id = 0 flow_entry.set_flow_table_id(table_id) flow_id = 18 flow_entry.set_flow_id(flow_id) flow_entry.set_flow_hard_timeout(0) flow_entry.set_flow_idle_timeout(0) flow_entry.set_flow_priority(1009) # --- Instruction: 'Apply-actions' # Action: 'Output' NORMAL instruction = Instruction(instruction_order=0) action = OutputAction(order=0, port="NORMAL") instruction.add_apply_action(action) flow_entry.add_instruction(instruction) # --- Match Fields: Ethernet Type # Ethernet Source Address # Ethernet Destination Address # IPv4 Source Address # IPv4 Destination Address # IP Protocol Number # IP DSCP # IP ECN # ICMPv4 Type # ICMPv4 Code # Input Port match = Match() match.set_eth_type(eth_type) match.set_eth_src(eth_src) match.set_eth_dst(eth_dst) match.set_ipv4_src(ipv4_src) match.set_ipv4_dst(ipv4_dst) match.set_ip_proto(ip_proto) match.set_ip_dscp(ip_dscp) match.set_ip_ecn(ip_ecn) match.set_icmpv4_type(icmpv4_type) match.set_icmpv4_code(icmpv4_code) match.set_in_port(input_port) flow_entry.add_match(match) print("\n") print("<<< Flow to send:") print flow_entry.get_payload() time.sleep(rundelay) result = ofswitch.add_modify_flow(flow_entry) status = result.get_status() if (status.eq(STATUS.OK)): print("<<< Flow successfully added to the Controller") else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print("\n") print("<<< Get configured flow from the Controller") time.sleep(rundelay) result = ofswitch.get_configured_flow(table_id, flow_id) status = result.get_status() if (status.eq(STATUS.OK)): print("<<< Flow successfully read from the Controller") print("Flow info:") flow = result.get_data() print json.dumps(flow, indent=4) else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print("\n") print( "<<< Delete flow with id of '%s' from the Controller's cache " "and from the table '%s' on the '%s' node" % (flow_id, table_id, nodeName)) time.sleep(rundelay) result = ofswitch.delete_flow(flow_entry.get_flow_table_id(), flow_entry.get_flow_id()) status = result.get_status() if (status.eq(STATUS.OK)): print("<<< Flow successfully removed from the Controller") else: print("\n") print("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print("\n") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print(">>> Demo End") print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def of_demo_18(): f = "cfg.yml" d = {} if(load_dict_from_file(f, d) is False): print("Config file '%s' read error: " % f) exit() try: ctrlIpAddr = d['ctrlIpAddr'] ctrlPortNum = d['ctrlPortNum'] ctrlUname = d['ctrlUname'] ctrlPswd = d['ctrlPswd'] nodeName = d['nodeName'] rundelay = d['rundelay'] except: print ("Failed to get Controller device attributes") exit(0) print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print ("<<< Demo 18 Start") print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) ofswitch = OFSwitch(ctrl, nodeName) # --- Flow Match: Ethernet Type # IPv6 Source Address # IPv6 Destination Address # IP DSCP # TCP Source Port # TCP Destination Port eth_type = ETH_TYPE_IPv6 ipv6_src = "2001::2acf:e9ff:fe21:6431/80" ipv6_dst = "2004:1234:2acf:e9ff::fe21:6431/64" ip_dscp = IP_DSCP_CS1 # 'Class Selector' = 'Priority' ip_proto = IP_PROTO_TCP tcp_src_port = 12345 tcp_dst_port = 54321 # --- Flow Actions: Output (CONTROLLER) output_port = "CONTROLLER" print ("<<< 'Controller': %s, 'OpenFlow' switch: '%s'" % (ctrlIpAddr, nodeName)) print "\n" print ("<<< Set OpenFlow flow on the Controller") print (" Match: Ethernet Type (%s)\n" " IPv6 Source Address (%s)\n" " IPv6 Destination Address (%s)\n" " IP DSCP (%s)\n" " TCP Source Port (%s)\n" " TCP Destination Port (%s)" % (hex(eth_type), ipv6_src, ipv6_dst, ip_dscp, tcp_src_port, tcp_dst_port)) print (" Action: Output (to %s)" % (output_port)) time.sleep(rundelay) flow_entry = FlowEntry() flow_entry.set_flow_name(flow_name="demo18.py") table_id = 0 flow_id = 24 flow_entry.set_flow_table_id(table_id) flow_entry.set_flow_id(flow_id) flow_entry.set_flow_hard_timeout(0) flow_entry.set_flow_idle_timeout(0) flow_entry.set_flow_priority(flow_priority=1017) # --- Instruction: 'Apply-actions' # Actions: 'Output' instruction = Instruction(instruction_order=0) action = OutputAction(order=0, port=output_port) instruction.add_apply_action(action) flow_entry.add_instruction(instruction) # --- Match Fields: Ethernet Type # IPv6 Source Address # IPv6 Destination Address # IP protocol number (TCP) # IP DSCP # TCP Source Port # TCP Destination Port match = Match() match.set_eth_type(eth_type) match.set_ipv6_src(ipv6_src) match.set_ipv6_dst(ipv6_dst) match.set_ip_proto(ip_proto) match.set_ip_dscp(ip_dscp) match.set_tcp_src_port(tcp_src_port) match.set_tcp_dst_port(tcp_dst_port) flow_entry.add_match(match) print ("\n") print ("<<< Flow to send:") print flow_entry.get_payload() time.sleep(rundelay) result = ofswitch.add_modify_flow(flow_entry) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully added to the Controller") else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print ("<<< Get configured flow from the Controller") time.sleep(rundelay) result = ofswitch.get_configured_flow(table_id, flow_id) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully read from the Controller") print ("Flow info:") flow = result.get_data() print json.dumps(flow, indent=4) else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print ("<<< Delete flow with id of '%s' from the Controller's cache " "and from the table '%s' on the '%s' node" % (flow_id, table_id, nodeName)) time.sleep(rundelay) result = ofswitch.delete_flow(flow_entry.get_flow_table_id(), flow_entry.get_flow_id()) status = result.get_status() if(status.eq(STATUS.OK)): print ("<<< Flow successfully removed from the Controller") else: print ("\n") print ("!!!Demo terminated, reason: %s" % status.brief().lower()) exit(0) print ("\n") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print (">>> Demo End") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
def nc_demo_13(): f = "cfg1.yml" d = {} if load_dict_from_file(f, d) is False: print ("Config file '%s' read error: " % f) exit() try: ctrlIpAddr = d["ctrlIpAddr"] ctrlPortNum = d["ctrlPortNum"] ctrlUname = d["ctrlUname"] ctrlPswd = d["ctrlPswd"] rundelay = d["rundelay"] except: print ("Failed to get Controller device attributes") exit(0) netconf_ids = [] netconf_nodes = [] print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print ("<<< Demo Start") print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") print "\n" ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd) print ("<<< Controller '%s:%s'" % (ctrlIpAddr, ctrlPortNum)) time.sleep(rundelay) print "\n" print ("<<< Get NETCONF Inventory Information") time.sleep(rundelay) result = ctrl.get_netconf_nodes_in_config() status = result.get_status() if status.eq(STATUS.OK): netconf_ids = result.get_data() else: print ("\n") print ("!!!Demo terminated, " "failed to get list of NETCONF devices, " "reason: %s" % status.brief()) exit(0) print "\n" print ("<<< NETCONF devices") print "\n".strip() for node_id in netconf_ids: print " %s" % node_id for node_id in netconf_ids: result = ctrl.build_netconf_node_inventory_object(node_id) status = result.get_status() if status.eq(STATUS.OK): node = result.get_data() assert isinstance(node, NetconfCapableNode) netconf_nodes.append(node) else: print ("\n") print ( "!!!Demo terminated, " "failed to build object for NETCONF device '%s', " "reason: %s" % (node_id, status.brief()) ) exit(0) for node in netconf_nodes: time.sleep(rundelay) print "\n".strip() print "<<< Information for '{}' device".format(node.get_id()) print "\n".strip() print " Device Name : {}".format(node.get_id()) print " Connection status : {}".format(node.get_conn_status()) print "\n".strip() print " Initial Capabilities" print " {}".format("-" * 60) clist = node.get_initial_capabilities() for item in clist: print " {}".format(item) print ("\n") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") print (">>> Demo End") print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")