-
Notifications
You must be signed in to change notification settings - Fork 74
/
ofnet.go
executable file
·330 lines (260 loc) · 9.42 KB
/
ofnet.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
/***
Copyright 2014 Cisco Systems Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package ofnet
// This package implements openflow network manager
import (
"net"
"time"
"github.com/contiv/libOpenflow/openflow13"
"github.com/contiv/ofnet/ofctrl"
)
const (
OFNET_INTERNAL = 1 //Internal contiv cluster ep type
OFNET_INTERNAL_BGP = 2 //Internal contiv bgp intf ep
OFNET_EXTERNAL_BGP = 3 //External contiv bgp neighbor ep
OFNET_EXTERNAL = 4 //External eps (non contiv eps)
)
// Interface implemented by each datapath
type OfnetDatapath interface {
// New master was added.
MasterAdded(master *OfnetNode) error
// Switch connected notification
SwitchConnected(sw *ofctrl.OFSwitch)
// Switch disconnected notification
SwitchDisconnected(sw *ofctrl.OFSwitch)
// Process Incoming packet
PacketRcvd(sw *ofctrl.OFSwitch, pkt *ofctrl.PacketIn)
// Add a local endpoint to forwarding DB
AddLocalEndpoint(endpoint OfnetEndpoint) error
// Remove a local endpoint from forwarding DB
RemoveLocalEndpoint(endpoint OfnetEndpoint) error
// Update a local endpoint state
UpdateLocalEndpoint(ep *OfnetEndpoint, epInfo EndpointInfo) error
// Add a remote endpoint to forwarding DB
AddEndpoint(endpoint *OfnetEndpoint) error
// Remove a remote endpoint from forwarding DB
RemoveEndpoint(endpoint *OfnetEndpoint) error
// Add an remote VTEP
AddVtepPort(portNo uint32, remoteIp net.IP) error
// Remove remote VTEP
RemoveVtepPort(portNo uint32, remoteIp net.IP) error
// Add a vlan
AddVlan(vlanId uint16, vni uint32, vrf string) error
// Remove a vlan
RemoveVlan(vlanId uint16, vni uint32, vrf string) error
//Add uplink port
AddUplink(uplinkPort *PortInfo) error
//Update uplink port
UpdateUplink(uplinkName string, update PortUpdates) error
//Delete uplink port
RemoveUplink(uplinkName string) error
// AddHostPort
AddHostPort(hp HostPortInfo) error
// RemoveHostPort
RemoveHostPort(portNo uint32) error
//Inject GARPs
InjectGARPs(epgID int)
// Add a service spec to proxy
AddSvcSpec(svcName string, spec *ServiceSpec) error
// Remove a service spec from proxy
DelSvcSpec(svcName string, spec *ServiceSpec) error
// Service Proxy Back End update
SvcProviderUpdate(svcName string, providers []string)
// Handle multipart replies from OVS
MultipartReply(sw *ofctrl.OFSwitch, reply *openflow13.MultipartReply)
// Get endpoint stats
GetEndpointStats() (map[string]*OfnetEndpointStats, error)
// Return the datapath state
InspectState() (interface{}, error)
// Set global config
GlobalConfigUpdate(cfg OfnetGlobalConfig) error
// flush the endpoints
FlushEndpoints(endpointType int)
}
// Interface implemented by each control protocol.
type OfnetProto interface {
//Create a protocol server
StartProtoServer(routerInfo *OfnetProtoRouterInfo) error
StopProtoServer() error
//Add a Protocol Neighbor
AddProtoNeighbor(neighborInfo *OfnetProtoNeighborInfo) error
//Delete a Protocol Neighbor
DeleteProtoNeighbor() error
//Get Protocol router info
GetRouterInfo() *OfnetProtoRouterInfo
//Set Protocol router info
SetRouterInfo(uplinkPort *PortInfo) error
//Add Local Route
AddLocalProtoRoute(path []*OfnetProtoRouteInfo) error
//Delete Local Route
DeleteLocalProtoRoute(path []*OfnetProtoRouteInfo) error
//Modify protocol Rib (Could be used for testing)
ModifyProtoRib(path interface{})
//Inspect bgp
InspectProto() (interface{}, error)
}
// Default port numbers
const OFNET_MASTER_PORT = 9001
const OFNET_AGENT_VXLAN_PORT = 9002
const OFNET_AGENT_VLAN_PORT = 9010
// internal vlan id
const nameServerInternalVlanId = 4093
// Information about each node
type OfnetNode struct {
HostAddr string
HostPort uint16
}
// OfnetEndpoint has info about an endpoint
type OfnetEndpoint struct {
EndpointID string // Unique identifier for the endpoint
EndpointType int // Type of the endpoint , "external" or "externalRoute"
EndpointGroup int // Endpoint group identifier for policies.
IpAddr net.IP // IP address of the end point
IpMask net.IP // IP mask for the end point
Ipv6Addr net.IP // IPv6 address of the end point
Ipv6Mask net.IP // IPv6 mask for the end point
Vrf string // IP address namespace
MacAddrStr string // Mac address of the end point(in string format)
Vlan uint16 // Vlan Id for the endpoint
Vni uint32 // Vxlan VNI
EndpointGroupVlan uint16 // EnpointGroup Vlan, needed in non-Standalone mode of netplugin
OriginatorIp net.IP // Originating switch
OriginatorMac string // Mac address of the endpoint host
PortNo uint32 `json:"-"` // Port number on originating switch
Dscp int `json:"-"` // DSCP value for the endpoint
Timestamp time.Time // Timestamp of the last event
HostPvtIP net.IP `json:"-"` // Private IP
}
// OfnetPolicyRule has security rule to be installed
type OfnetPolicyRule struct {
RuleId string // Unique identifier for the rule
Priority int // Priority for the rule (1..100. 100 is highest)
SrcEndpointGroup int // Source endpoint group
DstEndpointGroup int // Destination endpoint group
SrcIpAddr string // source IP addrss and mask
DstIpAddr string // Destination IP address and mask
IpProtocol uint8 // IP protocol number
SrcPort uint16 // Source port
DstPort uint16 // destination port
TcpFlags string // TCP flags to match: syn || syn,ack || ack || syn,!ack || !syn,ack;
Action string // rule action: 'accept' or 'deny'
}
// OfnetProtoNeighborInfo has bgp neighbor info
type OfnetProtoNeighborInfo struct {
ProtocolType string // type of protocol
NeighborIP string // ip address of the neighbor
As string // As of neighbor if applicable
}
// OfnetProtoRouterInfo has local router info
type OfnetProtoRouterInfo struct {
ProtocolType string // type of protocol
RouterIP string // ip address of the router
UplinkPort *PortInfo // uplink L2 intf
As string // As for Bgp protocol
}
// OfnetProtoRouteInfo contains a route
type OfnetProtoRouteInfo struct {
ProtocolType string // type of protocol
localEpIP string
nextHopIP string
}
type ArpModeT string
const (
// ArpFlood - ARP packets will be flooded in this mode
ArpFlood ArpModeT = "flood"
// ArpProxy - ARP packets will be redirected to controller
ArpProxy ArpModeT = "proxy"
// PortType - individual port
PortType = "individual"
// BondType - bonded port
BondType = "bond"
// LacpUpdate - for port update info
LacpUpdate = "lacp-upd"
)
// OfnetGlobalConfig has global level configs for ofnet
type OfnetGlobalConfig struct {
ArpMode ArpModeT // arp mode: proxy or flood
}
// OfnetVrfInfo has info about a VRF
type OfnetVrfInfo struct {
VrfName string // vrf name
VrfId uint16 // local vrf id
NumNetworks uint16 // ref count of networks in the vrf
}
// OfnetDatapathStats is generic stats struct
type OfnetDatapathStats struct {
PacketsIn uint64
BytesIn uint64
PacketsOut uint64
BytesOut uint64
}
// OfnetSvcProviderStats has stats for a provider of a service
type OfnetSvcProviderStats struct {
ProviderIP string // Provider IP address
ServiceIP string // service ip address
ServiceVrf string // Provider VRF name
OfnetDatapathStats // stats
}
// OfnetSvcStats per service stats from one client
type OfnetSvcStats struct {
ServiceIP string // service ip address
ServiceVRF string // service vrf name
Protocol string // service protocol tcp | udp
SvcPort string // Service Port
ProvPort string // Provider port
SvcStats OfnetDatapathStats // aggregate service stats
ProvStats map[string]OfnetSvcProviderStats // per provider stats
}
// OfnetEndpointStats has stats for local endpoints
type OfnetEndpointStats struct {
EndpointIP string // Endpoint IP address
VrfName string // vrf name
PortStats OfnetDatapathStats // Aggregate port stats
SvcStats map[string]OfnetSvcStats // Service level stats
}
type linkStatus int
// LinkStatus maintains link up/down information
const (
linkDown linkStatus = iota
linkUp
)
// LinkInfo maintains individual link information
type LinkInfo struct {
Name string
Port *PortInfo
LinkStatus linkStatus
OfPort uint32
}
// PortInfo maintains port information
type PortInfo struct {
Name string
Type string
LinkStatus linkStatus
MbrLinks []*LinkInfo
ActiveLinks []*LinkInfo
}
// PortUpdates maintains multiplae port update info
type PortUpdates struct {
PortName string
Updates []PortUpdate
}
// PortUpdate maintains information about port update
type PortUpdate struct {
UpdateType string
UpdateInfo interface{}
}
// LACP update
type LinkUpdateInfo struct {
LinkName string
LacpStatus bool
}