blob: cb8c54c2866b6c219093364d183f6dae71b92ed5 [file] [log] [blame]
Don Newton98fd8812019-09-23 15:15:02 -04001package goloxi
2
3import "fmt"
4
5const (
6 VERSION_1_0 = 1
7 VERSION_1_1 = 2
8 VERSION_1_2 = 3
9 VERSION_1_3 = 4
10 VERSION_1_4 = 5
11 VERSION_1_5 = 6
12)
13
14const (
15 OFPTHello = 0
16 OFPTError = 1
17 OFPTEchoRequest = 2
18 OFPTEchoReply = 3
19 OFPTExperimenter = 4
20)
21
22type Serializable interface {
23 Serialize(encoder *Encoder) error
24}
25
26type Deserializable interface {
27 Decode(decoder *Decoder) error
28}
29
30type Header struct {
31 Version uint8
32 Type uint8
33 Length uint16
34 Xid uint32
35}
36
37type Message interface {
38 Serializable
39 GetVersion() uint8
40 GetLength() uint16
41 MessageType() uint8
42 MessageName() string
43 GetXid() uint32
44 SetXid(xid uint32)
45}
46
47type Uint128 struct {
48 Hi uint64
49 Lo uint64
50}
51
52type IOxm interface {
53 Serializable
54 GetOXMName() string
55 GetOXMValue() interface{}
56}
57
58type IOxmMasked interface {
59 Serializable
60 GetOXMName() string
61 GetOXMValue() interface{}
62 GetOXMValueMask() interface{}
63}
64
65type IOxmId interface {
66 Serializable
67 GetOXMName() string
68}
69
70type IAction interface {
71 Serializable
72 GetType() uint16
73 GetLen() uint16
74 GetActionName() string
75 GetActionFields() map[string]interface{}
76}
77
78func (self *Header) Decode(decoder *Decoder) (err error) {
79 if decoder.Length() < 8 {
80 return fmt.Errorf("Header packet too short: %d < 4", decoder.Length())
81 }
82
83 defer func() {
84 if r := recover(); r != nil {
85 var ok bool
86 err, ok = r.(error)
87 if !ok {
88 err = fmt.Errorf("Error while parsing OpenFlow packet: %+v", r)
89 }
90 }
91 }()
92
93 self.Version = decoder.ReadByte()
94 self.Type = decoder.ReadByte()
95 self.Length = decoder.ReadUint16()
96 self.Xid = decoder.ReadUint32()
97
98 return nil
99}