forked from contiv/vpp
/
data_change.go
398 lines (339 loc) · 12.7 KB
/
data_change.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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
package linux
import (
"github.com/ligato/vpp-agent/clientv2/linux"
"github.com/ligato/vpp-agent/clientv2/vpp"
"github.com/contiv/vpp/mock/localclient/dsl"
"github.com/ligato/vpp-agent/api/models/linux/interfaces"
"github.com/ligato/vpp-agent/api/models/linux/l3"
"github.com/ligato/vpp-agent/api/models/vpp/abf"
"github.com/ligato/vpp-agent/api/models/vpp/acl"
"github.com/ligato/vpp-agent/api/models/vpp/interfaces"
"github.com/ligato/vpp-agent/api/models/vpp/ipsec"
"github.com/ligato/vpp-agent/api/models/vpp/l2"
"github.com/ligato/vpp-agent/api/models/vpp/l3"
"github.com/ligato/vpp-agent/api/models/vpp/nat"
"github.com/ligato/vpp-agent/api/models/vpp/punt"
"github.com/ligato/vpp-agent/api/models/vpp/stn"
)
// MockDataChangeDSL is mock for DataChangeDSL.
type MockDataChangeDSL struct {
dsl.CommonMockDSL
}
// NewMockDataChangeDSL is a constructor for MockDataChangeDSL.
func NewMockDataChangeDSL(commitFunc dsl.CommitFunc) *MockDataChangeDSL {
return &MockDataChangeDSL{CommonMockDSL: dsl.NewCommonMockDSL(commitFunc)}
}
// MockPutDSL is a mock for PutDSL.
type MockPutDSL struct {
parent *MockDataChangeDSL
}
// MockDeleteDSL is a mock for DeleteDSL.
type MockDeleteDSL struct {
parent *MockDataChangeDSL
}
// Put initiates a chained sequence of data change DSL statements declaring
// new or changing existing configurable objects.
func (d *MockDataChangeDSL) Put() linuxclient.PutDSL {
return &MockPutDSL{d}
}
// Delete initiates a chained sequence of data change DSL statements
// removing existing configurable objects.
func (d *MockDataChangeDSL) Delete() linuxclient.DeleteDSL {
return &MockDeleteDSL{d}
}
// Send commits the transaction into the mock DB.
func (d *MockDataChangeDSL) Send() vppclient.Reply {
err := d.CommitFunc(d.Values)
return &dsl.Reply{Err: err}
}
// VppInterface adds a mock request to create or update VPP network interface.
func (d *MockPutDSL) VppInterface(val *vpp_interfaces.Interface) linuxclient.PutDSL {
key := vpp_interfaces.InterfaceKey(val.Name)
d.parent.Values[key] = val
return d
}
// ABF adds a request to create or update VPP ACL-based forwarding.
func (d *MockPutDSL) ABF(val *vpp_abf.ABF) linuxclient.PutDSL {
key := vpp_abf.Key(val.Index)
d.parent.Values[key] = val
return d
}
// BD adds a mock request to create or update VPP Bridge Domain.
func (d *MockPutDSL) BD(val *vpp_l2.BridgeDomain) linuxclient.PutDSL {
key := vpp_l2.BridgeDomainKey(val.Name)
d.parent.Values[key] = val
return d
}
// BDFIB adds a mock request to create or update VPP L2 Forwarding Information
// Base.
func (d *MockPutDSL) BDFIB(val *vpp_l2.FIBEntry) linuxclient.PutDSL {
key := vpp_l2.FIBKey(val.BridgeDomain, val.PhysAddress)
d.parent.Values[key] = val
return d
}
// XConnect adds a mock request to create or update VPP Cross Connect.
func (d *MockPutDSL) XConnect(val *vpp_l2.XConnectPair) linuxclient.PutDSL {
key := vpp_l2.XConnectKey(val.ReceiveInterface)
d.parent.Values[key] = val
return d
}
// StaticRoute adds a mock request to create or update VPP L3 Static Route.
func (d *MockPutDSL) StaticRoute(val *vpp_l3.Route) linuxclient.PutDSL {
key := vpp_l3.RouteKey(val.OutgoingInterface, val.VrfId, val.DstNetwork, val.NextHopAddr)
d.parent.Values[key] = val
return d
}
// Span adds a mock VPP span to the Put request.
func (d *MockPutDSL) Span(val *vpp_interfaces.Span) linuxclient.PutDSL {
key := vpp_interfaces.SpanKey(val.InterfaceFrom, val.InterfaceTo)
d.parent.Values[key] = val
return d
}
// ACL adds a mock request to create or update VPP Access Control List.
func (d *MockPutDSL) ACL(val *vpp_acl.ACL) linuxclient.PutDSL {
key := vpp_acl.Key(val.Name)
d.parent.Values[key] = val
return d
}
// Arp adds a request to create or update VPP L3 ARP.
func (d *MockPutDSL) Arp(val *vpp_l3.ARPEntry) linuxclient.PutDSL {
key := vpp_l3.ArpEntryKey(val.Interface, val.IpAddress)
d.parent.Values[key] = val
return d
}
// ProxyArp adds a request to create or update VPP L3 proxy ARP.
func (d *MockPutDSL) ProxyArp(val *vpp_l3.ProxyARP) linuxclient.PutDSL {
key := vpp_l3.ProxyARPKey()
d.parent.Values[key] = val
return d
}
// IPScanNeighbor adds L3 IP Scan Neighbor to the RESYNC request.
func (d *MockPutDSL) IPScanNeighbor(val *vpp_l3.IPScanNeighbor) linuxclient.PutDSL {
key := vpp_l3.IPScanNeighborKey()
d.parent.Values[key] = val
return d
}
// StnRule adds a request to create or update VPP Stn rule.
func (d *MockPutDSL) StnRule(val *vpp_stn.Rule) linuxclient.PutDSL {
key := vpp_stn.Key(val.Interface, val.IpAddress)
d.parent.Values[key] = val
return d
}
// NAT44Global adds a request to set global configuration for NAT44
func (d *MockPutDSL) NAT44Global(val *vpp_nat.Nat44Global) linuxclient.PutDSL {
key := vpp_nat.GlobalNAT44Key()
d.parent.Values[key] = val
return d
}
// DNAT44 adds a request to create a new DNAT configuration
func (d *MockPutDSL) DNAT44(val *vpp_nat.DNat44) linuxclient.PutDSL {
key := vpp_nat.DNAT44Key(val.Label)
d.parent.Values[key] = val
return d
}
// LinuxInterface adds a mock request to create or update Linux network interface.
func (d *MockPutDSL) LinuxInterface(val *linux_interfaces.Interface) linuxclient.PutDSL {
key := linux_interfaces.InterfaceKey(val.Name)
d.parent.Values[key] = val
return d
}
func (d *MockPutDSL) LinuxArpEntry(val *linux_l3.ARPEntry) linuxclient.PutDSL {
key := linux_l3.ArpKey(val.Interface, val.IpAddress)
d.parent.Values[key] = val
return d
}
func (d *MockPutDSL) LinuxRoute(val *linux_l3.Route) linuxclient.PutDSL {
key := linux_l3.RouteKey(val.DstNetwork, val.OutgoingInterface)
d.parent.Values[key] = val
return d
}
// IPSecSA adds request to create a new Security Association
func (d *MockPutDSL) IPSecSA(val *vpp_ipsec.SecurityAssociation) linuxclient.PutDSL {
key := vpp_ipsec.SAKey(val.Index)
d.parent.Values[key] = val
return d
}
// IPSecSPD adds request to create a new Security Policy Database
func (d *MockPutDSL) IPSecSPD(val *vpp_ipsec.SecurityPolicyDatabase) linuxclient.PutDSL {
key := vpp_ipsec.SPDKey(val.Index)
d.parent.Values[key] = val
return d
}
// PuntIPRedirect adds request to create or update rule to punt L3 traffic via interface.
func (d *MockPutDSL) PuntIPRedirect(val *vpp_punt.IPRedirect) linuxclient.PutDSL {
key := vpp_punt.IPRedirectKey(val.L3Protocol, val.TxInterface)
d.parent.Values[key] = val
return d
}
// PuntToHost adds request to create or update rule to punt L4 traffic to a host.
func (d *MockPutDSL) PuntToHost(val *vpp_punt.ToHost) linuxclient.PutDSL {
key := vpp_punt.ToHostKey(val.L3Protocol, val.L4Protocol, val.Port)
d.parent.Values[key] = val
return d
}
// PuntException adds request to delete a rule used to add exception in punting of traffic to a host.
func (d *MockPutDSL) PuntException(val *vpp_punt.Exception) linuxclient.PutDSL {
key := vpp_punt.ExceptionKey(val.Reason)
d.parent.Values[key] = val
return d
}
// VrfTable adds a request to create or update VPP VRF table.
func (d *MockPutDSL) VrfTable(val *vpp_l3.VrfTable) linuxclient.PutDSL {
key := vpp_l3.VrfTableKey(val.Id, val.Protocol)
d.parent.Values[key] = val
return d
}
// Delete changes the DSL mode to allow removal of an existing configuration.
func (d *MockPutDSL) Delete() linuxclient.DeleteDSL {
return &MockDeleteDSL{d.parent}
}
// Send commits the transaction into the mock DB.
func (d *MockPutDSL) Send() vppclient.Reply {
return d.parent.Send()
}
// VppInterface adds a mock request to delete an existing VPP network interface.
func (d *MockDeleteDSL) VppInterface(interfaceName string) linuxclient.DeleteDSL {
key := vpp_interfaces.InterfaceKey(interfaceName)
d.parent.Values[key] = nil
return d
}
// ABF adds a request to delete and existing VPP Access Control List.
func (d *MockDeleteDSL) ABF(abfIndex uint32) linuxclient.DeleteDSL {
key := vpp_abf.Key(abfIndex)
d.parent.Values[key] = nil
return d
}
// BD adds a mock request to delete an existing VPP Bridge Domain.
func (d *MockDeleteDSL) BD(bdName string) linuxclient.DeleteDSL {
key := vpp_l2.BridgeDomainKey(bdName)
d.parent.Values[key] = nil
return d
}
// BDFIB adds a mock request to delete an existing VPP L2 Forwarding Information
// Base.
func (d *MockDeleteDSL) BDFIB(bdName string, mac string) linuxclient.DeleteDSL {
key := vpp_l2.FIBKey(bdName, mac)
d.parent.Values[key] = nil
return d
}
// XConnect adds a mock request to delete an existing VPP Cross Connect.
func (d *MockDeleteDSL) XConnect(rxIfName string) linuxclient.DeleteDSL {
key := vpp_l2.XConnectKey(rxIfName)
d.parent.Values[key] = nil
return d
}
// StaticRoute adds a mock request to delete an existing VPP L3 Static Route..
func (d *MockDeleteDSL) StaticRoute(iface string, vrf uint32, dstAddr string, nextHopAddr string) linuxclient.DeleteDSL {
key := vpp_l3.RouteKey(iface, vrf, dstAddr, nextHopAddr)
d.parent.Values[key] = nil
return d
}
// Span adds a mock VPP span to the Delete request.
func (d *MockDeleteDSL) Span(span *vpp_interfaces.Span) linuxclient.DeleteDSL {
key := vpp_interfaces.SpanKey(span.InterfaceFrom, span.InterfaceTo)
d.parent.Values[key] = nil
return d
}
// ACL adds a mock request to delete an existing VPP Access Control List.
func (d *MockDeleteDSL) ACL(aclName string) linuxclient.DeleteDSL {
key := vpp_acl.Key(aclName)
d.parent.Values[key] = nil
return d
}
// Arp adds a request to delete an existing VPP L3 ARP entry.
func (d *MockDeleteDSL) Arp(ifaceName string, ipAddr string) linuxclient.DeleteDSL {
key := vpp_l3.ArpEntryKey(ifaceName, ipAddr)
d.parent.Values[key] = nil
return d
}
// ProxyArp adds a request to delete an existing VPP L3 proxy ARP.
func (d *MockDeleteDSL) ProxyArp() linuxclient.DeleteDSL {
key := vpp_l3.ProxyARPKey()
d.parent.Values[key] = nil
return d
}
// IPScanNeighbor adds a request to delete an existing VPP L3 IP Scan Neighbor.
func (d *MockDeleteDSL) IPScanNeighbor() linuxclient.DeleteDSL {
key := vpp_l3.IPScanNeighborKey()
d.parent.Values[key] = nil
return d
}
// StnRule adds request to delete Stn rule.
func (d *MockDeleteDSL) StnRule(ifName, ipAddr string) linuxclient.DeleteDSL {
key := vpp_stn.Key(ifName, ipAddr)
d.parent.Values[key] = nil
return d
}
// NAT44Global adds a request to remove global configuration for NAT44
func (d *MockDeleteDSL) NAT44Global() linuxclient.DeleteDSL {
key := vpp_nat.GlobalNAT44Key()
d.parent.Values[key] = nil
return d
}
// DNAT44 adds a request to delete a DNAT configuration identified by label
func (d *MockDeleteDSL) DNAT44(label string) linuxclient.DeleteDSL {
key := vpp_nat.DNAT44Key(label)
d.parent.Values[key] = nil
return d
}
// LinuxInterface adds a mock request to delete an existing Linux network
// interface.
func (d *MockDeleteDSL) LinuxInterface(ifName string) linuxclient.DeleteDSL {
key := linux_interfaces.InterfaceKey(ifName)
d.parent.Values[key] = nil
return d
}
func (d *MockDeleteDSL) LinuxArpEntry(ifaceName string, ipAddr string) linuxclient.DeleteDSL {
key := linux_l3.ArpKey(ifaceName, ipAddr)
d.parent.Values[key] = nil
return d
}
func (d *MockDeleteDSL) LinuxRoute(dstAddr, outIfaceName string) linuxclient.DeleteDSL {
key := linux_l3.RouteKey(dstAddr, outIfaceName)
d.parent.Values[key] = nil
return d
}
// IPSecSA adds request to delete a Security Association
func (d *MockDeleteDSL) IPSecSA(saIndex string) linuxclient.DeleteDSL {
key := vpp_ipsec.SAKey(saIndex)
d.parent.Values[key] = nil
return d
}
// IPSecSPD adds request to delete a Security Policy Database
func (d *MockDeleteDSL) IPSecSPD(spdIndex string) linuxclient.DeleteDSL {
key := vpp_ipsec.SPDKey(spdIndex)
d.parent.Values[key] = nil
return d
}
// PuntIPRedirect adds request to delete a rule used to punt L3 traffic via interface.
func (d *MockDeleteDSL) PuntIPRedirect(l3Proto vpp_punt.L3Protocol, txInterface string) linuxclient.DeleteDSL {
key := vpp_punt.IPRedirectKey(l3Proto, txInterface)
d.parent.Values[key] = nil
return d
}
// PuntToHost adds request to delete a rule used to punt L4 traffic to a host.
func (d *MockDeleteDSL) PuntToHost(l3Proto vpp_punt.L3Protocol, l4Proto vpp_punt.L4Protocol, port uint32) linuxclient.DeleteDSL {
key := vpp_punt.ToHostKey(l3Proto, l4Proto, port)
d.parent.Values[key] = nil
return d
}
// PuntException adds request to delete a rule used to add exception in punting of traffic to a host.
func (d *MockDeleteDSL) PuntException(reason string) linuxclient.DeleteDSL {
key := vpp_punt.ExceptionKey(reason)
d.parent.Values[key] = nil
return d
}
// VrfTable adds a request to delete existing VPP VRF table.
func (d *MockDeleteDSL) VrfTable(id uint32, proto vpp_l3.VrfTable_Protocol) linuxclient.DeleteDSL {
key := vpp_l3.VrfTableKey(id, proto)
d.parent.Values[key] = nil
return d
}
// Put changes the DSL mode to allow configuration editing.
func (d *MockDeleteDSL) Put() linuxclient.PutDSL {
return &MockPutDSL{d.parent}
}
// Send commits the transaction into the mock DB.
func (d *MockDeleteDSL) Send() vppclient.Reply {
return d.parent.Send()
}