本文整理汇总了Python中pybvc.openflowdev.ofswitch.Match.set_vlan_id方法的典型用法代码示例。如果您正苦于以下问题:Python Match.set_vlan_id方法的具体用法?Python Match.set_vlan_id怎么用?Python Match.set_vlan_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pybvc.openflowdev.ofswitch.Match
的用法示例。
在下文中一共展示了Match.set_vlan_id方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Instruction
# 需要导入模块: from pybvc.openflowdev.ofswitch import Match [as 别名]
# 或者: from pybvc.openflowdev.ofswitch.Match import set_vlan_id [as 别名]
# Action: 'Output' to port 7
instruction = Instruction(instruction_order = 0)
action = OutputAction(action_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[0]
if(status.eq(STATUS.OK) == True):
print ("<<< Flow successfully added to the Controller")
else:
print ("\n")
print ("!!!Demo terminated, reason: %s" % status.brief().lower())
示例2: of_demo_15
# 需要导入模块: from pybvc.openflowdev.ofswitch import Match [as 别名]
# 或者: from pybvc.openflowdev.ofswitch.Match import set_vlan_id [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()
#.........这里部分代码省略.........
示例3: of_demo_25
# 需要导入模块: from pybvc.openflowdev.ofswitch import Match [as 别名]
# 或者: from pybvc.openflowdev.ofswitch.Match import set_vlan_id [as 别名]
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)
#.........这里部分代码省略.........
示例4: of_demo_26
# 需要导入模块: from pybvc.openflowdev.ofswitch import Match [as 别名]
# 或者: from pybvc.openflowdev.ofswitch.Match import set_vlan_id [as 别名]
#.........这里部分代码省略.........
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)
示例5: PushVlanHeaderAction
# 需要导入模块: from pybvc.openflowdev.ofswitch import Match [as 别名]
# 或者: from pybvc.openflowdev.ofswitch.Match import set_vlan_id [as 别名]
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)
示例6: of_demo_37
# 需要导入模块: from pybvc.openflowdev.ofswitch import Match [as 别名]
# 或者: from pybvc.openflowdev.ofswitch.Match import set_vlan_id [as 别名]
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)
#.........这里部分代码省略.........
示例7: of_demo_13
# 需要导入模块: from pybvc.openflowdev.ofswitch import Match [as 别名]
# 或者: from pybvc.openflowdev.ofswitch.Match import set_vlan_id [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)
#.........这里部分代码省略.........
示例8: SetFieldAction
# 需要导入模块: from pybvc.openflowdev.ofswitch import Match [as 别名]
# 或者: from pybvc.openflowdev.ofswitch.Match import set_vlan_id [as 别名]
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) == True):
print ("<<< Flow successfully added to the Controller")
else:
print ("\n")
print ("!!!Demo terminated, reason: %s" % status.detailed())