add ofproto 1.3 coverage, check key-error and attribute-error.

This commit is contained in:
Josh Bailey 2021-06-06 21:52:17 +00:00
parent 34f33491ff
commit 98d4913d32
6 changed files with 65 additions and 51 deletions

View File

@ -317,6 +317,7 @@ class Datapath(ofproto_protocol.ProtocolDesc):
self.state = state self.state = state
ev = ofp_event.EventOFPStateChange(self) ev = ofp_event.EventOFPStateChange(self)
ev.state = state ev.state = state
if self.ofp_brick is not None:
self.ofp_brick.send_event_to_observers(ev, state) self.ofp_brick.send_event_to_observers(ev, state)
# Low level socket handling layer # Low level socket handling layer
@ -362,6 +363,7 @@ class Datapath(ofproto_protocol.ProtocolDesc):
# LOG.debug('queue msg %s cls %s', msg, msg.__class__) # LOG.debug('queue msg %s cls %s', msg, msg.__class__)
if msg: if msg:
ev = ofp_event.ofp_msg_to_ev(msg) ev = ofp_event.ofp_msg_to_ev(msg)
if self.ofp_brick is not None:
self.ofp_brick.send_event_to_observers(ev, self.state) self.ofp_brick.send_event_to_observers(ev, self.state)
def dispatchers(x): def dispatchers(x):

View File

@ -149,6 +149,7 @@ def register_service(service):
there are applications consuming OFP events. there are applications consuming OFP events.
""" """
frame = inspect.currentframe() frame = inspect.currentframe()
if frame is not None:
m_name = frame.f_back.f_globals['__name__'] m_name = frame.f_back.f_globals['__name__']
m = sys.modules[m_name] m = sys.modules[m_name]
m._SERVICE_NAME = service m._SERVICE_NAME = service

View File

@ -50,7 +50,7 @@ class MacToPortTable(object):
return self.mac_to_port[dpid].get(mac) return self.mac_to_port[dpid].get(mac)
def mac_list(self, dpid, port): def mac_list(self, dpid, port):
return [mac for (mac, port_) in self.mac_to_port.get(dpid).items() return [mac for (mac, port_) in self.mac_to_port.get(dpid, {}).items()
if port_ == port] if port_ == port]
def mac_del(self, dpid, mac): def mac_del(self, dpid, mac):

View File

@ -47,7 +47,7 @@ def register_switch_address(addr, interval=None):
def _retry_loop(): def _retry_loop():
# Delays registration if ofp_handler is not started yet # Delays registration if ofp_handler is not started yet
while True: while True:
if ofp_handler.controller is not None: if ofp_handler is not None and ofp_handler.controller is not None:
for a, i in _TMP_ADDRESSES.items(): for a, i in _TMP_ADDRESSES.items():
ofp_handler.controller.spawn_client_loop(a, i) ofp_handler.controller.spawn_client_loop(a, i)
hub.sleep(1) hub.sleep(1)
@ -69,6 +69,6 @@ def unregister_switch_address(addr):
""" """
ofp_handler = app_manager.lookup_service_brick(ofp_event.NAME) ofp_handler = app_manager.lookup_service_brick(ofp_event.NAME)
# Do nothing if ofp_handler is not started yet # Do nothing if ofp_handler is not started yet
if ofp_handler.controller is None: if ofp_handler is None or ofp_handler.controller is None:
return return
ofp_handler.controller.stop_client_loop(addr) ofp_handler.controller.stop_client_loop(addr)

View File

