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

Conflicts: setup.cfg
Backport from https://github.com/faucetsdn/ryu/commit/98d4913
Story: #2009283
Task: #43617

Change-Id: I583942287b91606642c6df4f448ebe749d391f3c
This commit is contained in:
Josh Bailey
2021-06-06 21:52:17 +00:00
committed by elajkat
parent 2e8cf5bed2
commit f1735c323e
5 changed files with 64 additions and 49 deletions

View File

@@ -298,6 +298,7 @@ class Datapath(ofproto_protocol.ProtocolDesc):
self.state = state
ev = ofp_event.EventOFPStateChange(self)
ev.state = state
if self.ofp_brick is not None:
self.ofp_brick.send_event_to_observers(ev, state)
# Low level socket handling layer
@@ -343,6 +344,7 @@ class Datapath(ofproto_protocol.ProtocolDesc):
# LOG.debug('queue msg %s cls %s', msg, msg.__class__)
if 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)
def dispatchers(x):

View File

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

View File

@@ -50,7 +50,7 @@ class MacToPortTable(object):
return self.mac_to_port[dpid].get(mac)
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]
def mac_del(self, dpid, mac):

View File

@@ -47,7 +47,7 @@ def register_switch_address(addr, interval=None):
def _retry_loop():
# Delays registration if ofp_handler is not started yet
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():
ofp_handler.controller.spawn_client_loop(a, i)
hub.sleep(1)
@@ -69,6 +69,6 @@ def unregister_switch_address(addr):
"""
ofp_handler = app_manager.lookup_service_brick(ofp_event.NAME)
# 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
ofp_handler.controller.stop_client_loop(addr)

View File

@@ -1755,7 +1755,7 @@ class OFPMatchField(StringifyMixin):
(value, mask) = struct.unpack_from(pack_str, buf, offset + 4)
else:
(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):
if ofproto.oxm_tlv_header_extract_hasmask(self.header):
@@ -2774,6 +2774,7 @@ class OFPFlowMod(MsgBase):
try:
while offset < msg_len:
i = OFPInstruction.parser(buf, offset)
if i is not None:
instructions.append(i)
offset += i.len
except exception.OFPTruncatedMessage as e:
@@ -2806,7 +2807,9 @@ class OFPInstruction(StringifyMixin):
def parser(cls, buf, offset):
(type_, len_) = struct.unpack_from('!HH', buf, offset)
cls_ = cls._INSTRUCTION_TYPES.get(type_)
if cls_ is not None:
return cls_.parser(buf, offset)
return None
@OFPInstruction.register_instruction_type([ofproto.OFPIT_GOTO_TABLE])
@@ -3552,7 +3555,7 @@ class OFPActionExperimenter(OFPAction):
data = buf[(offset + ofproto.OFP_ACTION_EXPERIMENTER_HEADER_SIZE
): offset + len_]
if experimenter == ofproto_common.NX_EXPERIMENTER_ID:
obj = NXAction.parse(data) # noqa
obj = NXAction.parse(data) # pytype: disable=name-error # noqa
else:
obj = OFPActionExperimenterUnknown(experimenter, data)
obj.len = len_
@@ -3933,11 +3936,12 @@ class OFPMultipartReply(MsgBase):
ofproto.OFP_MULTIPART_REPLY_PACK_STR, six.binary_type(buf),
ofproto.OFP_HEADER_SIZE)
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)
msg.type = type_
msg.flags = flags
if stats_type_cls is not None:
offset = ofproto.OFP_MULTIPART_REPLY_SIZE
body = []
while offset < msg_len:
@@ -4578,6 +4582,7 @@ class OFPGroupStats(StringifyMixin):
group_stats = cls(*group)
group_stats.bucket_stats = []
if group_stats.length is not None:
total_len = group_stats.length + offset
offset += ofproto.OFP_GROUP_STATS_SIZE
while total_len > offset:
@@ -5771,7 +5776,7 @@ class ONFFlowMonitorRequest(StringifyMixin):
match_len = match.length
match_hdr_len = ofproto.OFP_MATCH_SIZE - 4 # exclude pad[4]
# 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)
buf = bytearray()
@@ -5937,6 +5942,7 @@ class OFPQueueProp(OFPQueuePropHeader):
ofproto.OFP_QUEUE_PROP_HEADER_PACK_STR,
buf, offset)
cls_ = cls._QUEUE_PROP_PROPERTIES.get(property_)
if cls_ is not None:
p = cls_.parser(buf, offset + ofproto.OFP_QUEUE_PROP_HEADER_SIZE)
p.property = property_
p.len = len_
@@ -5945,6 +5951,7 @@ class OFPQueueProp(OFPQueuePropHeader):
offset + len_]
p.parse_experimenter_data(rest)
return p
return None
@OFPQueueProp.register_property(ofproto.OFPQT_MIN_RATE,
@@ -6018,6 +6025,7 @@ class OFPPacketQueue(StringifyMixin):
properties = []
while length < len_:
queue_prop = OFPQueueProp.parser(buf, offset)
if queue_prop is not None:
properties.append(queue_prop)
offset += queue_prop.len
length += queue_prop.len
@@ -6343,6 +6351,10 @@ class OFPSetAsync(MsgBase):
self.flow_removed_mask[0], self.flow_removed_mask[1])
class OFPBundleProp(OFPPropBase):
_TYPES = {}
@_register_exp_type(ofproto_common.ONF_EXPERIMENTER_ID,
ofproto.ONF_ET_BUNDLE_CONTROL)
class ONFBundleCtrlMsg(OFPExperimenter):