Skip to content
This repository was archived by the owner on Apr 22, 2024. It is now read-only.

Commit f92a11c

Browse files
authored
Merge pull request #443 from renanrodrigo/fix_inits
Fix inits
2 parents 09f25c4 + 7ad69c9 commit f92a11c

4 files changed

Lines changed: 19 additions & 14 deletions

File tree

pyof/foundation/base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ def __lshift__(self, shift):
121121
def __rshift__(self, shift):
122122
return self.value >> shift
123123

124+
def __len__(self):
125+
return self.get_size()
126+
124127
@property
125128
def value(self):
126129
"""Return this type's value.

pyof/foundation/network_types.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ class Ethernet(GenericStruct):
201201
ether_type = UBInt16()
202202
data = BinaryData()
203203

204-
def __init__(self, destination=None, source=None, vlan=VLAN(),
204+
def __init__(self, destination=None, source=None, vlan=None,
205205
ether_type=None, data=b''):
206206
"""Create an instance and set its attributes.
207207
@@ -218,7 +218,7 @@ def __init__(self, destination=None, source=None, vlan=VLAN(),
218218
super().__init__()
219219
self.destination = destination
220220
self.source = source
221-
self.vlan = vlan
221+
self.vlan = VLAN() if vlan is None else vlan
222222
self.ether_type = ether_type
223223
self.data = data
224224

@@ -271,7 +271,7 @@ class GenericTLV(GenericStruct):
271271
type and value.
272272
"""
273273

274-
def __init__(self, tlv_type=127, value=BinaryData()):
274+
def __init__(self, tlv_type=127, value=None):
275275
"""Create an instance and set its attributes.
276276
277277
Args:
@@ -281,7 +281,7 @@ def __init__(self, tlv_type=127, value=BinaryData()):
281281
"""
282282
super().__init__()
283283
self.tlv_type = tlv_type
284-
self._value = value
284+
self._value = BinaryData() if value is None else value
285285

286286
@property
287287
def value(self):
@@ -547,7 +547,7 @@ class TLVWithSubType(GenericTLV):
547547
:attr:`sub_type` field and a new :attr:`sub_value` field.
548548
"""
549549

550-
def __init__(self, tlv_type=1, sub_type=7, sub_value=BinaryData()):
550+
def __init__(self, tlv_type=1, sub_type=7, sub_value=None):
551551
"""Create an instance and set its attributes.
552552
553553
Args:
@@ -558,7 +558,7 @@ def __init__(self, tlv_type=1, sub_type=7, sub_value=BinaryData()):
558558
"""
559559
super().__init__(tlv_type)
560560
self.sub_type = sub_type
561-
self.sub_value = sub_value
561+
self.sub_value = BinaryData() if sub_value is None else sub_value
562562

563563
@property
564564
def value(self):

pyof/v0x01/controller2switch/common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ class FlowStatsRequest(GenericStruct):
249249
pad = Pad(1)
250250
out_port = UBInt16()
251251

252-
def __init__(self, match=Match(), table_id=0xff, out_port=Port.OFPP_NONE):
252+
def __init__(self, match=None, table_id=0xff, out_port=Port.OFPP_NONE):
253253
"""Create a FlowStatsRequest with the optional parameters below.
254254
255255
Args:
@@ -262,7 +262,7 @@ def __init__(self, match=Match(), table_id=0xff, out_port=Port.OFPP_NONE):
262262
A value of :attr:`.Port.OFPP_NONE` indicates no restriction.
263263
"""
264264
super().__init__()
265-
self.match = match
265+
self.match = Match() if match is None else match
266266
self.table_id = table_id
267267
self.out_port = out_port
268268

pyof/v0x04/controller2switch/common.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ class NextTablesProperty(Property):
468468
next_table_ids = ListOfInstruction()
469469

470470
def __init__(self, property_type=TableFeaturePropType.OFPTFPT_NEXT_TABLES,
471-
next_table_ids=ListOfInstruction()):
471+
next_table_ids=None):
472472
"""Create a NextTablesProperty with the optional parameters below.
473473
474474
Args:
@@ -478,7 +478,8 @@ def __init__(self, property_type=TableFeaturePropType.OFPTFPT_NEXT_TABLES,
478478
List of InstructionGotoTable instances.
479479
"""
480480
super().__init__(property_type)
481-
self.next_table_ids = next_table_ids
481+
self.next_table_ids = (ListOfInstruction() if next_table_ids is None
482+
else next_table_ids)
482483
self.update_length()
483484

484485

@@ -525,7 +526,7 @@ class OxmProperty(Property):
525526
oxm_ids = ListOfOxmHeader()
526527

527528
def __init__(self, property_type=TableFeaturePropType.OFPTFPT_MATCH,
528-
oxm_ids=ListOfOxmHeader()):
529+
oxm_ids=None):
529530
"""Create an OxmProperty with the optional parameters below.
530531
531532
Args:
@@ -535,7 +536,7 @@ def __init__(self, property_type=TableFeaturePropType.OFPTFPT_MATCH,
535536
List of OxmHeader instances.
536537
"""
537538
super().__init__(property_type)
538-
self.oxm_ids = oxm_ids
539+
self.oxm_ids = ListOfOxmHeader() if oxm_ids is None else oxm_ids
539540
self.update_length()
540541

541542

@@ -583,7 +584,7 @@ def __init__(self, table_id=Table.OFPTT_ALL, name="",
583584
metadata_write=0xFFFFFFFFFFFFFFFF,
584585
config=0,
585586
max_entries=0,
586-
properties=ListOfProperty()):
587+
properties=None):
587588
"""Create a TableFeatures with the optional parameters below.
588589
589590
Args:
@@ -611,7 +612,8 @@ def __init__(self, table_id=Table.OFPTT_ALL, name="",
611612
self.metadata_write = metadata_write
612613
self.config = config
613614
self.max_entries = max_entries
614-
self.properties = properties
615+
self.properties = (ListOfProperty() if properties is None else
616+
properties)
615617
self.update_length()
616618

617619
def pack(self, value=None):

0 commit comments

Comments
 (0)