-
Notifications
You must be signed in to change notification settings - Fork 545
/
mclaglink.cpp
1962 lines (1643 loc) · 66.3 KB
/
mclaglink.cpp
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
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Copyright(c) 2016-2019 Nephos.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, see <http://www.gnu.org/licenses/>.
*
* The full GNU General Public License is included in this distribution in
* the file called "COPYING".
*
* Maintainer: Jim Jiang from nephos
*/
#include <string.h>
#include <errno.h>
#include <system_error>
#include <stdlib.h>
#include <iostream>
#include "logger.h"
#include "tokenize.h"
#include "netmsg.h"
#include "netdispatcher.h"
#include "swss/notificationproducer.h"
#include "mclagsyncd/mclaglink.h"
#include "mclagsyncd/mclag.h"
#include <set>
#include <unordered_set>
#include <algorithm>
#include "macaddress.h"
#include <string>
#include <iosfwd>
#include <iostream>
#include <sstream>
#include "table.h"
using namespace swss;
using namespace std;
void MclagLink::addVlanMbr(std::string vlan, std::string mbr_port)
{
m_vlan_mbrship.emplace(vlan_mbr(vlan,mbr_port));
}
//returns 1 if present, else returns zero
int MclagLink::findVlanMbr(std::string vlan, std::string mbr_port)
{
return (m_vlan_mbrship.find(vlan_mbr(vlan,mbr_port)) != m_vlan_mbrship.end());
}
void MclagLink::delVlanMbr(std::string vlan, std::string mbr_port)
{
m_vlan_mbrship.erase(vlan_mbr(vlan,mbr_port));
}
void MclagLink::getOidToPortNameMap(std::unordered_map<std::string, std:: string> & port_map)
{
auto hash = p_counters_db->hgetall("COUNTERS_PORT_NAME_MAP");
for (auto it = hash.begin(); it != hash.end(); ++it)
port_map.insert(pair<string, string>(it->second, it->first));
return;
}
void MclagLink::getBridgePortIdToAttrPortIdMap(std::map<std::string, std:: string> *oid_map)
{
std::string bridge_port_id;
size_t pos1 = 0;
auto keys = p_asic_db->keys("ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT:*");
for (auto& key : keys)
{
pos1 = key.find("oid:", 0);
bridge_port_id = key.substr(pos1);
auto hash = p_asic_db->hgetall(key);
auto attr_port_id = hash.find("SAI_BRIDGE_PORT_ATTR_PORT_ID");
if (attr_port_id == hash.end())
{
attr_port_id = hash.find("SAI_BRIDGE_PORT_ATTR_TUNNEL_ID");
if (attr_port_id == hash.end())
continue;
}
oid_map->insert(pair<string, string>(bridge_port_id, attr_port_id->second));
}
return;
}
void MclagLink::getVidByBvid(std::string &bvid, std::string &vlanid)
{
std::string pre = "ASIC_STATE:SAI_OBJECT_TYPE_VLAN:";
std::string key = pre + bvid;
auto hash = p_asic_db->hgetall(key.c_str());
auto attr_vlan_id = hash.find("SAI_VLAN_ATTR_VLAN_ID");
if (attr_vlan_id == hash.end())
return;
vlanid = attr_vlan_id->second;
return;
}
void MclagLink::mclagsyncdFetchSystemMacFromConfigdb()
{
vector<FieldValueTuple> fvs;
p_device_metadata_tbl->get("localhost",fvs);
auto it = find_if(fvs.begin(), fvs.end(), [](const FieldValueTuple &fv) {
return fv.first == "mac";
});
if (it == fvs.end())
{
SWSS_LOG_ERROR("mclagsyncd: Failed to get MAC address from configuration database");
return;
}
m_system_mac = it->second;
SWSS_LOG_NOTICE("mclagysncd: system_mac:%s ",m_system_mac.c_str());
return;
}
void MclagLink::mclagsyncdFetchMclagConfigFromConfigdb()
{
TableDump mclag_cfg_dump;
SWSS_LOG_NOTICE("mclag cfg dump....");
p_mclag_cfg_table->dump(mclag_cfg_dump);
std::deque<KeyOpFieldsValuesTuple> entries;
for (const auto&key: mclag_cfg_dump)
{
KeyOpFieldsValuesTuple cfgentry;
SWSS_LOG_NOTICE("Key: %s", key.first.c_str());
kfvKey(cfgentry) = key.first;
kfvOp(cfgentry) = "SET";
SWSS_LOG_NOTICE("Value:");
for (const auto& val : key.second) {
SWSS_LOG_NOTICE("%s: %s", val.first.c_str(), val.second.c_str());
FieldValueTuple value;
fvField(value) = val.first;
fvValue(value) = val.second;
kfvFieldsValues(cfgentry).push_back(value);
}
entries.push_back(cfgentry);
processMclagDomainCfg(entries);
}
}
void MclagLink::mclagsyncdFetchMclagInterfaceConfigFromConfigdb()
{
TableDump mclag_intf_cfg_dump;
SWSS_LOG_NOTICE("mclag cfg dump....");
p_mclag_intf_cfg_table->dump(mclag_intf_cfg_dump);
std::deque<KeyOpFieldsValuesTuple> entries;
for (const auto&key: mclag_intf_cfg_dump)
{
KeyOpFieldsValuesTuple cfgentry;
SWSS_LOG_NOTICE("Key: %s", key.first.c_str());
kfvKey(cfgentry) = key.first;
kfvOp(cfgentry) = "SET";
SWSS_LOG_NOTICE("Value:");
for (const auto& val : key.second) {
SWSS_LOG_NOTICE("%s: %s", val.first.c_str(), val.second.c_str());
FieldValueTuple value;
fvField(value) = val.first;
fvValue(value) = val.second;
kfvFieldsValues(cfgentry).push_back(value);
}
entries.push_back(cfgentry);
mclagsyncdSendMclagIfaceCfg(entries);
}
}
void MclagLink::setPortIsolate(char *msg)
{
static const unordered_set<string> supported {
BRCM_PLATFORM_SUBSTRING,
BFN_PLATFORM_SUBSTRING,
CTC_PLATFORM_SUBSTRING,
MRVL_PRST_PLATFORM_SUBSTRING
};
const char *platform = getenv("platform");
if (platform != nullptr && supported.find(string(platform)) != supported.end())
{
mclag_sub_option_hdr_t *op_hdr = NULL;
string isolate_src_port;
string isolate_dst_port;
char * cur = NULL;
vector<FieldValueTuple> fvts;
cur = msg;
/*get isolate src port infor*/
op_hdr = reinterpret_cast<mclag_sub_option_hdr_t *>(static_cast<void *>(cur));
cur = cur + MCLAG_SUB_OPTION_HDR_LEN;
isolate_src_port.insert(0, (const char*)cur, op_hdr->op_len);
cur = cur + op_hdr->op_len;
/*get isolate dst ports infor*/
op_hdr = reinterpret_cast<mclag_sub_option_hdr_t *>(static_cast<void *>(cur));
cur = cur + MCLAG_SUB_OPTION_HDR_LEN;
if (op_hdr->op_len == 0)
{
/*Destination port can be empty when all remote MLAG interfaces
* goes down down or ICCP session goes down. Do not delete the
* isolation group when all remote interfaces are down. Just remove
* all destination ports from the group
*/
if (is_iccp_up)
{
fvts.emplace_back("DESCRIPTION", "Isolation group for MCLAG");
fvts.emplace_back("TYPE", "bridge-port");
fvts.emplace_back("PORTS", isolate_src_port);
fvts.emplace_back("MEMBERS", isolate_dst_port);
p_iso_grp_tbl->set("MCLAG_ISO_GRP", fvts);
SWSS_LOG_NOTICE("Delete all isolation group destination ports");
}
else
{
p_iso_grp_tbl->del("MCLAG_ISO_GRP");
SWSS_LOG_NOTICE("Isolation group deleted");
}
}
else
{
string temp;
isolate_dst_port.insert(0, (const char*)cur, op_hdr->op_len);
istringstream dst_ss(isolate_dst_port);
isolate_dst_port.clear();
while (getline(dst_ss, temp, ','))
{
if (0 == temp.find("Ethernet"))
{
continue;
}
if (isolate_dst_port.length())
{
isolate_dst_port = isolate_dst_port + ',' + temp;
}
else
{
isolate_dst_port = temp;
}
}
fvts.emplace_back("DESCRIPTION", "Isolation group for MCLAG");
fvts.emplace_back("TYPE", "bridge-port");
fvts.emplace_back("PORTS", isolate_src_port);
fvts.emplace_back("MEMBERS", isolate_dst_port);
p_iso_grp_tbl->set("MCLAG_ISO_GRP", fvts);
SWSS_LOG_NOTICE("Isolation group created with ports %s and members %s",
isolate_src_port.c_str(),
isolate_dst_port.c_str());
}
}
else
{
mclag_sub_option_hdr_t *op_hdr = NULL;
string isolate_src_port;
string isolate_dst_port;
char * cur = NULL;
string acl_name = "mclag";
string acl_rule_name = "mclag:mclag";
vector<FieldValueTuple> acl_attrs;
vector<FieldValueTuple> acl_rule_attrs;
std::string acl_key = std::string("") + APP_ACL_TABLE_TABLE_NAME + ":" + acl_name;
std::string acl_rule_key = std::string("") + APP_ACL_RULE_TABLE_NAME + ":" + acl_rule_name;
static int acl_table_is_added = 0;
cur = msg;
/*get isolate src port infor*/
op_hdr = reinterpret_cast<mclag_sub_option_hdr_t *>(static_cast<void *>(cur));
cur = cur + MCLAG_SUB_OPTION_HDR_LEN;
isolate_src_port.insert(0, (const char*)cur, op_hdr->op_len);
cur = cur + op_hdr->op_len;
/*get isolate dst ports infor*/
op_hdr = reinterpret_cast<mclag_sub_option_hdr_t *>(static_cast<void *>(cur));
cur = cur + MCLAG_SUB_OPTION_HDR_LEN;
isolate_dst_port.insert(0, (const char*)cur, op_hdr->op_len);
if (op_hdr->op_len == 0)
{
/* If dst port is NULL, delete the acl table 'mclag' */
p_acl_table_tbl->del(acl_name);
acl_table_is_added = 0;
SWSS_LOG_NOTICE("set port isolate, src port: %s, dst port is NULL",
isolate_src_port.c_str());
return;
}
SWSS_LOG_NOTICE("set port isolate, src port: %s, dst port: %s",
isolate_src_port.c_str(), isolate_dst_port.c_str());
if (acl_table_is_added == 0)
{
/*First create ACL table*/
FieldValueTuple desc_attr("policy_desc", "Mclag egress port isolate acl");
acl_attrs.push_back(desc_attr);
FieldValueTuple type_attr("type", "L3");
acl_attrs.push_back(type_attr);
FieldValueTuple port_attr("ports", isolate_src_port);
acl_attrs.push_back(port_attr);
p_acl_table_tbl->set(acl_name, acl_attrs);
acl_table_is_added = 1;
/*End create ACL table*/
}
/*Then create ACL rule table*/
FieldValueTuple ip_type_attr("IP_TYPE", "ANY");
acl_rule_attrs.push_back(ip_type_attr);
string temp;
istringstream dst_ss(isolate_dst_port);
isolate_dst_port.clear();
while (getline(dst_ss, temp, ','))
{
if (0 == temp.find("PortChannel"))
{
continue;
}
if (isolate_dst_port.length())
{
isolate_dst_port = isolate_dst_port + ',' + temp;
}
else
{
isolate_dst_port = temp;
}
}
FieldValueTuple out_port_attr("OUT_PORTS", isolate_dst_port);
acl_rule_attrs.push_back(out_port_attr);
FieldValueTuple packet_attr("PACKET_ACTION", "DROP");
acl_rule_attrs.push_back(packet_attr);
p_acl_rule_tbl->set(acl_rule_name, acl_rule_attrs);
/*End create ACL rule table*/
}
return;
}
void MclagLink::setPortMacLearnMode(char *msg)
{
string learn_port;
string learn_mode;
mclag_sub_option_hdr_t *op_hdr = NULL;
char * cur = NULL;
cur = msg;
/*get port learning mode info*/
op_hdr = reinterpret_cast<mclag_sub_option_hdr_t *>(static_cast<void *>(cur));
if (op_hdr->op_type == MCLAG_SUB_OPTION_TYPE_MAC_LEARN_ENABLE)
{
learn_mode = "hardware";
}
else if (op_hdr->op_type == MCLAG_SUB_OPTION_TYPE_MAC_LEARN_DISABLE)
{
learn_mode = "disable";
}
cur = cur + MCLAG_SUB_OPTION_HDR_LEN;
learn_port.insert(0, (const char*)cur, op_hdr->op_len);
vector<FieldValueTuple> attrs;
FieldValueTuple learn_attr("learn_mode", learn_mode);
attrs.push_back(learn_attr);
if (strncmp(learn_port.c_str(), PORTCHANNEL_PREFIX, strlen(PORTCHANNEL_PREFIX)) == 0)
p_lag_tbl->set(learn_port, attrs);
/* vxlan tunnel is currently not supported, for src_ip is the mandatory attribute */
/* else if(strncmp(learn_port.c_str(),VXLAN_TUNNEL_PREFIX,5)==0)
p_tnl_tbl->set(learn_port, attrs); */
else
p_port_tbl->set(learn_port, attrs);
SWSS_LOG_NOTICE("set port mac learn mode, port: %s, learn-mode: %s",
learn_port.c_str(), learn_mode.c_str());
return;
}
void MclagLink::setFdbFlush()
{
swss::NotificationProducer flushFdb(p_appl_db.get(), "FLUSHFDBREQUEST");
vector<FieldValueTuple> values;
SWSS_LOG_NOTICE("send fdb flush notification");
flushFdb.send("ALL", "ALL", values);
return;
}
void MclagLink::setIntfMac(char *msg)
{
mclag_sub_option_hdr_t *op_hdr = NULL;
string intf_key;
string mac_value;
char *cur = NULL;
cur = msg;
/*get intf key name*/
op_hdr = reinterpret_cast<mclag_sub_option_hdr_t *>(static_cast<void *>(cur));
cur = cur + MCLAG_SUB_OPTION_HDR_LEN;
intf_key.insert(0, (const char*)cur, op_hdr->op_len);
cur = cur + op_hdr->op_len;
/*get mac*/
op_hdr = reinterpret_cast<mclag_sub_option_hdr_t *>(static_cast<void *>(cur));
cur = cur + MCLAG_SUB_OPTION_HDR_LEN;
mac_value.insert(0, (const char*)cur, op_hdr->op_len);
SWSS_LOG_NOTICE("set mac to chip, intf key name: %s, mac: %s", intf_key.c_str(), mac_value.c_str());
vector<FieldValueTuple> attrs;
FieldValueTuple mac_attr("mac_addr", mac_value);
attrs.push_back(mac_attr);
p_intf_tbl->set(intf_key, attrs);
return;
}
void MclagLink::setFdbEntry(char *msg, int msg_len)
{
struct mclag_fdb_info * fdb_info = NULL;
struct mclag_fdb fdb;
string fdb_key;
char key[64] = { 0 };
char *cur = NULL;
short count = 0;
int index = 0;
cur = msg;
count = (short)(msg_len/sizeof(struct mclag_fdb_info));
for (index =0; index < count; index ++)
{
memset(key, 0, 64);
fdb_info = reinterpret_cast<struct mclag_fdb_info *>(static_cast<void *>(cur + index * sizeof(struct mclag_fdb_info)));
fdb.mac = MacAddress::to_string(fdb_info->mac);
fdb.port_name = fdb_info->port_name;
fdb.vid = fdb_info->vid;
if (fdb_info->type == MCLAG_FDB_TYPE_STATIC)
fdb.type = "static";
else if (fdb_info->type == MCLAG_FDB_TYPE_DYNAMIC)
fdb.type = "dynamic";
else if (fdb_info->type == MCLAG_FDB_TYPE_DYNAMIC_LOCAL)
fdb.type = "dynamic_local";
snprintf(key, 64, "%s%d:%s", "Vlan", fdb_info->vid, fdb.mac.c_str());
fdb_key = key;
SWSS_LOG_DEBUG("Received MAC key: %s, op_type: %d, mac type: %s , port: %s",
fdb_key.c_str(), fdb_info->op_type, fdb.type.c_str(), fdb.port_name.c_str());
if (fdb_info->op_type == MCLAG_FDB_OPER_ADD)
{
vector<FieldValueTuple> attrs;
/*set port attr*/
FieldValueTuple port_attr("port", fdb.port_name);
attrs.push_back(port_attr);
/*set type attr*/
FieldValueTuple type_attr("type", fdb.type);
attrs.push_back(type_attr);
p_fdb_tbl->set(fdb_key, attrs);
SWSS_LOG_NOTICE("add fdb entry into ASIC_DB:key =%s, type =%s", fdb_key.c_str(), fdb.type.c_str());
}
else if (fdb_info->op_type == MCLAG_FDB_OPER_DEL)
{
p_fdb_tbl->del(fdb_key);
SWSS_LOG_NOTICE("del fdb entry from ASIC_DB:key =%s", fdb_key.c_str());
}
}
return;
}
void MclagLink::mclagsyncdSendFdbEntries(std::deque<KeyOpFieldsValuesTuple> &entries)
{
size_t infor_len = sizeof(mclag_msg_hdr_t);
struct mclag_fdb_info info;
mclag_msg_hdr_t * msg_head = NULL;
int count = 0;
ssize_t write = 0;
char *infor_start = m_messageBuffer_send;
/* Nothing popped */
if (entries.empty())
{
return;
}
for (auto entry: entries)
{
memset(&info, 0, sizeof(struct mclag_fdb_info));
count++;
std::string key = kfvKey(entry);
std::string op = kfvOp(entry);
std::size_t delimiter = key.find_first_of(":");
auto vlan_name = key.substr(0, delimiter);
const auto mac_address_str = key.substr(delimiter+1);
uint8_t mac_address[ETHER_ADDR_LEN];
MacAddress::parseMacString(mac_address_str, mac_address);
info.vid = (unsigned int) stoi(vlan_name.substr(4));
memcpy(info.mac, mac_address , ETHER_ADDR_LEN);
if (op == "SET")
info.op_type = MCLAG_FDB_OPER_ADD;
else
info.op_type = MCLAG_FDB_OPER_DEL;
for (auto i : kfvFieldsValues(entry))
{
if (fvField(i) == "port")
{
memcpy(info.port_name, fvValue(i).c_str(), fvValue(i).length());
}
if (fvField(i) == "type")
{
if (fvValue(i) == "dynamic")
info.type = MCLAG_FDB_TYPE_DYNAMIC;
else if (fvValue(i) == "static")
info.type = MCLAG_FDB_TYPE_STATIC;
else
SWSS_LOG_ERROR("MCLAGSYNCD STATE FDB updates key=%s, invalid MAC type %s\n", key.c_str(), fvValue(i).c_str());
}
}
SWSS_LOG_NOTICE("MCLAGSYNCD STATE FDB updates key=%s, operation=%s, type: %d, port: %s \n",
key.c_str(), op.c_str(), info.type, info.port_name);
if (MCLAG_MAX_SEND_MSG_LEN - infor_len < sizeof(struct mclag_fdb_info))
{
msg_head = reinterpret_cast<mclag_msg_hdr_t *>(static_cast<void *>(infor_start));
msg_head->version = 1;
msg_head->msg_len = (unsigned short)infor_len;
msg_head ->msg_type = MCLAG_SYNCD_MSG_TYPE_FDB_OPERATION;
SWSS_LOG_DEBUG("mclagsycnd buffer full send msg to iccpd, msg_len =%d, msg_type =%d count : %d",
msg_head->msg_len, msg_head->msg_type, count);
write = ::write(m_connection_socket, infor_start, msg_head->msg_len);
if (write <= 0)
{
SWSS_LOG_ERROR("mclagsycnd update FDB to ICCPD Buffer full, write to m_connection_socket failed");
}
infor_len = sizeof(mclag_msg_hdr_t);
count = 0;
}
memcpy((char*)(infor_start + infor_len), (char*)&info, sizeof(struct mclag_fdb_info));
infor_len = infor_len + sizeof(struct mclag_fdb_info);
}
if (infor_len <= sizeof(mclag_msg_hdr_t)) /*no fdb entry need notifying iccpd*/
return;
msg_head = reinterpret_cast<mclag_msg_hdr_t *>(static_cast<void *>(infor_start));
msg_head->version = 1;
msg_head->msg_len = (unsigned short)infor_len;
msg_head ->msg_type = MCLAG_SYNCD_MSG_TYPE_FDB_OPERATION;
SWSS_LOG_DEBUG("mclagsycnd send msg to iccpd, msg_len =%d, msg_type =%d count : %d",
msg_head->msg_len, msg_head->msg_type, count);
write = ::write(m_connection_socket, infor_start, msg_head->msg_len);
if (write <= 0)
{
SWSS_LOG_ERROR("mclagsycnd update FDB to ICCPD, write to m_connection_socket failed");
}
return;
}
void MclagLink::processMclagDomainCfg(std::deque<KeyOpFieldsValuesTuple> &entries)
{
char *infor_start = getSendMsgBuffer();
size_t infor_len = sizeof(mclag_msg_hdr_t);
uint8_t system_mac[ETHER_ADDR_LEN];
int add_cfg_dependent_selectables = 0;
int count = 0;
ssize_t write = 0;
struct mclag_domain_cfg_info cfg_info;
mclag_msg_hdr_t *cfg_msg_hdr = NULL;
/* Nothing popped */
if (entries.empty())
{
return;
}
MacAddress::parseMacString(m_system_mac, system_mac);
for (auto entry: entries)
{
std::string domain_id_str = kfvKey(entry);
std::string op = kfvOp(entry);
int entryExists = 0;
int attrBmap = MCLAG_CFG_ATTR_NONE;
int attrDelBmap = MCLAG_CFG_ATTR_NONE;
enum MCLAG_DOMAIN_CFG_OP_TYPE cfgOpType = MCLAG_CFG_OPER_NONE;
memset(&cfg_info, 0, sizeof(mclag_domain_cfg_info));
cfg_info.domain_id = stoi(domain_id_str);
memcpy(cfg_info.system_mac, system_mac, ETHER_ADDR_LEN);
SWSS_LOG_INFO("Key(mclag domain_id):%s; op:%s ", domain_id_str.c_str(), op.c_str());
const struct mclagDomainEntry domain(stoi(domain_id_str));
auto it = m_mclag_domains.find(domain);
if (it != m_mclag_domains.end())
{
entryExists = 1;
}
if (op == "SET")
{
struct mclagDomainData domainData;
for (auto i : kfvFieldsValues(entry))
{
SWSS_LOG_DEBUG(" MCLAGSYNCD CFG Table Updates : " "Field %s, Value: %s EntryExits:%d \n",
fvField(i).c_str(), fvValue(i).c_str(), entryExists);
if (fvField(i) == "source_ip")
{
domainData.source_ip = fvValue(i);
if(!entryExists)
{
attrBmap = (attrBmap | MCLAG_CFG_ATTR_SRC_ADDR);
memcpy(cfg_info.local_ip, domainData.source_ip.c_str(), INET_ADDRSTRLEN);
}
}
if (fvField(i) == "peer_ip")
{
domainData.peer_ip = fvValue(i);
if(!entryExists)
{
attrBmap = (attrBmap | MCLAG_CFG_ATTR_PEER_ADDR);
memcpy(cfg_info.peer_ip, domainData.peer_ip.c_str(), INET_ADDRSTRLEN);
}
}
if (fvField(i) == "peer_link")
{
domainData.peer_link = fvValue(i);
if(!entryExists)
{
attrBmap = (attrBmap | MCLAG_CFG_ATTR_PEER_LINK);
memcpy(cfg_info.peer_ifname, domainData.peer_link.c_str(), MAX_L_PORT_NAME);
}
}
if (fvField(i) == "keepalive_interval")
{
if (fvValue(i).empty())
{
domainData.keepalive_interval = -1;
}
else
{
domainData.keepalive_interval = stoi(fvValue(i).c_str());
}
if(!entryExists)
{
attrBmap = (attrBmap | MCLAG_CFG_ATTR_KEEPALIVE_INTERVAL);
cfg_info.keepalive_time = domainData.keepalive_interval;
}
}
if (fvField(i) == "session_timeout")
{
if (fvValue(i).empty())
{
domainData.session_timeout = -1;
}
else
{
domainData.session_timeout = stoi(fvValue(i).c_str());
}
if(!entryExists)
{
attrBmap = (attrBmap | MCLAG_CFG_ATTR_SESSION_TIMEOUT);
cfg_info.session_timeout = domainData.session_timeout;
}
}
}
//If entry present send only the diff
if (entryExists)
{
if( (it->second.source_ip.compare(domainData.source_ip)) != 0)
{
attrBmap = (attrBmap | MCLAG_CFG_ATTR_SRC_ADDR);
memcpy(cfg_info.local_ip, domainData.source_ip.c_str(), INET_ADDRSTRLEN);
if (domainData.source_ip.empty())
{
attrDelBmap = attrDelBmap | MCLAG_CFG_ATTR_SRC_ADDR;
}
}
if( (it->second.peer_ip.compare(domainData.peer_ip)) != 0)
{
attrBmap |= MCLAG_CFG_ATTR_PEER_ADDR;
memcpy(cfg_info.peer_ip, domainData.peer_ip.c_str(), INET_ADDRSTRLEN);
if (domainData.peer_ip.empty())
{
attrDelBmap = attrDelBmap | MCLAG_CFG_ATTR_PEER_ADDR;
}
}
if( (it->second.peer_link.compare(domainData.peer_link)) != 0)
{
attrBmap |= MCLAG_CFG_ATTR_PEER_LINK;
memcpy(cfg_info.peer_ifname, domainData.peer_link.c_str(), MAX_L_PORT_NAME);
if (domainData.peer_link.empty())
{
attrDelBmap = attrDelBmap | MCLAG_CFG_ATTR_PEER_LINK;
}
}
if(it->second.keepalive_interval != domainData.keepalive_interval)
{
attrBmap |= MCLAG_CFG_ATTR_KEEPALIVE_INTERVAL;
cfg_info.keepalive_time = domainData.keepalive_interval;
if (domainData.keepalive_interval == -1)
{
attrDelBmap = attrDelBmap | MCLAG_CFG_ATTR_KEEPALIVE_INTERVAL;
}
}
if(it->second.session_timeout != domainData.session_timeout)
{
attrBmap |= MCLAG_CFG_ATTR_SESSION_TIMEOUT;
cfg_info.session_timeout = domainData.session_timeout;
if (domainData.session_timeout == -1)
{
attrDelBmap = attrDelBmap | MCLAG_CFG_ATTR_SESSION_TIMEOUT;
}
}
}
//nothing changed no need to update
if (!attrBmap && !attrDelBmap)
{
//no need to update
SWSS_LOG_NOTICE("mclagsycnd: domain cfg processing ; no change - duplicate update");
return;
}
SWSS_LOG_NOTICE("mclagsycnd: domain cfg processing; mandatory args present; Domain [%d] send to iccpd", domain.domain_id);
//Add/update domain map
m_mclag_domains[domain] = domainData;
//send config msg to iccpd
SWSS_LOG_DEBUG(" MCLAGSYNCD CFG Table Updates : domain_id:%d op_type:%d attrBmap:0x%x attrDelBmap:0x%x cfg_info.local_ip %s, peer_ip: %s peer_link:%s system_mac:%s session_timeout:%d keepalive_time:%d ",
domain.domain_id, cfgOpType, attrBmap, attrDelBmap, cfg_info.local_ip, cfg_info.peer_ip, cfg_info.peer_ifname, m_system_mac.c_str(), cfg_info.session_timeout, cfg_info.keepalive_time);
//Entry not found previously and got created now - do add operation
if (!entryExists)
{
cfgOpType = MCLAG_CFG_OPER_ADD;
add_cfg_dependent_selectables = 1;
}
else //entry found
{
//entry found and one attribute is deleted
if ( attrDelBmap && (attrBmap == attrDelBmap) )
{
cfgOpType = MCLAG_CFG_OPER_ATTR_DEL;
}
else //entry found and attribute are getting updated
{
cfgOpType = MCLAG_CFG_OPER_UPDATE;
}
}
}
else
{
//Entry not found - error deletion
if (!entryExists)
{
SWSS_LOG_WARN("mclagsycnd to ICCPD, cfg processing ; Domain [%d] deletion - domain not found", domain.domain_id);
return;
}
else
{
cfgOpType = MCLAG_CFG_OPER_DEL;
SWSS_LOG_NOTICE(" Del dependent selectables from select ");
delDomainCfgDependentSelectables();
add_cfg_dependent_selectables = 0;
m_mclag_domains.erase(domain);
SWSS_LOG_NOTICE("mclagsycnd to ICCPD, cfg processing ; Domain [%d] deletion", domain.domain_id);
}
}
if (cfgOpType == MCLAG_CFG_OPER_NONE)
{
SWSS_LOG_NOTICE("mclagsycnd to ICCPD, cfg processing ; Domain [%d] op type not set", domain.domain_id);
return;
}
if (MCLAG_MAX_SEND_MSG_LEN - infor_len < (sizeof(struct mclag_domain_cfg_info)) )
{
cfg_msg_hdr = reinterpret_cast<mclag_msg_hdr_t *>(static_cast<void *>(infor_start));
cfg_msg_hdr->version = 1;
cfg_msg_hdr->msg_len = (unsigned short)infor_len;
cfg_msg_hdr->msg_type = MCLAG_SYNCD_MSG_TYPE_CFG_MCLAG_DOMAIN;
SWSS_LOG_DEBUG("mclagsycnd send msg to iccpd, msg_len =%d, msg_type =%d version=%d count : %d", cfg_msg_hdr->msg_len, cfg_msg_hdr->msg_type, cfg_msg_hdr->version, count);
write = ::write(getConnSocket(), infor_start, cfg_msg_hdr->msg_len);
if (write <= 0)
{
SWSS_LOG_ERROR("mclagsycnd to ICCPD, domain cfg send, buffer full; write to m_connection_socket failed");
}
infor_len = sizeof(mclag_msg_hdr_t);
}
cfg_info.op_type = cfgOpType;
cfg_info.attr_bmap = attrBmap;
memcpy((char*)(infor_start + infor_len), (char*)&cfg_info, sizeof(struct mclag_domain_cfg_info));
infor_len = infor_len + sizeof(struct mclag_domain_cfg_info);
SWSS_LOG_DEBUG(" MCLAGSYNCD CFG Table Updates: domain_id:%d infor_len:%d infor_start:%p ", cfg_info.domain_id, (int)infor_len, infor_start);
}
/*no config info notification reqd */
if (infor_len <= sizeof(mclag_msg_hdr_t))
return;
cfg_msg_hdr = reinterpret_cast<mclag_msg_hdr_t *>(static_cast<void *>(infor_start));
cfg_msg_hdr->version = 1;
cfg_msg_hdr->msg_len = (unsigned short)infor_len;
cfg_msg_hdr->msg_type = MCLAG_SYNCD_MSG_TYPE_CFG_MCLAG_DOMAIN;
SWSS_LOG_DEBUG("mclagsycnd send msg to iccpd, msg_len =%d, msg_type =%d count : %d ver = %d ", cfg_msg_hdr->msg_len, cfg_msg_hdr->msg_type, count, cfg_msg_hdr->version);
write = ::write(getConnSocket(), infor_start, cfg_msg_hdr->msg_len);
if (write <= 0)
{
SWSS_LOG_ERROR("mclagsycnd to ICCPD, domain cfg send; write to m_connection_socket failed");
}
if (add_cfg_dependent_selectables)
{
SWSS_LOG_NOTICE(" Add dependent selectables to select ");
addDomainCfgDependentSelectables();
}
}
void MclagLink::addDomainCfgDependentSelectables()
{
p_state_fdb_tbl = new SubscriberStateTable(p_state_db.get(), STATE_FDB_TABLE_NAME);
SWSS_LOG_INFO(" MCLAGSYNCD create state fdb table");
p_state_vlan_mbr_subscriber_table = new SubscriberStateTable(p_state_db.get(), STATE_VLAN_MEMBER_TABLE_NAME);
SWSS_LOG_INFO(" MCLAGSYNCD create state vlan member table");
p_mclag_intf_cfg_tbl = new SubscriberStateTable(p_config_db.get(), CFG_MCLAG_INTF_TABLE_NAME);
SWSS_LOG_INFO(" MCLAGSYNCD create cfg mclag intf table");
p_mclag_unique_ip_cfg_tbl = new SubscriberStateTable(p_config_db.get(), CFG_MCLAG_UNIQUE_IP_TABLE_NAME);
SWSS_LOG_INFO(" MCLAGSYNCD create cfg unique ip table");
if (p_state_fdb_tbl)
{
m_select->addSelectable(p_state_fdb_tbl);
SWSS_LOG_INFO(" MCLAGSYNCD Add state_fdb_tbl to selectable");
}
if (p_state_vlan_mbr_subscriber_table)
{
m_select->addSelectable(p_state_vlan_mbr_subscriber_table);
SWSS_LOG_NOTICE(" MCLAGSYNCD Add p_state_vlan_mbr_subscriber_table to selectable");
}
//add mclag interface table to selectable
if (p_mclag_intf_cfg_tbl)
{
m_select->addSelectable(p_mclag_intf_cfg_tbl);
SWSS_LOG_NOTICE("MCLagSYNCD Adding mclag_intf_cfg_tbl to selectable");
}
//add mclag unique ip table to selectable
if (p_mclag_unique_ip_cfg_tbl)
{
m_select->addSelectable(getMclagUniqueCfgTable());
SWSS_LOG_NOTICE("MCLagSYNCD Adding mclag_unique_ip_cfg_tbl to selectable");
}
}
void MclagLink::delDomainCfgDependentSelectables()
{
if (p_mclag_intf_cfg_tbl)
{
m_select->removeSelectable(getMclagIntfCfgTable());
SWSS_LOG_NOTICE("MCLagSYNCD remove mclag_intf_cfg_tbl to selectable");
delete p_mclag_intf_cfg_tbl;
p_mclag_intf_cfg_tbl = NULL;
}
if (p_mclag_unique_ip_cfg_tbl)
{
m_select->removeSelectable(getMclagUniqueCfgTable());
SWSS_LOG_NOTICE("MCLagSYNCD remove mclag_unique_ip_cfg_tbl to selectable");
delete p_mclag_unique_ip_cfg_tbl;
p_mclag_unique_ip_cfg_tbl = NULL;
}
if (p_state_fdb_tbl)
{
m_select->removeSelectable(p_state_fdb_tbl);
SWSS_LOG_INFO(" MCLAGSYNCD remove state_fdb_tbl from selectable");
delete p_state_fdb_tbl;
p_state_fdb_tbl = NULL;
}
if (p_state_vlan_mbr_subscriber_table)
{
m_select->removeSelectable(p_state_vlan_mbr_subscriber_table);
SWSS_LOG_INFO(" MCLAGSYNCD remove p_state_vlan_mbr_subscriber_table selectable");
delete p_state_vlan_mbr_subscriber_table;
p_state_vlan_mbr_subscriber_table = NULL;
}
}
void MclagLink::mclagsyncdSendMclagIfaceCfg(std::deque<KeyOpFieldsValuesTuple> &entries)
{
struct mclag_iface_cfg_info cfg_info;
mclag_msg_hdr_t *cfg_msg_hdr = NULL;
size_t infor_len = sizeof(mclag_msg_hdr_t);
int count = 0;
vector<string> po_names;
ssize_t write = 0;
char *infor_start = getSendMsgBuffer();
/* Nothing popped */
if (entries.empty())
{