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

Commit 1486700

Browse files
committed
Fixing repeated header XID between same class message instances
Fix #361
1 parent 1eeec4a commit 1486700

3 files changed

Lines changed: 5 additions & 9 deletions

File tree

pyof/foundation/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
from collections import OrderedDict
2323
from copy import deepcopy
2424
from enum import Enum, IntEnum
25+
from random import randint
2526

26-
# Local source tree imports
27+
from pyof.foundation.constants import UBINT32_MAX_VALUE as MAXID
2728
from pyof.foundation.exceptions import (
2829
BadValueException, PackException, UnpackException, ValidationError)
2930

@@ -747,8 +748,7 @@ class GenericMessage(GenericStruct):
747748
def __init__(self, xid=None):
748749
"""Initialize header's xid."""
749750
super().__init__()
750-
if xid is not None:
751-
self.header.xid = xid
751+
self.header.xid = randint(0, MAXID) if xid is None else xid
752752

753753
def __init_subclass__(cls, **kwargs):
754754
if cls.header is None or cls.header.__class__.__name__ != 'Header':

pyof/v0x01/common/header.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22

33
# System imports
44
from enum import IntEnum
5-
from random import randint
65

76
# Local source tree imports
87
from pyof.foundation.base import GenericStruct
98
from pyof.foundation.basic_types import UBInt8, UBInt16, UBInt32
10-
from pyof.foundation.constants import UBINT32_MAX_VALUE as MAXID
119
from pyof.v0x01.common.constants import OFP_VERSION
1210

1311
# Third-party imports
@@ -84,4 +82,4 @@ def __init__(self, message_type=None, length=None, xid=None):
8482
super().__init__()
8583
self.message_type = message_type
8684
self.length = length
87-
self.xid = randint(0, MAXID) if xid is None else xid
85+
self.xid = xid

pyof/v0x04/common/header.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22

33
# System imports
44
from enum import IntEnum
5-
from random import randint
65

76
# Local source tree imports
87
from pyof.foundation.base import GenericStruct
98
from pyof.foundation.basic_types import UBInt8, UBInt16, UBInt32
10-
from pyof.foundation.constants import UBINT32_MAX_VALUE as MAXID
119
from pyof.v0x04.common.constants import OFP_VERSION
1210

1311
# Third-party imports
@@ -90,7 +88,7 @@ class Header(GenericStruct):
9088
length = UBInt16()
9189
xid = UBInt32()
9290

93-
def __init__(self, message_type=None, length=None, xid=randint(0, MAXID)):
91+
def __init__(self, message_type=None, length=None, xid=None):
9492
"""Create a Header with the optional parameters below.
9593
9694
Args:

0 commit comments

Comments
 (0)