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

Commit

Permalink
[v0x02] Updated Header version
Browse files Browse the repository at this point in the history
  • Loading branch information
cemsbr committed Aug 31, 2016
1 parent 987b3fb commit 1634da3
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 58 deletions.
18 changes: 16 additions & 2 deletions pyof/v0x02/common/header.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
"""Defines Header classes and related items."""
from pyof.v0x01.common.header import Header, Type
"""Defines Header classes and related items.
Only differences between versions.
"""
from pyof.v0x01.common.header import Header as Header0x01, Type
from pyof.v0x02.foundation.base import OFP_VERSION
from pyof.v0x02.foundation.basic_types import UBInt8


__all__ = ('Header', 'Type')


class Header(Header0x01):
"""v0x02 Header differences."""

version = UBInt8(OFP_VERSION)

This comment has been minimized.

Copy link
@diraol

diraol Sep 2, 2016

Contributor

@cemsbr We have a problem here.

We are loosing the 'parent class' odered attribute. So, if you do:

>>> from pyof.v0x02.commom.header import Header
>>> h = Header()
>>> h.get_size()
1
>>> h.__ordered__
OrderedDict([('version', pyof.v0x01.foundation.basic_types.UBInt8)])

I can see two solutions here.
The first one is to implement the class again from the ground.
The second one is to override the ordered object.
The third one is to rewrite the MetaStruct class to consider inheritance cases.

This comment has been minimized.

Copy link
@diraol

diraol Sep 2, 2016

Contributor

Just to provide a follow up.
I've talked to @raphaelmcobe and we think that there is no simple/easy way to reimplement the metastruct class to consider this cases.
So, let's go with the kiss method and do a full new implementation of the class that has any changes, without inheritances.

This comment has been minimized.

Copy link
@cemsbr

cemsbr Sep 6, 2016

Author Contributor

Thanks for pointing that out. Another option is to use super().__ordered__, but manipulating the tuple list wouldn't be trivial.

This comment has been minimized.

Copy link
@diraol

diraol Sep 6, 2016

Contributor

Yeah, not trivial at all!
(And this is highly correlated to #157)

7 changes: 6 additions & 1 deletion pyof/v0x02/foundation/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
:class:`GenericMessage`, :class:`GenericBitMask` and :class:`GenericType`.
These classes are used in all parts of this library.
"""
from pyof.v0x01.foundation.base import (GenericBitMask, GenericMessage,
from pyof.v0x01.foundation.base import (DESC_STR_LEN, OFP_ETH_ALEN,
OFP_MAX_PORT_NAME_LEN,
OFP_MAX_TABLE_NAME_LEN, SERIAL_NUM_LEN,
GenericBitMask, GenericMessage,
GenericStruct, GenericType,
MetaBitMask, MetaStruct)

OFP_VERSION = 0x02
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def __init__(self, *args, **kwargs):
author_email='[email protected]',
license='MIT',
test_suite='tests',
packages=find_packages(exclude=['tests', '*v0x02*']),
packages=find_packages(exclude=['tests']),
cmdclass={
'lint': Linter,
'quick_lint': FastLinter
Expand Down
Empty file added tests/v0x02/__init__.py
Empty file.
54 changes: 0 additions & 54 deletions tests/v0x02/test_common/test_flow_instruction.py

This file was deleted.

13 changes: 13 additions & 0 deletions tests/v0x02/test_common/test_header.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""Header testing."""
import unittest

from pyof.v0x02.common.header import Header


class TestHeader(unittest.TestCase):
"""Test Header changes between v0x01 and v0x02."""

def test_version(self):
"""Version must be 0x02 for OF 1.1.0."""
header = Header()
self.assertEqual(0x02, header.version)

0 comments on commit 1634da3

Please sign in to comment.