本文整理汇总了Python中pybvc.openflowdev.ofswitch.Match类的典型用法代码示例。如果您正苦于以下问题:Python Match类的具体用法?Python Match怎么用?Python Match使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Match类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: of_demo_36
#.........这里部分代码省略.........
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)
开发者ID:BillTheBest,项目名称:pybvc,代码行数:67,代码来源:demo36.py
示例2: Instruction
instruction = Instruction(instruction_order = 0)
action = PushVlanHeaderAction(action_order = 0)
action.set_eth_type(eth_type = push_eth_type)
instruction.add_apply_action(action)
action = SetFieldAction(action_order = 1)
action.set_vlan_id(vid = push_vlan_id)
instruction.add_apply_action(action)
action = OutputAction(action_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_eth_src(eth_src)
match.set_eth_dst(eth_dst)
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[0]
if(status.eq(STATUS.OK) == True):
print ("<<< Flow successfully added to the Controller")
开发者ID:jebpublic,项目名称:pybvcsamples,代码行数:31,代码来源:of_flowMatchPhysPort-EthSrcDest_ActVlanPushSetPhysPort.py
示例3: Instruction
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:")
开发者ID:jebpublic,项目名称:pybvcsamples,代码行数:31,代码来源:demo20.py
示例4: of_demo_16
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()
#.........这里部分代码省略.........
开发者ID:BillTheBest,项目名称:pybvc,代码行数:101,代码来源:demo16.py
示例5: of_demo_12
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)
#.........这里部分代码省略.........
开发者ID:BillTheBest,项目名称:pybvc,代码行数:101,代码来源:demo12.py
示例6: of_demo_15
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()
#.........这里部分代码省略.........
开发者ID:BillTheBest,项目名称:pybvc,代码行数:101,代码来源:demo15.py
示例7: OutputAction
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")
开发者ID:jebpublic,项目名称:pybvcsamples,代码行数:31,代码来源:demo11.py
示例8: Instruction
# --- 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)
开发者ID:jebpublic,项目名称:pybvcsamples,代码行数:31,代码来源:demo12.py
示例9: of_demo_23
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)
#.........这里部分代码省略.........
开发者ID:BillTheBest,项目名称:pybvc,代码行数:101,代码来源:demo23.py
示例10: OutputAction
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
# UDP Source Port Number
# UDP 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_ip_ecn(ip_ecn)
match.set_udp_src_port(udp_src_port)
match.set_udp_dst_port(udp_dst_port)
match.set_in_port(in_port = input_port)
flow_entry.add_match(match)
print ("\n")
开发者ID:jebpublic,项目名称:pybvcsamples,代码行数:31,代码来源:demo10.py
示例11: of_demo_6
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))
#.........这里部分代码省略.........
开发者ID:BillTheBest,项目名称:pybvc,代码行数:101,代码来源:demo6.py
示例12: of_demo_38
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)
#.........这里部分代码省略.........
开发者ID:BillTheBest,项目名称:pybvc,代码行数:101,代码来源:demo38.py
示例13: FlowEntry
# 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)
开发者ID:jebpublic,项目名称:pybvcsamples,代码行数:31,代码来源:demo26.py
示例14: of_demo_37
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)
#.........这里部分代码省略.........
开发者ID:BillTheBest,项目名称:pybvc,代码行数:101,代码来源:demo37.py
示例15: Instruction
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) == True):
print ("<<< Flow successfully added to the Controller")
else:
开发者ID:jebpublic,项目名称:pybvcsamples,代码行数:31,代码来源:demo15.py
示例16: of_demo_9
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)
#.........这里部分代码省略.........
开发者ID:BillTheBest,项目名称:pybvc,代码行数:101,代码来源:demo9.py
|
请发表评论