parse: remove uses of from module import *
Since there is now both an action class named "vendor" and a message class
named "vendor" they clash when imported into the same namespace.
diff --git a/src/python/of10/parse.py b/src/python/of10/parse.py
index a3421a1..e56b69a 100644
--- a/src/python/of10/parse.py
+++ b/src/python/of10/parse.py
@@ -4,11 +4,11 @@
import sys
import logging
-from message import *
-from error import *
-from action import *
+import message
+import error
+import action
+import cstruct
from action_list import action_list
-from cstruct import *
try:
import scapy.all as scapy
except:
@@ -29,63 +29,63 @@
# These message types are subclassed
msg_type_subclassed = [
- OFPT_STATS_REQUEST,
- OFPT_STATS_REPLY,
- OFPT_ERROR
+ cstruct.OFPT_STATS_REQUEST,
+ cstruct.OFPT_STATS_REPLY,
+ cstruct.OFPT_ERROR
]
# Maps from sub-types to classes
stats_reply_to_class_map = {
- OFPST_DESC : desc_stats_reply,
- OFPST_AGGREGATE : aggregate_stats_reply,
- OFPST_FLOW : flow_stats_reply,
- OFPST_TABLE : table_stats_reply,
- OFPST_PORT : port_stats_reply,
- OFPST_QUEUE : queue_stats_reply
+ cstruct.OFPST_DESC : message.desc_stats_reply,
+ cstruct.OFPST_AGGREGATE : message.aggregate_stats_reply,
+ cstruct.OFPST_FLOW : message.flow_stats_reply,
+ cstruct.OFPST_TABLE : message.table_stats_reply,
+ cstruct.OFPST_PORT : message.port_stats_reply,
+ cstruct.OFPST_QUEUE : message.queue_stats_reply
}
stats_request_to_class_map = {
- OFPST_DESC : desc_stats_request,
- OFPST_AGGREGATE : aggregate_stats_request,
- OFPST_FLOW : flow_stats_request,
- OFPST_TABLE : table_stats_request,
- OFPST_PORT : port_stats_request,
- OFPST_QUEUE : queue_stats_request
+ cstruct.OFPST_DESC : message.desc_stats_request,
+ cstruct.OFPST_AGGREGATE : message.aggregate_stats_request,
+ cstruct.OFPST_FLOW : message.flow_stats_request,
+ cstruct.OFPST_TABLE : message.table_stats_request,
+ cstruct.OFPST_PORT : message.port_stats_request,
+ cstruct.OFPST_QUEUE : message.queue_stats_request
}
error_to_class_map = {
- OFPET_HELLO_FAILED : hello_failed_error_msg,
- OFPET_BAD_REQUEST : bad_request_error_msg,
- OFPET_BAD_ACTION : bad_action_error_msg,
- OFPET_FLOW_MOD_FAILED : flow_mod_failed_error_msg,
- OFPET_PORT_MOD_FAILED : port_mod_failed_error_msg,
- OFPET_QUEUE_OP_FAILED : queue_op_failed_error_msg
+ cstruct.OFPET_HELLO_FAILED : message.hello_failed_error_msg,
+ cstruct.OFPET_BAD_REQUEST : message.bad_request_error_msg,
+ cstruct.OFPET_BAD_ACTION : message.bad_action_error_msg,
+ cstruct.OFPET_FLOW_MOD_FAILED : message.flow_mod_failed_error_msg,
+ cstruct.OFPET_PORT_MOD_FAILED : message.port_mod_failed_error_msg,
+ cstruct.OFPET_QUEUE_OP_FAILED : message.queue_op_failed_error_msg
}
# Map from header type value to the underlieing message class
msg_type_to_class_map = {
- OFPT_HELLO : hello,
- OFPT_ERROR : error,
- OFPT_ECHO_REQUEST : echo_request,
- OFPT_ECHO_REPLY : echo_reply,
- OFPT_VENDOR : vendor,
- OFPT_FEATURES_REQUEST : features_request,
- OFPT_FEATURES_REPLY : features_reply,
- OFPT_GET_CONFIG_REQUEST : get_config_request,
- OFPT_GET_CONFIG_REPLY : get_config_reply,
- OFPT_SET_CONFIG : set_config,
- OFPT_PACKET_IN : packet_in,
- OFPT_FLOW_REMOVED : flow_removed,
- OFPT_PORT_STATUS : port_status,
- OFPT_PACKET_OUT : packet_out,
- OFPT_FLOW_MOD : flow_mod,
- OFPT_PORT_MOD : port_mod,
- OFPT_STATS_REQUEST : stats_request,
- OFPT_STATS_REPLY : stats_reply,
- OFPT_BARRIER_REQUEST : barrier_request,
- OFPT_BARRIER_REPLY : barrier_reply,
- OFPT_QUEUE_GET_CONFIG_REQUEST : queue_get_config_request,
- OFPT_QUEUE_GET_CONFIG_REPLY : queue_get_config_reply
+ cstruct.OFPT_HELLO : message.hello,
+ cstruct.OFPT_ERROR : message.error,
+ cstruct.OFPT_ECHO_REQUEST : message.echo_request,
+ cstruct.OFPT_ECHO_REPLY : message.echo_reply,
+ cstruct.OFPT_VENDOR : message.vendor,
+ cstruct.OFPT_FEATURES_REQUEST : message.features_request,
+ cstruct.OFPT_FEATURES_REPLY : message.features_reply,
+ cstruct.OFPT_GET_CONFIG_REQUEST : message.get_config_request,
+ cstruct.OFPT_GET_CONFIG_REPLY : message.get_config_reply,
+ cstruct.OFPT_SET_CONFIG : message.set_config,
+ cstruct.OFPT_PACKET_IN : message.packet_in,
+ cstruct.OFPT_FLOW_REMOVED : message.flow_removed,
+ cstruct.OFPT_PORT_STATUS : message.port_status,
+ cstruct.OFPT_PACKET_OUT : message.packet_out,
+ cstruct.OFPT_FLOW_MOD : message.flow_mod,
+ cstruct.OFPT_PORT_MOD : message.port_mod,
+ cstruct.OFPT_STATS_REQUEST : message.stats_request,
+ cstruct.OFPT_STATS_REPLY : message.stats_reply,
+ cstruct.OFPT_BARRIER_REQUEST : message.barrier_request,
+ cstruct.OFPT_BARRIER_REPLY : message.barrier_reply,
+ cstruct.OFPT_QUEUE_GET_CONFIG_REQUEST : message.queue_get_config_request,
+ cstruct.OFPT_QUEUE_GET_CONFIG_REPLY : message.queue_get_config_reply
}
def _of_message_to_object(binary_string):
@@ -94,30 +94,30 @@
Appropriately resolves subclasses
"""
- hdr = ofp_header()
+ hdr = message.ofp_header()
hdr.unpack(binary_string)
# FIXME: Add error detection
if not hdr.type in msg_type_subclassed:
return msg_type_to_class_map[hdr.type]()
- if hdr.type == OFPT_STATS_REQUEST:
- sub_hdr = ofp_stats_request()
- sub_hdr.unpack(binary_string[OFP_HEADER_BYTES:])
+ if hdr.type == cstruct.OFPT_STATS_REQUEST:
+ sub_hdr = message.ofp_stats_request()
+ sub_hdr.unpack(binary_string[cstruct.OFP_HEADER_BYTES:])
try:
obj = stats_request_to_class_map[sub_hdr.type]()
except KeyError:
obj = None
return obj
- elif hdr.type == OFPT_STATS_REPLY:
- sub_hdr = ofp_stats_reply()
- sub_hdr.unpack(binary_string[OFP_HEADER_BYTES:])
+ elif hdr.type == cstruct.OFPT_STATS_REPLY:
+ sub_hdr = message.ofp_stats_reply()
+ sub_hdr.unpack(binary_string[cstruct.OFP_HEADER_BYTES:])
try:
obj = stats_reply_to_class_map[sub_hdr.type]()
except KeyError:
obj = None
return obj
- elif hdr.type == OFPT_ERROR:
- sub_hdr = ofp_error_msg()
- sub_hdr.unpack(binary_string[OFP_HEADER_BYTES:])
+ elif hdr.type == cstruct.OFPT_ERROR:
+ sub_hdr = message.ofp_error_msg()
+ sub_hdr.unpack(binary_string[cstruct.OFP_HEADER_BYTES:])
return error_to_class_map[sub_hdr.type]()
else:
parse_logger.error("Cannot parse pkt to message")
@@ -166,7 +166,7 @@
parse_logger.error("raw packet message parsing not supported")
return None
- hdr = ofp_header()
+ hdr = message.ofp_header()
hdr.unpack(binary_string)
return hdr
@@ -284,60 +284,60 @@
parse_logger.error("packet_to_flow_match: Classify error")
return None
- match = ofp_match()
- match.wildcards = OFPFW_ALL
+ match = cstruct.ofp_match()
+ match.wildcards = cstruct.OFPFW_ALL
#@todo Check if packet is other than L2 format
match.dl_dst = parse_mac(ether.dst)
- match.wildcards &= ~OFPFW_DL_DST
+ match.wildcards &= ~cstruct.OFPFW_DL_DST
match.dl_src = parse_mac(ether.src)
- match.wildcards &= ~OFPFW_DL_SRC
+ match.wildcards &= ~cstruct.OFPFW_DL_SRC
match.dl_type = ether.type
- match.wildcards &= ~OFPFW_DL_TYPE
+ match.wildcards &= ~cstruct.OFPFW_DL_TYPE
if dot1q:
match.dl_vlan = dot1q.vlan
match.dl_vlan_pcp = dot1q.prio
match.dl_type = dot1q.type
else:
- match.dl_vlan = OFP_VLAN_NONE
+ match.dl_vlan = cstruct.OFP_VLAN_NONE
match.dl_vlan_pcp = 0
- match.wildcards &= ~OFPFW_DL_VLAN
- match.wildcards &= ~OFPFW_DL_VLAN_PCP
+ match.wildcards &= ~cstruct.OFPFW_DL_VLAN
+ match.wildcards &= ~cstruct.OFPFW_DL_VLAN_PCP
if ip:
match.nw_src = parse_ip(ip.src)
- match.wildcards &= ~OFPFW_NW_SRC_MASK
+ match.wildcards &= ~cstruct.OFPFW_NW_SRC_MASK
match.nw_dst = parse_ip(ip.dst)
- match.wildcards &= ~OFPFW_NW_DST_MASK
+ match.wildcards &= ~cstruct.OFPFW_NW_DST_MASK
match.nw_tos = ip.tos
- match.wildcards &= ~OFPFW_NW_TOS
+ match.wildcards &= ~cstruct.OFPFW_NW_TOS
if tcp:
match.nw_proto = 6
- match.wildcards &= ~OFPFW_NW_PROTO
+ match.wildcards &= ~cstruct.OFPFW_NW_PROTO
elif not tcp and udp:
tcp = udp
match.nw_proto = 17
- match.wildcards &= ~OFPFW_NW_PROTO
+ match.wildcards &= ~cstruct.OFPFW_NW_PROTO
if tcp:
match.tp_src = tcp.sport
- match.wildcards &= ~OFPFW_TP_SRC
+ match.wildcards &= ~cstruct.OFPFW_TP_SRC
match.tp_dst = tcp.dport
- match.wildcards &= ~OFPFW_TP_DST
+ match.wildcards &= ~cstruct.OFPFW_TP_DST
if icmp:
match.nw_proto = 1
match.tp_src = icmp.type
match.tp_dst = icmp.code
- match.wildcards &= ~OFPFW_NW_PROTO
+ match.wildcards &= ~cstruct.OFPFW_NW_PROTO
if arp:
match.nw_proto = arp.op
- match.wildcards &= ~OFPFW_NW_PROTO
+ match.wildcards &= ~cstruct.OFPFW_NW_PROTO
match.nw_src = parse_ip(arp.psrc)
- match.wildcards &= ~OFPFW_NW_SRC_MASK
+ match.wildcards &= ~cstruct.OFPFW_NW_SRC_MASK
match.nw_dst = parse_ip(arp.pdst)
- match.wildcards &= ~OFPFW_NW_DST_MASK
+ match.wildcards &= ~cstruct.OFPFW_NW_DST_MASK
return match