@@ -43,31 +43,30 @@ bool JsonRpc::createNetFlow(const string& brUuid, const string& target, const in
43
43
tuples.emplace_back (" " , target);
44
44
TupleDataSet tdSet (tuples);
45
45
JsonRpcTransactMessage msg1 (OvsdbOperation::INSERT, OvsdbTable::NETFLOW);
46
- msg1.rows [" targets" ] = tdSet;
46
+ msg1.rowData [" targets" ] = tdSet;
47
47
48
48
tuples.clear ();
49
49
tuples.emplace_back (" " , timeout);
50
50
tdSet = TupleDataSet (tuples);
51
- msg1.rows [" active_timeout" ] = tdSet;
51
+ msg1.rowData [" active_timeout" ] = tdSet;
52
52
53
53
tuples.clear ();
54
54
tuples.emplace_back (" " , addidtointerface);
55
55
tdSet = TupleDataSet (tuples);
56
- msg1.rows [" add_id_to_interface" ] = tdSet;
56
+ msg1.rowData [" add_id_to_interface" ] = tdSet;
57
57
58
58
const string uuid_name = " netflow1" ;
59
59
msg1.kvPairs .emplace_back (" uuid-name" , uuid_name);
60
60
61
61
JsonRpcTransactMessage msg2 (OvsdbOperation::UPDATE, OvsdbTable::BRIDGE);
62
- tuple<string, string, string> cond1 (" _uuid" , " ==" , brUuid);
63
62
set<tuple<string, string, string>> condSet;
64
- condSet.emplace (cond1 );
63
+ condSet.emplace (" _uuid " , " == " , brUuid );
65
64
msg2.conditions = condSet;
66
65
67
66
tuples.clear ();
68
67
tuples.emplace_back (" named-uuid" , uuid_name);
69
68
tdSet = TupleDataSet (tuples);
70
- msg2.rows .emplace (" netflow" , tdSet);
69
+ msg2.rowData .emplace (" netflow" , tdSet);
71
70
72
71
const list<JsonRpcTransactMessage> requests = {msg1, msg2};
73
72
if (!sendRequestAndAwaitResponse (requests)) {
@@ -82,12 +81,12 @@ bool JsonRpc::createIpfix(const string& brUuid, const string& target, const int&
82
81
tuples.emplace_back (" " , target);
83
82
TupleDataSet tdSet (tuples);
84
83
JsonRpcTransactMessage msg1 (OvsdbOperation::INSERT, OvsdbTable::IPFIX);
85
- msg1.rows .emplace (" targets" , tdSet);
84
+ msg1.rowData .emplace (" targets" , tdSet);
86
85
if (sampling != 0 ) {
87
86
tuples.clear ();
88
87
tuples.emplace_back (" " , sampling);
89
88
tdSet = TupleDataSet (tuples);
90
- msg1.rows .emplace (" sampling" , tdSet);
89
+ msg1.rowData .emplace (" sampling" , tdSet);
91
90
}
92
91
const string uuid_name = " ipfix1" ;
93
92
msg1.kvPairs .emplace_back (" uuid-name" , uuid_name);
@@ -100,7 +99,7 @@ bool JsonRpc::createIpfix(const string& brUuid, const string& target, const int&
100
99
tuples.clear ();
101
100
tuples.emplace_back (" named-uuid" , uuid_name);
102
101
tdSet = TupleDataSet (tuples);
103
- msg2.rows .emplace (" ipfix" , tdSet);
102
+ msg2.rowData .emplace (" ipfix" , tdSet);
104
103
105
104
const list<JsonRpcTransactMessage> requests = {msg1, msg2};
106
105
if (!sendRequestAndAwaitResponse (requests)) {
@@ -111,15 +110,14 @@ bool JsonRpc::createIpfix(const string& brUuid, const string& target, const int&
111
110
}
112
111
113
112
bool JsonRpc::deleteNetFlow (const string& brName) {
113
+ JsonRpcTransactMessage msg1 (OvsdbOperation::UPDATE, OvsdbTable::BRIDGE);
114
114
set<tuple<string, string, string>> condSet;
115
115
condSet.emplace (" name" , " ==" , brName);
116
-
117
- JsonRpcTransactMessage msg1 (OvsdbOperation::UPDATE, OvsdbTable::BRIDGE);
118
116
msg1.conditions = condSet;
119
117
120
118
vector<TupleData> tuples;
121
119
TupleDataSet tdSet (tuples, " set" );
122
- msg1.rows .emplace (" netflow" , tdSet);
120
+ msg1.rowData .emplace (" netflow" , tdSet);
123
121
124
122
list<JsonRpcTransactMessage> requests = {msg1};
125
123
if (!sendRequestAndAwaitResponse (requests)) {
@@ -130,16 +128,14 @@ bool JsonRpc::deleteNetFlow(const string& brName) {
130
128
}
131
129
132
130
bool JsonRpc::deleteIpfix (const string& brName) {
133
- tuple<string, string, string> cond1 (" name" , " ==" , brName);
134
- set<tuple<string, string, string>> condSet;
135
- condSet.emplace (cond1);
136
-
137
131
JsonRpcTransactMessage msg1 (OvsdbOperation::UPDATE, OvsdbTable::BRIDGE);
132
+ set<tuple<string, string, string>> condSet;
133
+ condSet.emplace (" name" , " ==" , brName);
138
134
msg1.conditions = condSet;
139
135
140
136
vector<TupleData> tuples;
141
137
TupleDataSet tdSet (tuples, " set" );
142
- msg1.rows .emplace (" ipfix" , tdSet);
138
+ msg1.rowData .emplace (" ipfix" , tdSet);
143
139
144
140
const list<JsonRpcTransactMessage> requests = {msg1};
145
141
if (!sendRequestAndAwaitResponse (requests)) {
@@ -179,11 +175,12 @@ bool JsonRpc::updateBridgePorts(
179
175
condSet.emplace (" _uuid" , " ==" , brUuid);
180
176
msg1.conditions = condSet;
181
177
vector<TupleData> tuples;
178
+ tuples.reserve (brPorts.size ());
182
179
for (auto & elem : brPorts) {
183
180
tuples.emplace_back (" uuid" , elem);
184
181
}
185
182
TupleDataSet tdSet (tuples, " set" );
186
- msg1.rows .emplace (" ports" , tdSet);
183
+ msg1.rowData .emplace (" ports" , tdSet);
187
184
188
185
const list<JsonRpcTransactMessage> requests = {msg1};
189
186
if (!sendRequestAndAwaitResponse (requests)) {
@@ -229,6 +226,7 @@ bool JsonRpc::handleGetBridgePortList(uint64_t reqId, const Document& payload, B
229
226
}
230
227
231
228
void JsonRpc::getUuidsFromVal (set<string>& uuidSet, const Document& payload, const string& index) {
229
+ LOG (INFO) << " getUuidsFromVal with index " << index;
232
230
list<string> ids = {" 0" ," rows" ," 0" ,index," 0" };
233
231
Value val;
234
232
opflexagent::getValue (payload, ids, val);
@@ -253,10 +251,9 @@ void JsonRpc::getUuidsFromVal(set<string>& uuidSet, const Document& payload, con
253
251
}
254
252
255
253
bool JsonRpc::getBridgePortList (const string& bridge, BrPortResult& res) {
256
- tuple<string, string, string> cond1 (" name" , " ==" , bridge);
257
- set<tuple<string, string, string>> condSet;
258
- condSet.emplace (cond1);
259
254
JsonRpcTransactMessage msg1 (OvsdbOperation::SELECT, OvsdbTable::BRIDGE);
255
+ set<tuple<string, string, string>> condSet;
256
+ condSet.emplace (" name" , " ==" , bridge);
260
257
msg1.conditions = condSet;
261
258
msg1.columns .emplace (" ports" );
262
259
msg1.columns .emplace (" _uuid" );
@@ -284,7 +281,7 @@ bool JsonRpc::getOvsdbMirrorConfig(mirror& mir) {
284
281
set<string> uuids;
285
282
uuids.insert (mir.src_ports .begin (), mir.src_ports .end ());
286
283
uuids.insert (mir.dst_ports .begin (), mir.dst_ports .end ());
287
- uuids.insert (mir.out_ports . begin (), mir. out_ports . end () );
284
+ uuids.insert (mir.out_port );
288
285
289
286
JsonRpcTransactMessage msg2 (OvsdbOperation::SELECT, OvsdbTable::PORT);
290
287
msg2.columns .emplace (" name" );
@@ -302,14 +299,18 @@ bool JsonRpc::getOvsdbMirrorConfig(mirror& mir) {
302
299
// replace port UUIDs with names in the mirror struct
303
300
substituteSet (mir.src_ports , portMap);
304
301
substituteSet (mir.dst_ports , portMap);
305
- substituteSet (mir.out_ports , portMap);
302
+ auto itr = portMap.find (mir.out_port );
303
+ if (itr != portMap.end ()) {
304
+ LOG (DEBUG) << " out_port name " << itr->second ;
305
+ mir.out_port = itr->second ;
306
+ }
306
307
return true ;
307
308
}
308
309
309
310
bool JsonRpc::getCurrentErspanParams (const string& portName, erspan_ifc& params) {
310
311
// for ERSPAN port get IP address
311
312
JsonRpcTransactMessage msg1 (OvsdbOperation::SELECT, OvsdbTable::INTERFACE);
312
- tuple<string, string, string> cond1 (" name" , " ==" , ERSPAN_PORT_NAME );
313
+ tuple<string, string, string> cond1 (" name" , " ==" , portName );
313
314
set<tuple<string, string, string>> condSet;
314
315
condSet.emplace (cond1);
315
316
msg1.conditions = condSet;
@@ -360,7 +361,9 @@ bool JsonRpc::handleMirrorConfig(uint64_t reqId, const Document& payload, mirror
360
361
uuids.clear ();
361
362
getUuidsFromVal (uuids, payload, " output_port" );
362
363
363
- mir.out_ports .insert (uuids.begin (), uuids.end ());
364
+ if (!uuids.empty ()) {
365
+ mir.out_port = *(uuids.begin ());
366
+ }
364
367
return true ;
365
368
}
366
369
@@ -474,10 +477,9 @@ void JsonRpc::getPortUuids(map<string, string>& ports) {
474
477
}
475
478
476
479
void JsonRpc::getBridgeUuid (const string& name, string& uuid) {
477
- tuple<string, string, string> cond1 (" name" , " ==" , name);
478
- set<tuple<string, string, string>> condSet;
479
- condSet.emplace (cond1);
480
480
JsonRpcTransactMessage msg1 (OvsdbOperation::SELECT, OvsdbTable::BRIDGE);
481
+ set<tuple<string, string, string>> condSet;
482
+ condSet.emplace (" name" , " ==" , name);
481
483
msg1.conditions = condSet;
482
484
msg1.columns .emplace (" _uuid" );
483
485
@@ -506,7 +508,7 @@ bool JsonRpc::createMirror(const string& brUuid, const string& name, const set<s
506
508
set<string> ports;
507
509
ports.insert (srcPorts.begin (), srcPorts.end ());
508
510
ports.insert (dstPorts.begin (), dstPorts.end ());
509
- ports.insert (ERSPAN_PORT_NAME );
511
+ ports.insert (ERSPAN_PORT_PREFIX + name );
510
512
for (const auto & port : ports) {
511
513
portUuidMap.emplace (port, " " );
512
514
}
@@ -518,54 +520,56 @@ bool JsonRpc::createMirror(const string& brUuid, const string& name, const set<s
518
520
// src ports
519
521
set<tuple<string,string>> rdata;
520
522
populatePortUuids (srcPorts, portUuidMap, rdata);
523
+ tuples.reserve (rdata.size ());
521
524
for (auto pair : rdata) {
522
- tuples.emplace_back (get<0 >(pair).c_str (), get<1 >(pair).c_str ());
525
+ LOG (INFO) << " entry " << get<0 >(pair).c_str () << " - " << get<1 >(pair).c_str ();
526
+ const string val = get<1 >(pair);
527
+ tuples.emplace_back (get<0 >(pair).c_str (), val);
523
528
}
529
+ LOG (INFO) << " mirror src_port size " << tuples.size ();
524
530
TupleDataSet tdSet (tuples, " set" );
525
- msg1.rows .emplace (" select_src_port" , tdSet);
531
+ msg1.rowData .emplace (" select_src_port" , tdSet);
526
532
527
533
// dst ports
528
534
rdata.clear ();
529
535
tuples.clear ();
530
536
populatePortUuids (dstPorts, portUuidMap, rdata);
531
537
for (auto pair : rdata) {
532
- tuples.emplace_back (get<0 >(pair).c_str (), get<1 >(pair).c_str ());
538
+ LOG (INFO) << " entry " << get<0 >(pair).c_str () << " - " << get<1 >(pair).c_str ();
539
+ const string val = get<1 >(pair);
540
+ tuples.emplace_back (get<0 >(pair).c_str (), val);
533
541
}
542
+ LOG (INFO) << " mirror dst_port size " << tuples.size ();
534
543
tdSet = TupleDataSet (tuples, " set" );
535
- msg1.rows .emplace (" select_dst_port" , tdSet);
544
+ msg1.rowData .emplace (" select_dst_port" , tdSet);
536
545
537
546
// output ports
547
+ string outputPortUuid = portUuidMap[ERSPAN_PORT_PREFIX + name];
548
+ LOG (WARNING) << " output port uuid " << outputPortUuid;
549
+
538
550
tuples.clear ();
539
- rdata.clear ();
540
- ports.clear ();
541
- ports.insert (ERSPAN_PORT_NAME);
542
- populatePortUuids (ports, portUuidMap, rdata);
543
- for (auto pair : rdata) {
544
- tuples.emplace_back (get<0 >(pair).c_str (), get<1 >(pair).c_str ());
545
- }
546
- tdSet = TupleDataSet (tuples, " set" );
547
- msg1.rows .emplace (" output_port" , tdSet);
551
+ tuples.emplace_back (" uuid" , outputPortUuid);
552
+ tdSet = TupleDataSet (tuples);
553
+ msg1.rowData .emplace (" output_port" , tdSet);
548
554
549
555
// name
550
556
tuples.clear ();
551
557
tuples.emplace_back (" " , name);
552
558
tdSet = TupleDataSet (tuples);
553
- msg1.rows .emplace (" name" , tdSet);
559
+ msg1.rowData .emplace (" name" , tdSet);
554
560
555
561
const string uuid_name = " mirror1" ;
556
562
msg1.kvPairs .emplace_back (" uuid-name" , uuid_name);
557
563
558
564
// msg2
559
- tuple<string, string, string> cond1 (" _uuid" , " ==" , brUuid);
560
- set<tuple<string, string, string>> condSet;
561
- condSet.emplace (cond1);
562
-
563
565
tuples.clear ();
564
566
JsonRpcTransactMessage msg2 (OvsdbOperation::UPDATE, OvsdbTable::BRIDGE);
567
+ set<tuple<string, string, string>> condSet;
568
+ condSet.emplace (" _uuid" , " ==" , brUuid);
565
569
msg2.conditions = condSet;
566
570
tuples.emplace_back (" named-uuid" , uuid_name);
567
571
tdSet = TupleDataSet (tuples);
568
- msg2.rows .emplace (" mirrors" , tdSet);
572
+ msg2.rowData .emplace (" mirrors" , tdSet);
569
573
570
574
const list<JsonRpcTransactMessage> requests = {msg1};
571
575
if (!sendRequestAndAwaitResponse (requests)) {
@@ -580,7 +584,7 @@ bool JsonRpc::addErspanPort(const string& bridge, erspan_ifc& port) {
580
584
vector<TupleData> tuples;
581
585
tuples.emplace_back (" " , port.name );
582
586
TupleDataSet tdSet (tuples);
583
- msg1.rows .emplace (" name" , tdSet);
587
+ msg1.rowData .emplace (" name" , tdSet);
584
588
585
589
// uuid-name
586
590
const string uuid_name = " port1" ;
@@ -591,7 +595,7 @@ bool JsonRpc::addErspanPort(const string& bridge, erspan_ifc& port) {
591
595
const string named_uuid = " interface1" ;
592
596
tuples.emplace_back (" named-uuid" , named_uuid);
593
597
tdSet = TupleDataSet (tuples);
594
- msg1.rows .emplace (" interfaces" , tdSet);
598
+ msg1.rowData .emplace (" interfaces" , tdSet);
595
599
596
600
// uuid-name
597
601
JsonRpcTransactMessage msg2 (OvsdbOperation::INSERT, OvsdbTable::INTERFACE);
@@ -602,7 +606,14 @@ bool JsonRpc::addErspanPort(const string& bridge, erspan_ifc& port) {
602
606
tuples.clear ();
603
607
tuples.emplace_back (" " , port.name );
604
608
tdSet = TupleDataSet (tuples);
605
- msg2.rows .emplace (" name" , tdSet);
609
+ msg2.rowData .emplace (" name" , tdSet);
610
+
611
+ tuples.clear ();
612
+ const string typeString (" erspan" );
613
+ TupleData typeData (" " , typeString);
614
+ tuples.push_back (typeData);
615
+ tdSet = TupleDataSet (tuples);
616
+ msg2.rowData .emplace (" type" , tdSet);
606
617
607
618
// options depend upon version
608
619
tuples.clear ();
@@ -619,22 +630,13 @@ bool JsonRpc::addErspanPort(const string& bridge, erspan_ifc& port) {
619
630
std::to_string (static_cast <erspan_ifc_v2&>(port).erspan_dir ));
620
631
}
621
632
tdSet = TupleDataSet (tuples, " map" );
622
- msg2.rows .emplace (" options" , tdSet);
623
-
624
- // type
625
- tuples.clear ();
626
- tuples.emplace_back (" " , " erspan" );
627
- tdSet = TupleDataSet (tuples);
628
- msg2.rows .emplace (" type" , tdSet);
633
+ msg2.rowData .emplace (" options" , tdSet);
629
634
630
635
// get bridge port list and add erspan port to it.
631
636
BrPortResult res;
632
637
if (!getBridgePortList (bridge, res)) {
633
638
return false ;
634
639
}
635
- tuple<string, string, string> cond1 (" _uuid" , " ==" , res.brUuid );
636
- set<tuple<string, string, string>> condSet;
637
- condSet.emplace (cond1);
638
640
639
641
JsonRpcTransactMessage msg3 (OvsdbOperation::UPDATE, OvsdbTable::BRIDGE);
640
642
tuples.clear ();
@@ -643,7 +645,10 @@ bool JsonRpc::addErspanPort(const string& bridge, erspan_ifc& port) {
643
645
}
644
646
tuples.emplace_back (" named-uuid" , uuid_name);
645
647
tdSet = TupleDataSet (tuples, " set" );
646
- msg3.rows .emplace (" ports" , tdSet);
648
+ msg3.rowData .emplace (" ports" , tdSet);
649
+ set<tuple<string, string, string>> condSet;
650
+ condSet.emplace (" _uuid" , " ==" , res.brUuid );
651
+ msg3.conditions = condSet;
647
652
648
653
const list<JsonRpcTransactMessage> requests = {msg1, msg2, msg3};
649
654
if (!sendRequestAndAwaitResponse (requests)) {
@@ -676,18 +681,15 @@ bool JsonRpc::handleCreateMirrorResp(uint64_t reqId, const Document& payload) {
676
681
}
677
682
678
683
bool JsonRpc::deleteMirror (const string& brName) {
679
- list<string> mirList;
680
- tuple<string, string, string> cond1 (" name" , " ==" , brName);
681
- set<tuple<string, string, string>> condSet;
682
- condSet.emplace (cond1);
683
-
684
684
JsonRpcTransactMessage msg (OvsdbOperation::UPDATE, OvsdbTable::BRIDGE);
685
+ set<tuple<string, string, string>> condSet;
686
+ condSet.emplace (" name" , " ==" , brName);
685
687
msg.conditions = condSet;
686
688
687
689
vector<TupleData> tuples;
688
690
TupleDataSet tdSet (tuples, " set" );
689
691
tdSet.label = " set" ;
690
- msg.rows .emplace (" mirrors" , tdSet);
692
+ msg.rowData .emplace (" mirrors" , tdSet);
691
693
692
694
list<JsonRpcTransactMessage> requests = {msg};
693
695
if (!sendRequestAndAwaitResponse (requests)) {
0 commit comments