-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathfeatures.go
112 lines (94 loc) · 2.66 KB
/
features.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
* Cherry - An OpenFlow Controller
*
* Copyright (C) 2015 Samjung Data Service, Inc. All rights reserved.
* Kitae Kim <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package of10
import (
"encoding/binary"
"github.com/superkkt/cherry/openflow"
)
type FeaturesRequest struct {
openflow.Message
}
func NewFeaturesRequest(xid uint32) openflow.FeaturesRequest {
return &FeaturesRequest{
Message: openflow.NewMessage(openflow.OF10_VERSION, OFPT_FEATURES_REQUEST, xid),
}
}
func (r *FeaturesRequest) MarshalBinary() ([]byte, error) {
return r.Message.MarshalBinary()
}
type FeaturesReply struct {
openflow.Message
dpid uint64
numBuffers uint32
numTables uint8
capabilities uint32
actions uint32
ports []openflow.Port
}
func (r FeaturesReply) DPID() uint64 {
return r.dpid
}
func (r FeaturesReply) NumBuffers() uint32 {
return r.numBuffers
}
func (r FeaturesReply) NumTables() uint8 {
return r.numTables
}
func (r FeaturesReply) Capabilities() uint32 {
return r.capabilities
}
func (r FeaturesReply) Actions() uint32 {
return r.actions
}
func (r FeaturesReply) Ports() []openflow.Port {
return r.ports
}
func (r FeaturesReply) AuxID() uint8 {
// OpenFlow 1.0 does not have auxilary ID
return 0
}
func (r *FeaturesReply) UnmarshalBinary(data []byte) error {
if err := r.Message.UnmarshalBinary(data); err != nil {
return err
}
payload := r.Payload()
if payload == nil || len(payload) < 24 {
return openflow.ErrInvalidPacketLength
}
r.dpid = binary.BigEndian.Uint64(payload[0:8])
r.numBuffers = binary.BigEndian.Uint32(payload[8:12])
r.numTables = payload[12]
r.capabilities = binary.BigEndian.Uint32(payload[16:20])
r.actions = binary.BigEndian.Uint32(payload[20:24])
nPorts := (len(payload) - 24) / 48
if nPorts == 0 {
return nil
}
r.ports = make([]openflow.Port, nPorts)
for i := 0; i < nPorts; i++ {
buf := payload[24+i*48:]
r.ports[i] = new(Port)
if err := r.ports[i].UnmarshalBinary(buf[0:48]); err != nil {
return err
}
}
return nil
}