本文整理汇总了Python中testutils.flow_msg_create函数的典型用法代码示例。如果您正苦于以下问题:Python flow_msg_create函数的具体用法?Python flow_msg_create怎么用?Python flow_msg_create使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了flow_msg_create函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: runTest
def runTest(self):
ing_port = flow_mods_port_map.keys()[0]
out_port1 = flow_mods_port_map.keys()[1]
out_port2 = flow_mods_port_map.keys()[2]
pkt = testutils.simple_tcp_packet()
testutils.delete_all_flows(self.controller, self.logger)
fm_orig = testutils.flow_msg_create(self, pkt,
ing_port=ing_port,
egr_port=out_port1)
fm_new = testutils.flow_msg_create(self, pkt,
ing_port=ing_port,
egr_port=out_port2)
fm_new.command = ofp.OFPFC_MODIFY_STRICT
rv = self.controller.message_send(fm_orig)
self.assertEqual(rv, 0, "Failed to insert 1st flow_mod")
testutils.do_barrier(self.controller)
rv = self.controller.message_send(fm_new)
testutils.do_barrier(self.controller)
self.assertEqual(rv, 0, "Failed to insert 2nd flow_mod")
flow_stats = testutils.flow_stats_get(self)
self.assertEqual(len(flow_stats.stats),1,
"Expected only one flow_mod")
stat = flow_stats.stats[0]
self.assertEqual(stat.match, fm_new.match)
self.assertEqual(stat.instructions, fm_new.instructions)
示例2: runTest
def runTest(self):
table_id = testutils.EX_L2_TABLE
of_ports = exact_port_map.keys()
egr_port = of_ports[0]
pkt = testutils.simple_tcp_packet(dl_src='22:22:22:22:22:22', dl_dst='22:22:22:22:22:22')
pkt_metadata = {'metadata_val':0x1122334455667788,
'metadata_msk':0xFFFFFFFFFFFFFFFF}
request = testutils.flow_msg_create(self, pkt, pkt_metadata, egr_port = egr_port, table_id = table_id)
testutils.flow_msg_install(self, request)
#"delete it"
request_del = testutils.flow_msg_create(self, pkt, match_fields = request.match_fields, egr_port = egr_port, table_id = table_id)
request_del.command = ofp.OFPFC_DELETE
testutils.ofmsg_send(self, request_del)
#'read it back , returns blank;'
stat_req = message.flow_stats_request()
stat_req.buffer_id = 0xffffffff
stat_req.table_id = table_id
stat_req.out_port = ofp.OFPP_ANY
stat_req.out_group = ofp.OFPG_ANY
stat_req.match_fields = request.match_fields
response, _ = self.controller.transact(stat_req, timeout=2)
self.assertTrue(isinstance(response,message.flow_stats_reply),"Not a flow_stats_reply")
self.assertEqual(len(response.stats),0, "len of stats is:"+str(len(response.stats)))
示例3: runTest
def runTest(self):
basic_logger.info("Running TableStats")
testutils.delete_all_flows(self.controller, self.logger)
basic_logger.info("Sending table stats request")
request = message.table_stats_request()
response, _ = self.controller.transact(request, timeout=2)
# delete everything, so there should be no entries
self.assertEqual(self.get_first_table_active_entries(response), 0)
# add two entries to first table
m1 = testutils.match_all_generate()
m1.dl_type = 0x800
m1.wildcards ^= ofp.OFPFW_DL_TYPE
fm1 = testutils.flow_msg_create(self, None, match=m1, egr_port=2)
rv = self.controller.message_send(fm1)
self.assertEqual(rv, 0)
m2 = testutils.match_all_generate()
m2.dl_type = 0x806
m2.wildcards ^= ofp.OFPFW_DL_TYPE
fm2 = testutils.flow_msg_create(self, None, match=m2, egr_port=2)
rv = self.controller.message_send(fm2)
self.assertEqual(rv, 0)
testutils.do_barrier(self.controller)
response, _ = self.controller.transact(request, timeout=2)
self.assertEqual(self.get_first_table_active_entries(response), 2)
示例4: runTest
def runTest(self):
ing_port = flow_mods_port_map.keys()[0]
out_port1 = flow_mods_port_map.keys()[1]
out_port2 = flow_mods_port_map.keys()[2]
pkt = testutils.simple_tcp_packet()
testutils.delete_all_flows(self.controller, self.logger)
fm_orig = testutils.flow_msg_create(self, pkt,
ing_port=ofp.OFPP_ANY,
egr_port=out_port1,
table_id=2)
fm_new = testutils.flow_msg_create(self, pkt,
ing_port=ing_port,
egr_port=out_port2,
table_id=2)
fm_new.command = ofp.OFPFC_MODIFY_STRICT
testutils.ofmsg_send(self, fm_orig)
testutils.ofmsg_send(self, fm_new)
flow_stats = testutils.flow_stats_get(self)
#print(flow_stats.show())
self.assertEqual(len(flow_stats.stats),1,
"Expected only one flow_mod")
#fail to modify and instruction will remain the same
stat = flow_stats.stats[0]
self.assertEqual(stat.match, fm_orig.match)
self.assertEqual(stat.instructions, fm_orig.instructions)
示例5: runTest
def runTest(self):
of_ports = testutils.clear_switch(self, pa_port_map.keys(), pa_logger)
# For making the test simpler...
ing_port = of_ports[0]
egr_port = of_ports[1]
check_expire_tbl0 = False
check_expire_tbl1 = False
# Build the ingress packet
pkt = testutils.simple_tcp_packet(**self.base_pkt_params)
# Set action for the first table
for item_tbl0 in self.start_pkt_params:
tbl0_pkt_params = self.base_pkt_params.copy()
tbl0_pkt_params[item_tbl0] = self.mod_pkt_params[item_tbl0]
act = testutils.action_generate(self, item_tbl0, tbl0_pkt_params)
action_list = [act]
inst_1 = instruction.instruction_apply_actions()
inst_2 = instruction.instruction_goto_table()
inst_2.table_id = 1
inst_list = [inst_1, inst_2]
request0 = testutils.flow_msg_create(self, pkt,
ing_port=ing_port,
instruction_list=inst_list,
action_list=action_list,
check_expire=check_expire_tbl0,
table_id=0)
exp_pkt = testutils.simple_tcp_packet(**tbl0_pkt_params)
request1 = testutils.flow_msg_create(self, exp_pkt,
ing_port=ing_port,
check_expire=check_expire_tbl1,
table_id=1,
egr_port=egr_port)
# Insert two flows
self.logger.debug("Inserting flows: Modify-field: " + item_tbl0)
testutils.flow_msg_install(self, request0)
testutils.flow_msg_install(self, request1)
# Send pkt
self.logger.debug("Send packet: " + str(ing_port) +
" to " + str(egr_port))
self.dataplane.send(ing_port, str(pkt))
#@todo Not all HW supports both pkt and byte counters
#@todo We shouldn't expect the order of coming response..
if check_expire_tbl0:
flow_removed_verify(self, request0, pkt_count=1,
byte_count=pktlen)
if check_expire_tbl1:
flow_removed_verify(self, request1, pkt_count=1,
byte_count=exp_pktlen)
# Receive and verify pkt
testutils.receive_pkt_verify(self, egr_port, exp_pkt)
示例6: runTest
def runTest(self):
"""
** Currently, same scenario with "NoGoto" **
Add four flow entries:
First Table; Match IP Src A; goto Second Table
Second Table; Match IP Src A; send to 1, goto Third Table
Third Table; Match IP Src A; do nothing // match but stop pipeline
Fourth Table; Match IP Src A; send to 2 // not match, just a fake
Then send in 2 packets:
IP A, TCP C; expect out port 1
IP A, TCP B; expect out port 1
"""
of_ports = testutils.clear_switch(self, pa_port_map.keys(), pa_logger)
# Set up first match
testutils.write_goto(self, testutils.WC_ACL_TABLE, testutils.WC_SERV_TABLE)
# Set up second match
testutils.write_goto_output(self, testutils.WC_SERV_TABLE, testutils.EX_L2_TABLE,
of_ports[0], of_ports[2])
# Set up third match, "Empty Instruction"
pkt = testutils.simple_tcp_packet()
request = testutils.flow_msg_create(self, pkt, ing_port = of_ports[2], table_id = testutils.EX_L2_TABLE)
testutils.flow_msg_install(self, request)
# Set up fourth match
testutils.write_output(self, testutils.EX_VLAN_TABLE, of_ports[1])
# Generate a packet matching flow 1, 2, and 3; rcv on port[0]
testutils.reply_check_dp(self, tcp_sport=1234,
ing_port = of_ports[2], egr_port = of_ports[0])
示例7: runTest
def runTest(self):
testutils.clear_switch(self,group_port_map,group_logger)
# self.clear_switch()
group_add_msg = \
create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_INDIRECT, group_id = 1, buckets = [
create_bucket(0, 0, 0, [
create_action(action = ofp.OFPAT_SET_FIELD, tcp_sport = 2000),
create_action(action = ofp.OFPAT_OUTPUT, port = 2)
])
])
self.send_ctrl_exp_noerror(group_add_msg, 'group add')
packet_in = testutils.simple_tcp_packet(tcp_sport=1000)
packet_out = testutils.simple_tcp_packet(tcp_sport=2000)
flow_add_msg = \
testutils.flow_msg_create(self,packet_in,ing_port = 1,action_list = [
create_action(action = ofp.OFPAT_GROUP, group_id = 1)
])
self.send_ctrl_exp_noerror(flow_add_msg, 'flow add')
self.send_data(packet_in, 1)
self.recv_data(2, packet_out)
示例8: runTest
def runTest(self):
of_ports = pa_port_map.keys()
of_ports.sort()
self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
pkt = testutils.simple_tcp_packet()
act_all = action.action_output()
act_all.port = ofp.OFPP_ALL
act_ing = action.action_output()
act_ing.port = ofp.OFPP_IN_PORT
actions = [ act_all, act_ing]
for ingress_port in of_ports:
rv = testutils.delete_all_flows(self.controller, pa_logger)
self.assertEqual(rv, 0, "Failed to delete all flows")
pa_logger.info("Ingress " + str(ingress_port) + " to all ports")
flow_mod = testutils.flow_msg_create(self, pkt,
ing_port=ingress_port,
action_list=actions,
inst_app_flag=testutils.APPLY_ACTIONS_INSTRUCTION
)
pa_logger.info(flow_mod.show())
pa_logger.info("Inserting flow")
testutils.ofmsg_send(self, flow_mod)
pa_logger.info("Sending packet to dp port " + str(ingress_port))
self.dataplane.send(ingress_port, str(pkt))
testutils.receive_pkt_check(self.dataplane, pkt, of_ports, [], self,
pa_logger)
示例9: runTest
def runTest(self):
for of_port in sdn_port_map.keys():
ing_port = of_port
for egr_port in sdn_port_map.keys():
if egr_port != of_port:
break
#egr_port = (i+1) %4 + 1
#print("\ncount: " + str(ing_port))
#print("erg_port : " + str(egr_port) + " ing_port: " + str(ing_port))
self.logger.info("\ncount: " + str(ing_port))
self.logger.info("erg_port : " + str(egr_port) + " ing_port: " + str(ing_port))
pkt = testutils.simple_tcp_packet()
testutils.delete_all_flows(self.controller, self.logger)
request = testutils.flow_msg_create(self, pkt, ing_port = ing_port, egr_port = egr_port,check_expire=True)
request.cookie = random.randint(0,9007199254740992)
request.buffer_id = 0xffffffff
request.hard_timeout = 1000
request.idle_timeout = 1000
rv = self.controller.message_send(request)
self.assertTrue(rv != -1, "Error installing flow mod")
testutils.do_barrier(self.controller)
self.dataplane.send(ing_port, str(pkt))
(rcv_port, rcv_pkt, _) = self.dataplane.poll(timeout=1)
#print("erg_port : " + str(rcv_port) + " pkt: %s" % str(rcv_pkt).encode("hex") )
#print("\n")
self.logger.info("erg_port : " + str(rcv_port) + " pkt: %s" % str(rcv_pkt).encode("hex") )
self.logger.info("\n")
self.assertTrue(rcv_pkt is not None, "Did not receive packet")
示例10: handleFlow
def handleFlow(self, pkttype='TCP'):
of_ports = pa_port_map.keys()
of_ports.sort()
self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
if (pkttype == 'ICMP'):
pkt = testutils.simple_icmp_packet()
table_id = testutils.EX_ICMP_TABLE
else:
pkt = testutils.simple_tcp_packet()
table_id = testutils.WC_ACL_TABLE
for idx in range(len(of_ports)):
rv = testutils.delete_all_flows(self.controller, pa_logger)
self.assertEqual(rv, 0, "Failed to delete all flows")
testutils.set_table_config(self, table_id, ofp.OFPTC_TABLE_MISS_CONTINUE)
ingress_port = of_ports[idx]
egress_port = of_ports[(idx + 1) % len(of_ports)]
pa_logger.info("Ingress " + str(ingress_port) +
" to egress " + str(egress_port))
#controller send flow mod to switch
request = testutils.flow_msg_create(self,pkt, ing_port=ingress_port,
egr_port=egress_port, table_id=table_id)
testutils.flow_msg_install(self, request)
#user send pkt to switch
pa_logger.info("Sending packet to dp port " + str(ingress_port))
self.dataplane.send(ingress_port, str(pkt))
testutils.receive_pkt_verify(self, egress_port, pkt)
示例11: runTest
def runTest(self):
of_ports = ipv6_port_map.keys()
of_ports.sort()
ing_port = of_ports[0]
egr_port = of_ports[2]
table_id = testutils.WC_L3_TABLE
# Remove all entries Add entry match all
rc = testutils.delete_all_flows(self.controller, self.logger)
self.assertEqual(rc, 0, "Failed to delete all flows")
rv = testutils.set_table_config(self, table_id)
self.assertEqual(rv, 0, "Failed to set table config")
# Add entry match
pkt = testutils.simple_ipv6_packet()
request = testutils.flow_msg_create(self, pkt, ing_port = ing_port, egr_port = egr_port, table_id = table_id)
testutils.flow_msg_install(self, request)
#Send packet
self.logger.info("Sending IPv6 packet to " + str(ing_port))
self.logger.debug("Data: " + str(pkt).encode('hex'))
self.dataplane.send(ing_port, str(pkt))
#Receive packet
testutils.receive_pkt_verify(self, egr_port, pkt)
#Remove flows
rc = testutils.delete_all_flows(self.controller, self.logger)
self.assertEqual(rc, 0, "Failed to delete all flows")
示例12: runTest
def runTest(self):
of_ports = pa_port_map.keys()
of_ports.sort()
self.assertTrue(len(of_ports) > 2, "Not enough ports for test")
pkt = testutils.simple_tcp_packet()
for ingress_port in of_ports:
rv = testutils.delete_all_flows(self.controller, pa_logger)
self.assertEqual(rv, 0, "Failed to delete all flows")
pa_logger.info("Ingress " + str(ingress_port) + " to all ports")
actions = []
for egress_port in of_ports:
act = action.action_output()
if egress_port == ingress_port:
act.port = ofp.OFPP_IN_PORT
else:
act.port = egress_port
actions.append(act)
request = testutils.flow_msg_create(self, pkt, ingress_port, action_list=actions)
request.buffer_id = 0xffffffff
# pa_logger.info(request.show())
pa_logger.info("Inserting flow")
rv = self.controller.message_send(request)
self.assertTrue(rv != -1, "Error installing flow mod")
testutils.do_barrier(self.controller)
pa_logger.info("Sending packet to dp port " + str(ingress_port))
self.dataplane.send(ingress_port, str(pkt))
testutils.receive_pkt_check(self.dataplane, pkt, of_ports, [], self,
pa_logger)
示例13: runExpireTest
def runExpireTest(self, idle_timeout=0, hard_timeout=0):
global pa_port_map
of_ports = pa_port_map.keys()
of_ports.sort()
self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
rc = delete_all_flows(self.controller, pa_logger)
self.assertEqual(rc, 0, "Failed to delete all flows")
pkt = simple_tcp_packet()
# match = parse.packet_to_flow_match(pkt)
# match.wildcards &= ~ofp.OFPFW_IN_PORT
# self.assertTrue(match is not None,
# "Could not generate flow match from pkt")
# act = action.action_output()
#
ingress_port = pa_config["base_of_port"]
egress_port = (pa_config["base_of_port"] + 1) % len(of_ports)
pa_logger.info("Ingress " + str(ingress_port) +
" to egress " + str(egress_port))
#
# match.in_port = ingress_port
#
# request = message.flow_mod()
# request.match = match
#
request = testutils.flow_msg_create(self, pkt, ingress_port, egr_port=egress_port, check_expire=True)
request.cookie = random.randint(0,9007199254740992)
request.buffer_id = 0xffffffff
request.idle_timeout = idle_timeout
request.hard_timeout = hard_timeout
request.flags |= ofp.OFPFF_SEND_FLOW_REM
match = request.match
pa_logger.info("Inserting flow")
rv = self.controller.message_send(request)
self.assertTrue(rv != -1, "Error installing flow mod")
do_barrier(self.controller)
(response, _) = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 2)
self.assertTrue(response is not None,
'Did not receive flow removed message ')
self.assertEqual(request.cookie, response.cookie,
'Cookies do not match')
if idle_timeout == 0:
self.assertEqual(ofp.OFPRR_HARD_TIMEOUT, response.reason,
'Flow table entry removal reason is not idle_timeout')
elif hard_timeout == 0:
self.assertEqual(ofp.OFPRR_IDLE_TIMEOUT, response.reason,
'Flow table entry removal reason is not idle_timeout')
self.assertEqual(match, response.match,
'Flow table entry does not match')
示例14: runTest
def runTest(self):
global pa_port_map
of_ports = pa_port_map.keys()
of_ports.sort()
self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
ingress_port = of_ports[0];
egress_port = of_ports[1];
rc = testutils.delete_all_flows(self.controller, pa_logger)
self.assertEqual(rc, 0, "Failed to delete all flows")
#controller send flow_mod to switch
pkt = testutils.simple_tcp_packet()
flow_mod_add = testutils.flow_msg_create(self, pkt, ing_port=ingress_port, egr_port=egress_port, table_id=testutils.EX_ACL_TABLE)
testutils.flow_msg_install(self, flow_mod_add)
#user send pkt to switch, switch transfer to eng_port
pa_logger.info("Sending packet to dp port " +
str(ingress_port))
self.dataplane.send(ingress_port, str(pkt))
(rcv_port, rcv_pkt, _) = self.dataplane.poll(egress_port, timeout=2)
self.assertTrue(rcv_pkt is not None, "Did not receive packet")
pa_logger.debug("Packet len " + str(len(pkt)) + " in on " +
str(rcv_port))
self.assertEqual(rcv_port, egress_port, "Unexpected receive port")
self.assertEqual(str(pkt), str(rcv_pkt),
'Response packet does not match send packet')
#check the stats msg
stat_req = message.flow_stats_request()
stat_req.match_fields = flow_mod_add.match_fields
stat_req.table_id = 0xff
stat_req.out_port = ofp.OFPP_ANY;
stat_req.out_group = ofp.OFPG_ANY;
pa_logger.info("Sending stats request")
testutils.ofmsg_send(self, stat_req)
(response, _) = self.controller.poll(ofp.OFPT_MULTIPART_REPLY, 2)
self.assertTrue(response, "No Flow_stats reply")
#print "YYY: Stats reply is \n%s" % (response.show())
self.assertEqual(len(response.stats), 1, "Did not receive flow stats reply")
self.assertEqual(response.stats[0].packet_count,1)
self.assertEqual(response.stats[0].byte_count,len(rcv_pkt))
示例15: runExpireTest
def runExpireTest(self, idle_timeout=0, hard_timeout=0):
global pa_port_map
of_ports = pa_port_map.keys()
of_ports.sort()
self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
rc = delete_all_flows(self.controller, pa_logger)
self.assertEqual(rc, 0, "Failed to delete all flows")
pkt = simple_tcp_packet()
ingress_port = pa_config["base_of_port"]
egress_port = (pa_config["base_of_port"] + 1) % len(of_ports)
pa_logger.info("Ingress " + str(ingress_port) +
" to egress " + str(egress_port))
request = testutils.flow_msg_create(self, pkt, ing_port=ingress_port, egr_port=egress_port, check_expire=True)
request.cookie = random.randint(0,9007199254740992)
request.buffer_id = 0xffffffff
request.idle_timeout = idle_timeout
request.hard_timeout = hard_timeout
request.flags |= ofp.OFPFF_SEND_FLOW_REM
match_fields = request.match_fields
pa_logger.info("Inserting flow")
testutils.ofmsg_send(self, request)
(response, _) = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 8)
self.assertTrue(response is not None,
'Did not receive flow removed message ')
self.assertEqual(request.cookie, response.cookie,
'Cookies do not match')
if idle_timeout == 0:
self.assertEqual(ofp.OFPRR_HARD_TIMEOUT, response.reason,
'Flow table entry removal reason is not idle_timeout')
elif hard_timeout == 0:
self.assertEqual(ofp.OFPRR_IDLE_TIMEOUT, response.reason,
'Flow table entry removal reason is not idle_timeout')