OXM/OXS: Enable to sort Experimenter oxm_type/oxs_type in Python3

The representation of oxm_type/oxs_type is an int type value if
OXM/OXS in OpenFlowBasic class, but a tuple type value if in
Experimenter class.
So, Python3 may fail to sort a list of OXM/OXS fields by using
oxm_type/oxs_type.
This patch adds 'key' parameter into sort() method and enables to
sort a list which contains both OpenFlowBasic and Experimenter.

Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
Yusuke Iwase 2015-09-17 16:30:22 +09:00 committed by FUJITA Tomonori
parent 1d1777c891
commit be5b00996d
4 changed files with 12 additions and 6 deletions

View File

@ -3428,7 +3428,8 @@ class OFPMatch(StringifyMixin):
in kwargs.items()]
# assumption: sorting by OXM type values makes fields
# meet ordering requirements (eg. eth_type before ipv4_src)
fields.sort()
fields.sort(
key=lambda x: x[0][0] if isinstance(x[0], tuple) else x[0])
self._fields2 = [ofproto.oxm_to_user(n, v, m) for (n, v, m)
in fields]

View File

@ -832,7 +832,8 @@ class OFPMatch(StringifyMixin):
in kwargs.items()]
# assumption: sorting by OXM type values makes fields
# meet ordering requirements (eg. eth_type before ipv4_src)
fields.sort()
fields.sort(
key=lambda x: x[0][0] if isinstance(x[0], tuple) else x[0])
self._fields2 = [ofproto.oxm_to_user(n, v, m) for (n, v, m)
in fields]

View File

@ -716,7 +716,8 @@ class OFPMatch(StringifyMixin):
in kwargs.items()]
# assumption: sorting by OXM type values makes fields
# meet ordering requirements (eg. eth_type before ipv4_src)
fields.sort()
fields.sort(
key=lambda x: x[0][0] if isinstance(x[0], tuple) else x[0])
self._fields2 = [ofproto.oxm_to_user(n, v, m) for (n, v, m)
in fields]

View File

@ -717,7 +717,8 @@ class OFPMatch(StringifyMixin):
in kwargs.items()]
# assumption: sorting by OXM type values makes fields
# meet ordering requirements (eg. eth_type before ipv4_src)
fields.sort()
fields.sort(
key=lambda x: x[0][0] if isinstance(x[0], tuple) else x[0])
self._fields2 = [ofproto.oxm_to_user(n, v, m) for (n, v, m)
in fields]
@ -859,7 +860,8 @@ class OFPStats(StringifyMixin):
fields = [ofproto.oxs_from_user(k, v) for (k, v)
in kwargs.items()]
# sort by OXS type values
fields.sort()
fields.sort(
key=lambda x: x[0][0] if isinstance(x[0], tuple) else x[0])
# No mask
self.fields = [ofproto.oxs_to_user(n, v, None) for (n, v, _)
in fields]
@ -2231,7 +2233,8 @@ class OFPTableFeaturePropOxmValues(OFPTableFeatureProp):
in kwargs.items()]
# assumption: sorting by OXM type values makes fields
# meet ordering requirements (eg. eth_type before ipv4_src)
values.sort()
values.sort(
key=lambda x: x[0][0] if isinstance(x[0], tuple) else x[0])
self.oxm_values = [ofproto.oxm_to_user(n, v, m) for (n, v, m)
in values]