@ -1754,7 +1754,7 @@ class OFPMatchField(StringifyMixin):
(value, mask) = struct.unpack_from(pack_str, buf, offset + 4) (value, mask) = struct.unpack_from(pack_str, buf, offset + 4)
else: else:
(value,) = struct.unpack_from(cls.pack_str, buf, offset + 4) (value,) = struct.unpack_from(cls.pack_str, buf, offset + 4)
return cls(header, value, mask) return cls(header, value, mask) # pytype: disable=wrong-arg-count
def serialize(self, buf, offset): def serialize(self, buf, offset):
if ofproto.oxm_tlv_header_extract_hasmask(self.header): if ofproto.oxm_tlv_header_extract_hasmask(self.header):
@ -2773,6 +2773,7 @@ class OFPFlowMod(MsgBase):
try: try:
while offset < msg_len: while offset < msg_len:
i = OFPInstruction.parser(buf, offset) i = OFPInstruction.parser(buf, offset)
if i is not None:
instructions.append(i) instructions.append(i)
offset += i.len offset += i.len
except exception.OFPTruncatedMessage as e: except exception.OFPTruncatedMessage as e:
@ -2805,7 +2806,9 @@ class OFPInstruction(StringifyMixin):
def parser(cls, buf, offset): def parser(cls, buf, offset):
(type_, len_) = struct.unpack_from('!HH', buf, offset) (type_, len_) = struct.unpack_from('!HH', buf, offset)
cls_ = cls._INSTRUCTION_TYPES.get(type_) cls_ = cls._INSTRUCTION_TYPES.get(type_)
if cls_ is not None:
return cls_.parser(buf, offset) return cls_.parser(buf, offset)
return None
@OFPInstruction.register_instruction_type([ofproto.OFPIT_GOTO_TABLE]) @OFPInstruction.register_instruction_type([ofproto.OFPIT_GOTO_TABLE])
@ -3551,7 +3554,7 @@ class OFPActionExperimenter(OFPAction):
data = buf[(offset + ofproto.OFP_ACTION_EXPERIMENTER_HEADER_SIZE data = buf[(offset + ofproto.OFP_ACTION_EXPERIMENTER_HEADER_SIZE
): offset + len_] ): offset + len_]
if experimenter == ofproto_common.NX_EXPERIMENTER_ID: if experimenter == ofproto_common.NX_EXPERIMENTER_ID:
obj = NXAction.parse(data) # noqa obj = NXAction.parse(data) # pytype: disable=name-error # noqa
else: else:
obj = OFPActionExperimenterUnknown(experimenter, data) obj = OFPActionExperimenterUnknown(experimenter, data)
obj.len = len_ obj.len = len_
@ -3932,11 +3935,12 @@ class OFPMultipartReply(MsgBase):
ofproto.OFP_MULTIPART_REPLY_PACK_STR, six.binary_type(buf), ofproto.OFP_MULTIPART_REPLY_PACK_STR, six.binary_type(buf),
ofproto.OFP_HEADER_SIZE) ofproto.OFP_HEADER_SIZE)
stats_type_cls = cls._STATS_MSG_TYPES.get(type_) stats_type_cls = cls._STATS_MSG_TYPES.get(type_)
msg = super(OFPMultipartReply, stats_type_cls).parser( msg = super(OFPMultipartReply, stats_type_cls).parser( # pytype: disable=attribute-error
datapath, version, msg_type, msg_len, xid, buf) datapath, version, msg_type, msg_len, xid, buf)
msg.type = type_ msg.type = type_
msg.flags = flags msg.flags = flags
if stats_type_cls is not None:
offset = ofproto.OFP_MULTIPART_REPLY_SIZE offset = ofproto.OFP_MULTIPART_REPLY_SIZE
body = [] body = []
while offset < msg_len: while offset < msg_len:
@ -4577,6 +4581,7 @@ class OFPGroupStats(StringifyMixin):
group_stats = cls(*group) group_stats = cls(*group)
group_stats.bucket_stats = [] group_stats.bucket_stats = []
if group_stats.length is not None:
total_len = group_stats.length + offset total_len = group_stats.length + offset
offset += ofproto.OFP_GROUP_STATS_SIZE offset += ofproto.OFP_GROUP_STATS_SIZE
while total_len > offset: while total_len > offset:
@ -5770,7 +5775,7 @@ class ONFFlowMonitorRequest(StringifyMixin):
match_len = match.length match_len = match.length
match_hdr_len = ofproto.OFP_MATCH_SIZE - 4 # exclude pad[4] match_hdr_len = ofproto.OFP_MATCH_SIZE - 4 # exclude pad[4]
# strip ofp_match header and trailing padding # strip ofp_match header and trailing padding
bin_match = bytes(bin_match)[match_hdr_len:match_len] bin_match = bytearray(bin_match)[match_hdr_len:match_len]
self.match_len = len(bin_match) self.match_len = len(bin_match)
buf = bytearray() buf = bytearray()
@ -5936,6 +5941,7 @@ class OFPQueueProp(OFPQueuePropHeader):
ofproto.OFP_QUEUE_PROP_HEADER_PACK_STR, ofproto.OFP_QUEUE_PROP_HEADER_PACK_STR,
buf, offset) buf, offset)
cls_ = cls._QUEUE_PROP_PROPERTIES.get(property_) cls_ = cls._QUEUE_PROP_PROPERTIES.get(property_)
if cls_ is not None:
p = cls_.parser(buf, offset + ofproto.OFP_QUEUE_PROP_HEADER_SIZE) p = cls_.parser(buf, offset + ofproto.OFP_QUEUE_PROP_HEADER_SIZE)
p.property = property_ p.property = property_
p.len = len_ p.len = len_
@ -5944,6 +5950,7 @@ class OFPQueueProp(OFPQueuePropHeader):
offset + len_] offset + len_]
p.parse_experimenter_data(rest) p.parse_experimenter_data(rest)
return p return p
return None
@OFPQueueProp.register_property(ofproto.OFPQT_MIN_RATE, @OFPQueueProp.register_property(ofproto.OFPQT_MIN_RATE,
@ -6017,6 +6024,7 @@ class OFPPacketQueue(StringifyMixin):
properties = [] properties = []
while length < len_: while length < len_:
queue_prop = OFPQueueProp.parser(buf, offset) queue_prop = OFPQueueProp.parser(buf, offset)
if queue_prop is not None:
properties.append(queue_prop) properties.append(queue_prop)
offset += queue_prop.len offset += queue_prop.len
length += queue_prop.len length += queue_prop.len
@ -6342,6 +6350,10 @@ class OFPSetAsync(MsgBase):
self.flow_removed_mask[0], self.flow_removed_mask[1]) self.flow_removed_mask[0], self.flow_removed_mask[1])
class OFPBundleProp(OFPPropBase):
_TYPES = {}
@_register_exp_type(ofproto_common.ONF_EXPERIMENTER_ID, @_register_exp_type(ofproto_common.ONF_EXPERIMENTER_ID,
ofproto.ONF_ET_BUNDLE_CONTROL) ofproto.ONF_ET_BUNDLE_CONTROL)
class ONFBundleCtrlMsg(OFPExperimenter): class ONFBundleCtrlMsg(OFPExperimenter):

View File

@ -59,10 +59,9 @@ console_scripts =
[pytype] [pytype]
inputs = inputs =
ryu/controller/ ryu/controller/
ryu/ofproto/ofproto_v1_3*
disable = disable =
attribute-error
import-error import-error
key-error
module-attr module-attr
keep-going = keep-going =
1 1