Passed
Pull Request — master (#69)
by Humberto
01:53
created

build.serializers.base   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
eloc 16
dl 0
loc 33
rs 10
c 0
b 0
f 0
ccs 0
cts 11
cp 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A FlowSerializer.to_dict() 0 4 1
A FlowSerializer.from_dict() 0 4 1
A FlowSerializer.__init__() 0 4 1
1
"""Abstract class for serializing flows."""
2
from abc import ABC, abstractmethod
3
4
from pyof.v0x01.controller2switch.flow_mod import \
5
    FlowModCommand as CommonFlowModCommand
6
7
8
class FlowSerializer(ABC):
9
    """Common code for OF 1.0 and 1.3 flow serialization.
10
11
    For a FlowMod dictionary, create a FlowMod message and, for a FlowStats,
12
    create a dictionary.
13
    """
14
15
    # These values are the same in both versions 1.0 and 1.3
16
    OFPFC_ADD = CommonFlowModCommand.OFPFC_ADD
17
    OFPFC_DELETE = CommonFlowModCommand.OFPFC_DELETE
18
19
    def __init__(self):
20
        """Initialize common attributes of 1.0 and 1.3 versions."""
21
        self.flow_attributes = set(('priority', 'idle_timeout', 'hard_timeout',
22
                                    'cookie'))
23
24
    @abstractmethod
25
    def from_dict(self, dictionary):
26
        """Return a FlowMod instance created from a serialized dictionary."""
27
        pass
28
29
    @abstractmethod
30
    def to_dict(self, flow_stats):
31
        """Return a serialized dictionary for a FlowStats message."""
32
        pass
33