" IP DSCP (%s)\n" " IP ECN (%s)\n" " UDP Source Port Number (%s)\n" " UDP Destination Port Number (%s)\n" " Input Port (%s)" % (hex(eth_type), eth_src, eth_dst, ipv4_src, ipv4_dst, ip_proto, ip_dscp, ip_ecn, udp_src_port, udp_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 = 17 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 = 1008) # --- 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)
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() flow_entry.set_flow_name(flow_name = "match=ipv6_src,ipv6_dst;actions=output:Controller") 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)
print "\n" print ("<<< Set OpenFlow flow on the Controller") print (" Match: Input Port (%s)\n" " Ethernet Type (%s)\n" " IPv4 Destination Address (%s)" % (match_in_port, hex(match_ip_eth_type), match_ipv4_dst)) print (" Action: Set IPv4 ToS (tos %s)\n" " Output (Port number %s)" % (mod_nw_tos, 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 = SetNwTosAction(action_order)
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
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) flow_entry1.set_flow_name(flow_name = "[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_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)
rundelay = 5 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)
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() flow_entry.set_flow_name( flow_name="match=ipv6_src,ipv6_dst;actions=output:Controller") 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)
" 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)
" IP DSCP (%s)\n" " IP ECN (%s)\n" " IPv6 Source Address (%s)\n" " IPv6 Destination Address (%s)\n" " IPv6 Flow Label (%s)\n" " IPv6 Extension Header (%s)\n" " TCP Source Port (%s)\n" " TCP Destination Port (%s)\n" " Metadata (%s)" % (hex(eth_type), ip_dscp, ip_ecn, ipv6_src, ipv6_dst, ipv6_flabel, ipv6_exthdr, tcp_src_port, tcp_dst_port, metadata)) print(" Action: Output (to %s)" % output_port) time.sleep(rundelay) flow_entry = FlowEntry() table_id = 0 flow_id = 27 flow_entry.set_flow_table_id(table_id) flow_entry.set_flow_id(flow_id) flow_entry.set_flow_priority(flow_priority=1020) flow_entry.set_flow_cookie(cookie=2100) flow_entry.set_flow_hard_timeout(hard_timeout=1234) flow_entry.set_flow_idle_timeout(idle_timeout=3456) flow_entry.set_flow_strict(False) flow_entry.set_flow_install_hw(False) # --- Instruction: 'Apply-actions' # Actions: 'Output' instruction = Instruction(instruction_order=0) action = OutputAction(order=0, port=output_port)
print ("<<< Set OpenFlow flow on the Controller") print (" Match: Input Port (%s)\n" " Ethernet Type (%s)\n" " IPv4 Destination Address (%s)" % (match_in_port, hex(match_ip_eth_type), match_ipv4_dst)) print (" Action: Set IPv4 ToS (tos %s)\n" " Output (Port number %s)" % (mod_nw_tos, 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 = SetNwTosAction(action_order)
" 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)
" IPv6 Source Address (%s)\n" " IPv6 Destination Address (%s)\n" " IPv6 Flow Label (%s)\n" " IPv6 Extension Header (%s)\n" " TCP Source Port (%s)\n" " TCP Destination Port (%s)\n" " Metadata (%s)" % (hex(eth_type), ip_dscp, ip_ecn, ipv6_src, ipv6_dst, ipv6_flabel, ipv6_exthdr, tcp_src_port, tcp_dst_port, metadata)) print (" Action: Output (to %s)" % (output_port)) time.sleep(rundelay) flow_entry = FlowEntry() table_id = 0 flow_id = 27 flow_entry.set_flow_table_id(table_id) flow_entry.set_flow_id(flow_id) flow_entry.set_flow_priority(flow_priority=1020) flow_entry.set_flow_cookie(cookie=2100) flow_entry.set_flow_hard_timeout(hard_timeout=1234) flow_entry.set_flow_idle_timeout(idle_timeout=3456) flow_entry.set_flow_strict(False) flow_entry.set_flow_install_hw(False) # --- Instruction: 'Apply-actions' # Actions: 'Output' instruction = Instruction(instruction_order=0) action = OutputAction(order=0, port=output_port)
rundelay = 5 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)
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'
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)
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" " UDP Source Port (%s)\n" " UDP Destination Port (%s)" % (hex(eth_type), ipv6_src, ipv6_dst, ip_dscp, udp_src_port, udp_dst_port)) print(" Action: Output (to %s)" % output_port) time.sleep(rundelay) flow_entry = FlowEntry() flow_entry.set_flow_name(flow_name="demo17.py") 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_hard_timeout(0) flow_entry.set_flow_idle_timeout(0) flow_entry.set_flow_priority(flow_priority=1015) # --- 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)
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: Pop MPLS (Ethernet Type %s)\n" " Output (Physical Port number %s)" % (pop_ether_type, output_port)) time.sleep(rundelay) flow_entry = FlowEntry() table_id = 0 flow_id = 30 flow_entry.set_flow_table_id(table_id) flow_entry.set_flow_id(flow_id) flow_entry.set_flow_name(flow_name = "Strip 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 = 1023) flow_entry.set_flow_cookie(cookie = 889) flow_entry.set_flow_cookie_mask(cookie_mask = 255) # --- Instruction: 'Apply-actions' # Actions: 'Pop MPLS Header' # 'Output' instruction = Instruction(instruction_order = 0)
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)
" 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