Skip to content

Commit fa36c11

Browse files
committed
Continue reworking erspan code. Add tests/logs
Signed-off-by: Tom Flynn <tom.flynn@gmail.com> Change-Id: I5c1ee19000d0786c10c88c084b82c957c9c03241
1 parent d975bcd commit fa36c11

14 files changed

+119
-155
lines changed

agent-ovs/Makefile.am

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,6 @@ if RENDERER_OVS
435435
ovs/test/include/MockPortMapper.h \
436436
ovs/test/include/MockFlowExecutor.h \
437437
ovs/test/include/MockFlowReader.h \
438-
ovs/test/include/MockJsonRpc.h \
439438
ovs/test/include/MockRpcConnection.h \
440439
ovs/test/include/MockSwitchManager.h \
441440
ovs/test/include/FlowManagerFixture.h \

agent-ovs/lib/include/opflexagent/SpanManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ class SpanManager {
196196

197197
/**
198198
* get the URI of the parent of LocalEp object
199-
* @param lEp shared pointer to a LocalEpp object
199+
* @param localEp shared pointer to a LocalEpp object
200200
* @return optional URI reference
201201
*/
202202
static const optional<URI> getSession(const shared_ptr<LocalEp>& localEp);

agent-ovs/lib/test/SpanManager_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ static bool checkSpan(boost::optional<shared_ptr<SessionState>> pSess,
145145
}
146146

147147
static bool checkSrcEps(boost::optional<shared_ptr<SessionState>> pSess,
148-
shared_ptr<span::SrcMember> srcMem, shared_ptr<L2Ep> l2e) {
148+
shared_ptr<span::SrcMember>& srcMem, shared_ptr<L2Ep>& l2e) {
149149
if (!pSess) {
150150
return false;
151151
}

agent-ovs/ovs/JsonRpc.cpp

Lines changed: 70 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -43,31 +43,30 @@ bool JsonRpc::createNetFlow(const string& brUuid, const string& target, const in
4343
tuples.emplace_back("", target);
4444
TupleDataSet tdSet(tuples);
4545
JsonRpcTransactMessage msg1(OvsdbOperation::INSERT, OvsdbTable::NETFLOW);
46-
msg1.rows["targets"] = tdSet;
46+
msg1.rowData["targets"] = tdSet;
4747

4848
tuples.clear();
4949
tuples.emplace_back("", timeout);
5050
tdSet = TupleDataSet(tuples);
51-
msg1.rows["active_timeout"] = tdSet;
51+
msg1.rowData["active_timeout"] = tdSet;
5252

5353
tuples.clear();
5454
tuples.emplace_back("", addidtointerface);
5555
tdSet = TupleDataSet(tuples);
56-
msg1.rows["add_id_to_interface"] = tdSet;
56+
msg1.rowData["add_id_to_interface"] = tdSet;
5757

5858
const string uuid_name = "netflow1";
5959
msg1.kvPairs.emplace_back("uuid-name", uuid_name);
6060

6161
JsonRpcTransactMessage msg2(OvsdbOperation::UPDATE, OvsdbTable::BRIDGE);
62-
tuple<string, string, string> cond1("_uuid", "==", brUuid);
6362
set<tuple<string, string, string>> condSet;
64-
condSet.emplace(cond1);
63+
condSet.emplace("_uuid", "==", brUuid);
6564
msg2.conditions = condSet;
6665

6766
tuples.clear();
6867
tuples.emplace_back("named-uuid", uuid_name);
6968
tdSet = TupleDataSet(tuples);
70-
msg2.rows.emplace("netflow", tdSet);
69+
msg2.rowData.emplace("netflow", tdSet);
7170

7271
const list<JsonRpcTransactMessage> requests = {msg1, msg2};
7372
if (!sendRequestAndAwaitResponse(requests)) {
@@ -82,12 +81,12 @@ bool JsonRpc::createIpfix(const string& brUuid, const string& target, const int&
8281
tuples.emplace_back("", target);
8382
TupleDataSet tdSet(tuples);
8483
JsonRpcTransactMessage msg1(OvsdbOperation::INSERT, OvsdbTable::IPFIX);
85-
msg1.rows.emplace("targets", tdSet);
84+
msg1.rowData.emplace("targets", tdSet);
8685
if (sampling != 0) {
8786
tuples.clear();
8887
tuples.emplace_back("", sampling);
8988
tdSet = TupleDataSet(tuples);
90-
msg1.rows.emplace("sampling", tdSet);
89+
msg1.rowData.emplace("sampling", tdSet);
9190
}
9291
const string uuid_name = "ipfix1";
9392
msg1.kvPairs.emplace_back("uuid-name", uuid_name);
@@ -100,7 +99,7 @@ bool JsonRpc::createIpfix(const string& brUuid, const string& target, const int&
10099
tuples.clear();
101100
tuples.emplace_back("named-uuid", uuid_name);
102101
tdSet = TupleDataSet(tuples);
103-
msg2.rows.emplace("ipfix", tdSet);
102+
msg2.rowData.emplace("ipfix", tdSet);
104103

105104
const list<JsonRpcTransactMessage> requests = {msg1, msg2};
106105
if (!sendRequestAndAwaitResponse(requests)) {
@@ -111,15 +110,14 @@ bool JsonRpc::createIpfix(const string& brUuid, const string& target, const int&
111110
}
112111

113112
bool JsonRpc::deleteNetFlow(const string& brName) {
113+
JsonRpcTransactMessage msg1(OvsdbOperation::UPDATE, OvsdbTable::BRIDGE);
114114
set<tuple<string, string, string>> condSet;
115115
condSet.emplace("name", "==", brName);
116-
117-
JsonRpcTransactMessage msg1(OvsdbOperation::UPDATE, OvsdbTable::BRIDGE);
118116
msg1.conditions = condSet;
119117

120118
vector<TupleData> tuples;
121119
TupleDataSet tdSet(tuples, "set");
122-
msg1.rows.emplace("netflow", tdSet);
120+
msg1.rowData.emplace("netflow", tdSet);
123121

124122
list<JsonRpcTransactMessage> requests = {msg1};
125123
if (!sendRequestAndAwaitResponse(requests)) {
@@ -130,16 +128,14 @@ bool JsonRpc::deleteNetFlow(const string& brName) {
130128
}
131129

132130
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-
137131
JsonRpcTransactMessage msg1(OvsdbOperation::UPDATE, OvsdbTable::BRIDGE);
132+
set<tuple<string, string, string>> condSet;
133+
condSet.emplace("name", "==", brName);
138134
msg1.conditions = condSet;
139135

140136
vector<TupleData> tuples;
141137
TupleDataSet tdSet(tuples, "set");
142-
msg1.rows.emplace("ipfix", tdSet);
138+
msg1.rowData.emplace("ipfix", tdSet);
143139

144140
const list<JsonRpcTransactMessage> requests = {msg1};
145141
if (!sendRequestAndAwaitResponse(requests)) {
@@ -179,11 +175,12 @@ bool JsonRpc::updateBridgePorts(
179175
condSet.emplace("_uuid", "==", brUuid);
180176
msg1.conditions = condSet;
181177
vector<TupleData> tuples;
178+
tuples.reserve(brPorts.size());
182179
for (auto& elem : brPorts) {
183180
tuples.emplace_back("uuid", elem);
184181
}
185182
TupleDataSet tdSet(tuples, "set");
186-
msg1.rows.emplace("ports", tdSet);
183+
msg1.rowData.emplace("ports", tdSet);
187184

188185
const list<JsonRpcTransactMessage> requests = {msg1};
189186
if (!sendRequestAndAwaitResponse(requests)) {
@@ -229,6 +226,7 @@ bool JsonRpc::handleGetBridgePortList(uint64_t reqId, const Document& payload, B
229226
}
230227

231228
void JsonRpc::getUuidsFromVal(set<string>& uuidSet, const Document& payload, const string& index) {
229+
LOG(INFO) << "getUuidsFromVal with index " << index;
232230
list<string> ids = {"0","rows","0",index,"0"};
233231
Value val;
234232
opflexagent::getValue(payload, ids, val);
@@ -253,10 +251,9 @@ void JsonRpc::getUuidsFromVal(set<string>& uuidSet, const Document& payload, con
253251
}
254252

255253
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);
259254
JsonRpcTransactMessage msg1(OvsdbOperation::SELECT, OvsdbTable::BRIDGE);
255+
set<tuple<string, string, string>> condSet;
256+
condSet.emplace("name", "==", bridge);
260257
msg1.conditions = condSet;
261258
msg1.columns.emplace("ports");
262259
msg1.columns.emplace("_uuid");
@@ -284,7 +281,7 @@ bool JsonRpc::getOvsdbMirrorConfig(mirror& mir) {
284281
set<string> uuids;
285282
uuids.insert(mir.src_ports.begin(), mir.src_ports.end());
286283
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);
288285

289286
JsonRpcTransactMessage msg2(OvsdbOperation::SELECT, OvsdbTable::PORT);
290287
msg2.columns.emplace("name");
@@ -302,14 +299,18 @@ bool JsonRpc::getOvsdbMirrorConfig(mirror& mir) {
302299
//replace port UUIDs with names in the mirror struct
303300
substituteSet(mir.src_ports, portMap);
304301
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+
}
306307
return true;
307308
}
308309

309310
bool JsonRpc::getCurrentErspanParams(const string& portName, erspan_ifc& params) {
310311
// for ERSPAN port get IP address
311312
JsonRpcTransactMessage msg1(OvsdbOperation::SELECT, OvsdbTable::INTERFACE);
312-
tuple<string, string, string> cond1("name", "==", ERSPAN_PORT_NAME);
313+
tuple<string, string, string> cond1("name", "==", portName);
313314
set<tuple<string, string, string>> condSet;
314315
condSet.emplace(cond1);
315316
msg1.conditions = condSet;
@@ -360,7 +361,9 @@ bool JsonRpc::handleMirrorConfig(uint64_t reqId, const Document& payload, mirror
360361
uuids.clear();
361362
getUuidsFromVal(uuids, payload, "output_port");
362363

363-
mir.out_ports.insert(uuids.begin(), uuids.end());
364+
if (!uuids.empty()) {
365+
mir.out_port = *(uuids.begin());
366+
}
364367
return true;
365368
}
366369

@@ -474,10 +477,9 @@ void JsonRpc::getPortUuids(map<string, string>& ports) {
474477
}
475478

476479
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);
480480
JsonRpcTransactMessage msg1(OvsdbOperation::SELECT, OvsdbTable::BRIDGE);
481+
set<tuple<string, string, string>> condSet;
482+
condSet.emplace("name", "==", name);
481483
msg1.conditions = condSet;
482484
msg1.columns.emplace("_uuid");
483485

@@ -506,7 +508,7 @@ bool JsonRpc::createMirror(const string& brUuid, const string& name, const set<s
506508
set<string> ports;
507509
ports.insert(srcPorts.begin(), srcPorts.end());
508510
ports.insert(dstPorts.begin(), dstPorts.end());
509-
ports.insert(ERSPAN_PORT_NAME);
511+
ports.insert(ERSPAN_PORT_PREFIX + name);
510512
for (const auto& port : ports) {
511513
portUuidMap.emplace(port, "");
512514
}
@@ -518,54 +520,56 @@ bool JsonRpc::createMirror(const string& brUuid, const string& name, const set<s
518520
// src ports
519521
set<tuple<string,string>> rdata;
520522
populatePortUuids(srcPorts, portUuidMap, rdata);
523+
tuples.reserve(rdata.size());
521524
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);
523528
}
529+
LOG(INFO) << "mirror src_port size " << tuples.size();
524530
TupleDataSet tdSet(tuples, "set");
525-
msg1.rows.emplace("select_src_port", tdSet);
531+
msg1.rowData.emplace("select_src_port", tdSet);
526532

527533
// dst ports
528534
rdata.clear();
529535
tuples.clear();
530536
populatePortUuids(dstPorts, portUuidMap, rdata);
531537
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);
533541
}
542+
LOG(INFO) << "mirror dst_port size " << tuples.size();
534543
tdSet = TupleDataSet(tuples, "set");
535-
msg1.rows.emplace("select_dst_port", tdSet);
544+
msg1.rowData.emplace("select_dst_port", tdSet);
536545

537546
// output ports
547+
string outputPortUuid = portUuidMap[ERSPAN_PORT_PREFIX + name];
548+
LOG(WARNING) << "output port uuid " << outputPortUuid;
549+
538550
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);
548554

549555
// name
550556
tuples.clear();
551557
tuples.emplace_back("", name);
552558
tdSet = TupleDataSet(tuples);
553-
msg1.rows.emplace("name", tdSet);
559+
msg1.rowData.emplace("name", tdSet);
554560

555561
const string uuid_name = "mirror1";
556562
msg1.kvPairs.emplace_back("uuid-name", uuid_name);
557563

558564
// msg2
559-
tuple<string, string, string> cond1("_uuid", "==", brUuid);
560-
set<tuple<string, string, string>> condSet;
561-
condSet.emplace(cond1);
562-
563565
tuples.clear();
564566
JsonRpcTransactMessage msg2(OvsdbOperation::UPDATE, OvsdbTable::BRIDGE);
567+
set<tuple<string, string, string>> condSet;
568+
condSet.emplace("_uuid", "==", brUuid);
565569
msg2.conditions = condSet;
566570
tuples.emplace_back("named-uuid", uuid_name);
567571
tdSet = TupleDataSet(tuples);
568-
msg2.rows.emplace("mirrors", tdSet);
572+
msg2.rowData.emplace("mirrors", tdSet);
569573

570574
const list<JsonRpcTransactMessage> requests = {msg1};
571575
if (!sendRequestAndAwaitResponse(requests)) {
@@ -580,7 +584,7 @@ bool JsonRpc::addErspanPort(const string& bridge, erspan_ifc& port) {
580584
vector<TupleData> tuples;
581585
tuples.emplace_back("", port.name);
582586
TupleDataSet tdSet(tuples);
583-
msg1.rows.emplace("name", tdSet);
587+
msg1.rowData.emplace("name", tdSet);
584588

585589
// uuid-name
586590
const string uuid_name = "port1";
@@ -591,7 +595,7 @@ bool JsonRpc::addErspanPort(const string& bridge, erspan_ifc& port) {
591595
const string named_uuid = "interface1";
592596
tuples.emplace_back("named-uuid", named_uuid);
593597
tdSet = TupleDataSet(tuples);
594-
msg1.rows.emplace("interfaces", tdSet);
598+
msg1.rowData.emplace("interfaces", tdSet);
595599

596600
// uuid-name
597601
JsonRpcTransactMessage msg2(OvsdbOperation::INSERT, OvsdbTable::INTERFACE);
@@ -602,7 +606,14 @@ bool JsonRpc::addErspanPort(const string& bridge, erspan_ifc& port) {
602606
tuples.clear();
603607
tuples.emplace_back("", port.name);
604608
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);
606617

607618
// options depend upon version
608619
tuples.clear();
@@ -619,22 +630,13 @@ bool JsonRpc::addErspanPort(const string& bridge, erspan_ifc& port) {
619630
std::to_string(static_cast<erspan_ifc_v2&>(port).erspan_dir));
620631
}
621632
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);
629634

630635
// get bridge port list and add erspan port to it.
631636
BrPortResult res;
632637
if (!getBridgePortList(bridge, res)) {
633638
return false;
634639
}
635-
tuple<string, string, string> cond1("_uuid", "==", res.brUuid);
636-
set<tuple<string, string, string>> condSet;
637-
condSet.emplace(cond1);
638640

639641
JsonRpcTransactMessage msg3(OvsdbOperation::UPDATE, OvsdbTable::BRIDGE);
640642
tuples.clear();
@@ -643,7 +645,10 @@ bool JsonRpc::addErspanPort(const string& bridge, erspan_ifc& port) {
643645
}
644646
tuples.emplace_back("named-uuid", uuid_name);
645647
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;
647652

648653
const list<JsonRpcTransactMessage> requests = {msg1, msg2, msg3};
649654
if (!sendRequestAndAwaitResponse(requests)) {
@@ -676,18 +681,15 @@ bool JsonRpc::handleCreateMirrorResp(uint64_t reqId, const Document& payload) {
676681
}
677682

678683
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-
684684
JsonRpcTransactMessage msg(OvsdbOperation::UPDATE, OvsdbTable::BRIDGE);
685+
set<tuple<string, string, string>> condSet;
686+
condSet.emplace("name", "==", brName);
685687
msg.conditions = condSet;
686688

687689
vector<TupleData> tuples;
688690
TupleDataSet tdSet(tuples, "set");
689691
tdSet.label = "set";
690-
msg.rows.emplace("mirrors", tdSet);
692+
msg.rowData.emplace("mirrors", tdSet);
691693

692694
list<JsonRpcTransactMessage> requests = {msg};
693695
if (!sendRequestAndAwaitResponse(requests)) {

0 commit comments

Comments
 (0)