-
Notifications
You must be signed in to change notification settings - Fork 14
/
fq_req.go
282 lines (239 loc) · 8.29 KB
/
fq_req.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
// vi: sw=4 ts=4:
/*
---------------------------------------------------------------------------
Copyright (c) 2013-2015 AT&T Intellectual Property
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.
---------------------------------------------------------------------------
*/
/*
Mnemonic: fq_req.go
Abstract: Functions that work directly on fq_req structures.
Date: 22 August 2014
Author: E. Scott Daniels
Mods: 24 Sep 2014 : Added support for vlan id setting.
16 Jan 2015 : Support port masks in flow-mods.
20 Apr 2015 : Correct bug - not passing direction of external IP address to agent.
01 Sep 2015 : Changed bleat level for bwow debugging message.
04 Feg 2015 : Tweak to allow udp:0 and tcp:0 to be passed to agent.
*/
package managers
import (
"fmt"
"encoding/json"
"time"
"github.com/att/tegu/gizmos"
)
/*
Create a structure that is initialised such that the default is to not actually cause
a match to be generated and forces output to none.
*/
func Mk_fqreq( id *string ) ( np *Fq_req ) {
output := "none" // table 90 fmod does not output the packet
cookie := 0xedde
fq_match := &Fq_parms{
Swport: -1, // these defaults will not generate any match criteria
Dscp: -1,
Tpsport: &zero_string,
Tpdport: &zero_string,
}
fq_action := &Fq_parms{ // these defaults will not generate any actions
Meta: nil,
Swport: -1,
Dscp: -1,
Tpsport: &zero_string,
Tpdport: &zero_string,
}
np = &Fq_req { // fq-mgr request data
Id: id,
Cookie: cookie,
Expiry: 10, // default to a very short lived f-mod (DON'T defaut to 0)
Match: fq_match,
Action: fq_action,
Table: 0,
Output: &output, // default to no output
Dscp_koe: false,
Ipv6: false,
}
return
}
/*
Makes a deep copy (copies the match and action structs too) of a fq request
structure. Returns a pointer to the new struct.
*/
func ( src *Fq_req ) Clone( ) ( nr *Fq_req ) {
nmatch := &Fq_parms{} // create new
naction := &Fq_parms{}
nespq := &gizmos.Spq{}
nr = &Fq_req{}
*nr = *src // copy into our new struct
*naction = *src.Action // copy action and match to new structs
*nmatch = *src.Match
if src.Espq != nil {
*nespq = *src.Espq
}
nr.Espq = nespq
nr.Match = nmatch // must reset pointers in new to copies of match and action
nr.Action = naction
return
}
/*
Bundle the structure into json.
*/
func ( fq *Fq_req ) To_json( ) ( *string, error ) {
jbytes, err := json.Marshal( fq ) // bundle into a json string
s := string( jbytes )
return &s, err
}
/*
Build a map suitable for use as parms for a bandwidth request to the agent manager.
The agent bandwidth flow-mod generator takes a more generic set of parameters
and the match/action information is "compressed".
OVS doesn't accept DSCP values, but shifted values (e.g. 46 == 184), so we shift
the DSCP value given to be what OVS might want as a parameter.
*/
func ( fq *Fq_req ) To_bw_map( ) ( fmap map[string]string ) {
fmap = make( map[string]string )
if fq == nil {
return
}
if fq.Match.Smac != nil {
fmap["smac"] = *fq.Match.Smac
} else {
fmap["smac"] = ""
}
if fq.Match.Dmac != nil {
fmap["dmac"] = *fq.Match.Dmac
} else {
fmap["dmac"] = ""
}
if fq.Extip != nil {
fmap["extip"] = *fq.Extip // external IP if supplied
} else {
fmap["extip"] = ""
}
if fq.Exttyp != nil {
fmap["extdir"] = *fq.Exttyp // direction of external address (-D or -S)
} else {
fmap["extdir"] = ""
}
if fq.Match.Vlan_id != nil { // adds a vlan number to match (should NOT be a mac)
fmap["vlan_match"] = *fq.Match.Vlan_id
} else {
fmap["vlan_match"] = ""
}
if fq.Action.Vlan_id != nil { // adds a set vlan action, can be a MAC for late conversion
fmap["vlan_action"] = *fq.Action.Vlan_id
} else {
fmap["vlan_action"] = ""
}
fmap["queue"] = fmt.Sprintf( "%d", fq.Espq.Queuenum )
fmap["dscp"] = fmt.Sprintf( "%d", fq.Dscp << 2 ) // shift left 2 bits to match what OVS wants
fmap["ipv6"] = fmt.Sprintf( "%v", fq.Ipv6 ) // force ipv6 fmods is on
fmap["timeout"] = fmt.Sprintf( "%d", fq.Expiry - time.Now().Unix() )
//fmap["mtbase"] = fmt.Sprintf( "%d", fq.Mtbase )
fmap["oneswitch"] = fmt.Sprintf( "%v", fq.Single_switch )
fmap["koe"] = fmt.Sprintf( "%v", fq.Dscp_koe )
if fq.Tptype != nil && *fq.Tptype != "none" && *fq.Tptype != "" { // if a transport proto type supplied, turn it on
if fq.Match.Tpsport != nil { // set src/dest ports if they are defined
fmap["sproto"] = fmt.Sprintf( "%s:%s", *fq.Tptype, *fq.Match.Tpsport )
}
if fq.Match.Tpdport != nil {
fmap["dproto"] = fmt.Sprintf( "%s:%s", *fq.Tptype, *fq.Match.Tpdport )
}
}
if fq_sheep.Would_baa( 3 ) {
for k, v := range fmap {
fq_sheep.Baa( 3, "fq_req to action id=%s %s = %s", fq.Id, k, v )
}
}
return
}
/*
Build a map suitable for use as parms for a oneway bandwidth request to the agent manager.
The agent bandwidth flow-mod generator takes a more generic set of parameters
and the match/action information is "compressed".
OVS doesn't accept DSCP values, but shifted values (e.g. 46 == 184), so we shift
the DSCP value given to be what OVS might want as a parameter.
*/
func ( fq *Fq_req ) To_bwow_map( ) ( fmap map[string]string ) {
fmap = make( map[string]string )
if fq == nil {
return
}
if fq.Match.Smac != nil {
fmap["smac"] = *fq.Match.Smac
} else {
fmap["smac"] = ""
}
if fq.Match.Dmac != nil { // likely nil as oneways are usually x-project when router is not a neutron device
fmap["dmac"] = *fq.Match.Dmac
} else {
fmap["dmac"] = ""
}
if fq.Extip != nil {
fmap["extip"] = *fq.Extip // external IP if supplied
} else {
fmap["extip"] = ""
}
if fq.Match.Vlan_id != nil { // adds a vlan number to match (should NOT be a mac)
fmap["vlan_match"] = *fq.Match.Vlan_id
} else {
fmap["vlan_match"] = ""
}
if fq.Action.Vlan_id != nil { // adds a set vlan action, can be a MAC for late conversion
fmap["vlan_action"] = *fq.Action.Vlan_id
} else {
fmap["vlan_action"] = ""
}
fmap["queue"] = fmt.Sprintf( "%d", fq.Espq.Queuenum )
fmap["dscp"] = fmt.Sprintf( "%d", fq.Dscp << 2 ) // shift left 2 bits to match what OVS wants
fmap["ipv6"] = fmt.Sprintf( "%v", fq.Ipv6 ) // force ipv6 fmods is on
fmap["timeout"] = fmt.Sprintf( "%d", fq.Expiry - time.Now().Unix() )
if fq.Tptype != nil && *fq.Tptype != "none" && *fq.Tptype != "" { // if transport prototype defined, turn it on
if fq.Match.Tpsport != nil { // set src and dest ports if they are defined too
fmap["sproto"] = fmt.Sprintf( "%s:%s", *fq.Tptype, *fq.Match.Tpsport )
}
if fq.Match.Tpdport != nil {
fmap["dproto"] = fmt.Sprintf( "%s:%s", *fq.Tptype, *fq.Match.Tpdport )
}
}
if fq_sheep.Would_baa( 2 ) {
for k, v := range fmap {
fq_sheep.Baa( 2, "fq_req to action id=%s %s = %s", *fq.Id, k, v )
}
}
return
}
/*
Build a map suitable for use as parms for a passthrough request to the agent manager.
build_opt( parms["smac"], "-s" ) + // smac can (and should) be an endpoint UUID which is converted to mac/bridge on the host
build_opt( parms["sip"], "-S" ) + // sip is [proto:][addr:][port] where either proto or address must be supplied
build_opt( parms["timeout"], "-t" )
*/
func ( fq *Fq_req ) To_pt_map( ) ( fmap map[string]string ) {
fmap = make( map[string]string )
if fq == nil {
return
}
if fq.Match.Smac != nil { // could be endpoint, but likely mac in the original Tegu.
fmap["smac"] = *fq.Match.Smac
} else {
fmap["smac"] = "" // agent likely to barf on this
}
fmap["timeout"] = fmt.Sprintf( "%d", fq.Expiry - time.Now().Unix() )
fmap["sip"] = *fq.Match.Ip1 // will be [{udp|tcp}:]address[:port]
if fq_sheep.Would_baa( 3 ) {
for k, v := range fmap {
fq_sheep.Baa( 3, "to_pt_map: fq_req value -> action id=%s %s = %s", *fq.Id, k, v )
}
}
return
}