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

Commit 384c848

Browse files
authored
Merge pull request #487 from renanrodrigo/fix_actionsetfield_length
Fix Actions get_size method
2 parents 3643f6a + 4ca834d commit 384c848

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

pyof/v0x04/common/action.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Defines actions that may be associated with flows packets."""
22
# System imports
33
from enum import IntEnum
4+
from math import ceil
45

56
# Local source tree imports
67
from pyof.foundation.base import GenericStruct
@@ -107,6 +108,15 @@ def __init__(self, action_type=None, length=None):
107108
self.action_type = action_type
108109
self.length = length
109110

111+
def get_size(self, value=None):
112+
"""Return the action length including the padding (multiple of 8)."""
113+
if isinstance(value, ActionHeader):
114+
return value.get_size()
115+
elif value is None:
116+
current_size = super().get_size()
117+
return ceil(current_size / 8) * 8
118+
raise ValueError(f'Invalid value "{value}" for Action*.get_size()')
119+
110120
def unpack(self, buff, offset=0):
111121
"""Unpack a binary message into this object's attributes.
112122

0 commit comments

Comments
 (0)