Jonathan Hart | 828908c | 2020-04-15 14:23:45 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior University |
| 3 | * Copyright (c) 2011, 2012 Open Networking Foundation |
| 4 | * Copyright 2013, Big Switch Networks, Inc. This library was generated by the LoxiGen Compiler. |
| 5 | * Copyright 2018, Red Hat, Inc. |
| 6 | */ |
Don Newton | 98fd881 | 2019-09-23 15:15:02 -0400 | [diff] [blame] | 7 | package goloxi |
| 8 | |
| 9 | import "fmt" |
| 10 | |
| 11 | const ( |
| 12 | VERSION_1_0 = 1 |
| 13 | VERSION_1_1 = 2 |
| 14 | VERSION_1_2 = 3 |
| 15 | VERSION_1_3 = 4 |
| 16 | VERSION_1_4 = 5 |
| 17 | VERSION_1_5 = 6 |
| 18 | ) |
| 19 | |
| 20 | const ( |
| 21 | OFPTHello = 0 |
| 22 | OFPTError = 1 |
| 23 | OFPTEchoRequest = 2 |
| 24 | OFPTEchoReply = 3 |
| 25 | OFPTExperimenter = 4 |
| 26 | ) |
| 27 | |
| 28 | type Serializable interface { |
| 29 | Serialize(encoder *Encoder) error |
| 30 | } |
| 31 | |
| 32 | type Deserializable interface { |
| 33 | Decode(decoder *Decoder) error |
| 34 | } |
| 35 | |
| 36 | type Header struct { |
| 37 | Version uint8 |
| 38 | Type uint8 |
| 39 | Length uint16 |
| 40 | Xid uint32 |
| 41 | } |
| 42 | |
| 43 | type Message interface { |
| 44 | Serializable |
| 45 | GetVersion() uint8 |
| 46 | GetLength() uint16 |
| 47 | MessageType() uint8 |
| 48 | MessageName() string |
| 49 | GetXid() uint32 |
| 50 | SetXid(xid uint32) |
| 51 | } |
| 52 | |
| 53 | type Uint128 struct { |
| 54 | Hi uint64 |
| 55 | Lo uint64 |
| 56 | } |
| 57 | |
| 58 | type IOxm interface { |
| 59 | Serializable |
| 60 | GetOXMName() string |
| 61 | GetOXMValue() interface{} |
| 62 | } |
| 63 | |
| 64 | type IOxmMasked interface { |
| 65 | Serializable |
| 66 | GetOXMName() string |
| 67 | GetOXMValue() interface{} |
| 68 | GetOXMValueMask() interface{} |
| 69 | } |
| 70 | |
| 71 | type IOxmId interface { |
| 72 | Serializable |
| 73 | GetOXMName() string |
| 74 | } |
| 75 | |
| 76 | type IAction interface { |
| 77 | Serializable |
| 78 | GetType() uint16 |
| 79 | GetLen() uint16 |
| 80 | GetActionName() string |
| 81 | GetActionFields() map[string]interface{} |
| 82 | } |
| 83 | |
| 84 | func (self *Header) Decode(decoder *Decoder) (err error) { |
| 85 | if decoder.Length() < 8 { |
| 86 | return fmt.Errorf("Header packet too short: %d < 4", decoder.Length()) |
| 87 | } |
| 88 | |
| 89 | defer func() { |
| 90 | if r := recover(); r != nil { |
| 91 | var ok bool |
| 92 | err, ok = r.(error) |
| 93 | if !ok { |
| 94 | err = fmt.Errorf("Error while parsing OpenFlow packet: %+v", r) |
| 95 | } |
| 96 | } |
| 97 | }() |
| 98 | |
| 99 | self.Version = decoder.ReadByte() |
| 100 | self.Type = decoder.ReadByte() |
| 101 | self.Length = decoder.ReadUint16() |
| 102 | self.Xid = decoder.ReadUint32() |
| 103 | |
| 104 | return nil |
| 105 | } |