本文整理汇总了Python中pybvc.openflowdev.ofswitch.FlowEntry.get_payload方法的典型用法代码示例。如果您正苦于以下问题:Python FlowEntry.get_payload方法的具体用法?Python FlowEntry.get_payload怎么用?Python FlowEntry.get_payload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pybvc.openflowdev.ofswitch.FlowEntry
的用法示例。
在下文中一共展示了FlowEntry.get_payload方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: of_demo_11
# 需要导入模块: from pybvc.openflowdev.ofswitch import FlowEntry [as 别名]
# 或者: from pybvc.openflowdev.ofswitch.FlowEntry import get_payload [as 别名]
#.........这里部分代码省略.........
" 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 (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
示例2: of_demo_40
# 需要导入模块: from pybvc.openflowdev.ofswitch import FlowEntry [as 别名]
# 或者: from pybvc.openflowdev.ofswitch.FlowEntry import get_payload [as 别名]
#.........这里部分代码省略.........
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
示例3: of_demo_15
# 需要导入模块: from pybvc.openflowdev.ofswitch import FlowEntry [as 别名]
# 或者: from pybvc.openflowdev.ofswitch.FlowEntry import get_payload [as 别名]
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()
#.........这里部分代码省略.........
示例4: origApp
# 需要导入模块: from pybvc.openflowdev.ofswitch import FlowEntry [as 别名]
# 或者: from pybvc.openflowdev.ofswitch.FlowEntry import get_payload [as 别名]
#.........这里部分代码省略.........
print ("!!!Demo terminated, reason: %s" % status.brief().lower())
exit(0)
idx = mktime(gmtime(0))
for n in nodenames:
ofswitch = OFSwitch(ctrl, n)
# --- Flow Match:
# IPv4 Source Address
# IPv4 Destination Address
# NOTE: Ethernet type MUST be 2048 (0x800) -> IPv4 protocol
eth_type = ETH_TYPE_IPv4
ipv4_src = srcIp
ipv4_dst = destIp
print ("<<< 'Controller': %s, 'OpenFlow' switch: '%s'" % (ctrlIpAddr, n))
print "\n"
print ("<<< Set OpenFlow flow on the Controller")
print (
" Match: Ethernet Type (%s)\n"
" IPv4 Source Address (%s)\n"
" IPv4 Destination Address (%s)\n" % (hex(eth_type), ipv4_src, ipv4_dst)
)
print (" Action: Output (NORMAL)")
time.sleep(rundelay)
for i in range(0, 2):
flow_entry = FlowEntry()
table_id = 0
flow_entry.set_flow_table_id(table_id)
flow_id = 16 + idx
idx = idx + 1
flow_entry.set_flow_id(flow_id)
flow_entry.set_flow_priority(flow_priority=1007)
# --- 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)
if i == 0:
match.set_ipv4_src(ipv4_src)
match.set_ipv4_dst(ipv4_dst)
else:
match.set_ipv4_src(ipv4_dst)
match.set_ipv4_dst(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) == True:
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) == True:
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 (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
print (">>> Demo End")
print (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
示例5: of_demo_8
# 需要导入模块: from pybvc.openflowdev.ofswitch import FlowEntry [as 别名]
# 或者: from pybvc.openflowdev.ofswitch.FlowEntry import get_payload [as 别名]
#.........这里部分代码省略.........
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 (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
示例6: of_demo_12
# 需要导入模块: from pybvc.openflowdev.ofswitch import FlowEntry [as 别名]
# 或者: from pybvc.openflowdev.ofswitch.FlowEntry import get_payload [as 别名]
#.........这里部分代码省略.........
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 (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
示例7: print
# 需要导入模块: from pybvc.openflowdev.ofswitch import FlowEntry [as 别名]
# 或者: from pybvc.openflowdev.ofswitch.FlowEntry import get_payload [as 别名]
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) == True):
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)
示例8: of_demo_37
# 需要导入模块: from pybvc.openflowdev.ofswitch import FlowEntry [as 别名]
# 或者: from pybvc.openflowdev.ofswitch.FlowEntry import get_payload [as 别名]
#.........这里部分代码省略.........
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"
示例9: of_demo_38
# 需要导入模块: from pybvc.openflowdev.ofswitch import FlowEntry [as 别名]
# 或者: from pybvc.openflowdev.ofswitch.FlowEntry import get_payload [as 别名]
#.........这里部分代码省略.........
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"
示例10: of_demo_13
# 需要导入模块: from pybvc.openflowdev.ofswitch import FlowEntry [as 别名]
# 或者: from pybvc.openflowdev.ofswitch.FlowEntry import get_payload [as 别名]
def of_demo_13():
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 13 Start")
print ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
ctrl = Controller(ctrlIpAddr, ctrlPortNum, ctrlUname, ctrlPswd)
ofswitch = OFSwitch(ctrl, nodeName)
# --- Flow Match: Ethernet Type
# Ethernet Source Address
# Ethernet Destination Address
# VLAN ID
# VLAN PCP
eth_type = ETH_TYPE_IPv4
eth_src = "00:00:00:11:23:ad"
eth_dst = "00:ff:29:01:19:61"
vlan_id = 100
vlan_pcp = PCP_CA # 'Critical Applications' (priority 3)
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"
" VLAN ID (%s)\n"
" VLAN PCP(%s)"
% (hex(eth_type), eth_src,
eth_dst, vlan_id, vlan_pcp))
print (" Action: Output (to Physical Port Number)")
time.sleep(rundelay)
flow_entry = FlowEntry()
table_id = 0
flow_entry.set_flow_table_id(table_id)
flow_id = 20
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(1011)
# --- Instruction: 'Apply-actions'
# Action: 'Output' to port 7
instruction = Instruction(instruction_order=0)
action = OutputAction(order=0, port=7)
instruction.add_apply_action(action)
flow_entry.add_instruction(instruction)
# --- Match Fields: Ethernet Type
# Ethernet Source Address
# Ethernet Destination Address
# VLAN ID
# VLAN PCP
match = Match()
match.set_eth_type(eth_type)
match.set_eth_src(eth_src)
match.set_eth_dst(eth_dst)
match.set_vlan_id(vlan_id)
match.set_vlan_pcp(vlan_pcp)
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)
#.........这里部分代码省略.........
示例11: of_demo_36
# 需要导入模块: from pybvc.openflowdev.ofswitch import FlowEntry [as 别名]
# 或者: from pybvc.openflowdev.ofswitch.FlowEntry import get_payload [as 别名]
#.........这里部分代码省略.........
# 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:")
示例12: of_demo_20
# 需要导入模块: from pybvc.openflowdev.ofswitch import FlowEntry [as 别名]
# 或者: from pybvc.openflowdev.ofswitch.FlowEntry import get_payload [as 别名]
#.........这里部分代码省略.........
" 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 (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
示例13: of_demo_43
# 需要导入模块: from pybvc.openflowdev.ofswitch import FlowEntry [as 别名]
# 或者: from pybvc.openflowdev.ofswitch.FlowEntry import get_payload [as 别名]
def of_demo_43():
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 43 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 = "Set Queue example"
priority = 1000
cookie = 1400
match_in_port = 109
match_eth_type = ETH_TYPE_IPv4
match_ipv4_dst_addr = "10.0.0.0/8"
act_queue_id = 7
act_out_port = 112
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_eth_type),
match_ipv4_dst_addr))
print (" Actions: Set Queue (%s)\n"
" Output (%s)" %
(act_queue_id, 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 = SetQueueAction(action_order)
action.set_gueue_id(act_queue_id)
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_dst(match_ipv4_dst_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)
#.........这里部分代码省略.........
示例14: of_demo_42
# 需要导入模块: from pybvc.openflowdev.ofswitch import FlowEntry [as 别名]
# 或者: from pybvc.openflowdev.ofswitch.FlowEntry import get_payload [as 别名]
def of_demo_42():
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 42 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 MPLS TTL example1"
priority = 900
cookie = 1300
match_in_port = 3
match_eth_type = ETH_TYPE_MPLS_UCAST
match_mpls_label = 567
act_mod_mpls_ttl = 2
act_out_port = 112
print "\n"
print ("<<< Set OpenFlow flow on the Controller")
print (
" Match: Input Port (%s)\n"
" Ethernet Type (%s)\n"
" MPLS Label (%s)" % (match_in_port, hex(match_eth_type), match_mpls_label)
)
print (" Actions: Set MPLS TTL (%s)\n" " Output (%s)" % (act_mod_mpls_ttl, 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 = SetMplsTTLAction(action_order)
action.set_ttl(act_mod_mpls_ttl)
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_mpls_label(match_mpls_label)
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:
#.........这里部分代码省略.........
示例15: of_demo_25
# 需要导入模块: from pybvc.openflowdev.ofswitch import FlowEntry [as 别名]
# 或者: from pybvc.openflowdev.ofswitch.FlowEntry import get_payload [as 别名]
#.........这里部分代码省略.........
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