Skip to content

Commit 682d7cb

Browse files
[Vlans]: Extract VLAN_MEMBER_TABLE from VLAN_TABLE (sonic-net#229)
* Extract VLAN_MEMBER_TABLE from VLAN_TABLE * it compiles * Fix wiki
1 parent d2a466d commit 682d7cb

File tree

6 files changed

+125
-93
lines changed

6 files changed

+125
-93
lines changed

doc/swss-schema.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,18 @@ For example (reorder output)
101101
### VLAN_TABLE
102102
;Defines VLANs and the interfaces which are members of the vlan
103103
;Status: work in progress
104-
key = VLAN_TABLE:"vlan"vlanid ; DIGIT 0-4095 with prefix "Vlan"
104+
key = VLAN_TABLE:"Vlan"vlanid ; DIGIT 0-4095 with prefix "Vlan"
105105
admin_status = "down" / "up" ; admin status
106106
oper_status = "down" / "up" ; operating status
107107
mtu = 1*4DIGIT ; MTU for the IP interface of the VLAN
108108

109-
key = VLAN_TABLE:vlanid:ifname ; physical port member of VLAN
110-
tagging_mode = "untagged" / "tagged" / "priority_tagged" ; default value as untagged
109+
---------------------------------------------
110+
### VLAN_MEMBER_TABLE
111+
;Defines interfaces which are members of a vlan
112+
;Status: work in progress
111113

114+
key = VLAN_MEMBER_TABLE:"Vlan"vlanid:ifname ; physical port "ifname" is a member of a VLAN "VlanX"
115+
tagging_mode = "untagged" / "tagged" / "priority_tagged" ; default value as untagged
112116

113117
---------------------------------------------
114118
### LAG_TABLE

orchagent/orchdaemon.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ bool OrchDaemon::init()
3636
vector<string> ports_tables = {
3737
APP_PORT_TABLE_NAME,
3838
APP_VLAN_TABLE_NAME,
39+
APP_VLAN_MEMBER_TABLE_NAME,
3940
APP_LAG_TABLE_NAME,
4041
APP_LAG_MEMBER_TABLE_NAME
4142
};

orchagent/portsorch.cpp

Lines changed: 108 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -451,117 +451,145 @@ void PortsOrch::doVlanTask(Consumer &consumer)
451451
/* Ensure the key starts with "Vlan" otherwise ignore */
452452
if (strncmp(key.c_str(), VLAN_PREFIX, 4))
453453
{
454+
SWSS_LOG_ERROR("Invalid key format. No 'Vlan' prefix: %s", key.c_str());
454455
it = consumer.m_toSync.erase(it);
455456
continue;
456457
}
457458

458-
key = key.substr(4);
459-
size_t found = key.find(':');
460459
int vlan_id;
461-
string vlan_alias, port_alias;
462-
if (found == string::npos)
463-
vlan_id = stoi(key);
464-
else
465-
{
466-
vlan_id = stoi(key.substr(0, found));
467-
port_alias = key.substr(found+1);
468-
}
460+
vlan_id = stoi(key.substr(4)); // FIXME: might raise exception
469461

462+
string vlan_alias, port_alias;
470463
vlan_alias = VLAN_PREFIX + to_string(vlan_id);
471464
string op = kfvOp(t);
472465

473-
/* Manipulate VLAN when port_alias is empty */
474-
if (port_alias == "")
466+
if (op == SET_COMMAND)
475467
{
476-
if (op == SET_COMMAND)
468+
/* Duplicate entry */
469+
if (m_portList.find(vlan_alias) != m_portList.end())
477470
{
478-
/* Duplicate entry */
479-
if (m_portList.find(vlan_alias) != m_portList.end())
480-
{
481-
it = consumer.m_toSync.erase(it);
482-
continue;
483-
}
484-
485-
if (addVlan(vlan_alias))
486-
it = consumer.m_toSync.erase(it);
487-
else
488-
it++;
471+
it = consumer.m_toSync.erase(it);
472+
continue;
489473
}
490-
else if (op == DEL_COMMAND)
491-
{
492-
Port vlan;
493-
getPort(vlan_alias, vlan);
494474

495-
if (removeVlan(vlan))
496-
it = consumer.m_toSync.erase(it);
497-
else
498-
it++;
499-
}
475+
if (addVlan(vlan_alias))
476+
it = consumer.m_toSync.erase(it);
500477
else
501-
{
502-
SWSS_LOG_ERROR("Unknown operation type %s", op.c_str());
478+
it++;
479+
}
480+
else if (op == DEL_COMMAND)
481+
{
482+
Port vlan;
483+
getPort(vlan_alias, vlan);
484+
485+
if (removeVlan(vlan))
503486
it = consumer.m_toSync.erase(it);
504-
}
487+
else
488+
it++;
505489
}
506-
/* Manipulate member */
507490
else
508491
{
509-
assert(m_portList.find(vlan_alias) != m_portList.end());
510-
Port vlan, port;
492+
SWSS_LOG_ERROR("Unknown operation type %s", op.c_str());
493+
it = consumer.m_toSync.erase(it);
494+
}
495+
}
496+
}
511497

512-
/* When VLAN member is to be created before VLAN is created */
513-
if (!getPort(vlan_alias, vlan))
514-
{
515-
SWSS_LOG_INFO("Failed to locate VLAN %s", vlan_alias.c_str());
516-
it++;
517-
continue;
518-
}
498+
void PortsOrch::doVlanMemberTask(Consumer &consumer)
499+
{
500+
if (!isInitDone())
501+
return;
502+
503+
auto it = consumer.m_toSync.begin();
504+
while (it != consumer.m_toSync.end())
505+
{
506+
auto &t = it->second;
507+
508+
string key = kfvKey(t);
509+
510+
/* Ensure the key starts with "Vlan" otherwise ignore */
511+
if (strncmp(key.c_str(), VLAN_PREFIX, 4))
512+
{
513+
SWSS_LOG_ERROR("Invalid key format. No 'Vlan' prefix: %s", key.c_str());
514+
it = consumer.m_toSync.erase(it);
515+
continue;
516+
}
517+
518+
key = key.substr(4);
519+
size_t found = key.find(':');
520+
int vlan_id;
521+
string vlan_alias, port_alias;
522+
if (found != string::npos)
523+
{
524+
vlan_id = stoi(key.substr(0, found)); // FIXME: might raise exception
525+
port_alias = key.substr(found+1);
526+
}
527+
else
528+
{
529+
SWSS_LOG_ERROR("Invalid key format. No member port is presented: %s",
530+
kfvKey(t).c_str());
531+
it = consumer.m_toSync.erase(it);
532+
continue;
533+
}
519534

520-
if (!getPort(port_alias, port))
535+
vlan_alias = VLAN_PREFIX + to_string(vlan_id);
536+
string op = kfvOp(t);
537+
538+
assert(m_portList.find(vlan_alias) != m_portList.end());
539+
Port vlan, port;
540+
541+
/* When VLAN member is to be created before VLAN is created */
542+
if (!getPort(vlan_alias, vlan))
543+
{
544+
SWSS_LOG_INFO("Failed to locate VLAN %s", vlan_alias.c_str());
545+
it++;
546+
continue;
547+
}
548+
549+
if (!getPort(port_alias, port))
550+
{
551+
SWSS_LOG_ERROR("Failed to locate port %s", port_alias.c_str());
552+
it = consumer.m_toSync.erase(it);
553+
continue;
554+
}
555+
556+
if (op == SET_COMMAND)
557+
{
558+
/* Duplicate entry */
559+
if (vlan.m_members.find(port_alias) != vlan.m_members.end())
521560
{
522-
SWSS_LOG_ERROR("Failed to locate port %s", port_alias.c_str());
523561
it = consumer.m_toSync.erase(it);
524562
continue;
525563
}
526564

527-
if (op == SET_COMMAND)
528-
{
529-
/* Duplicate entry */
530-
if (vlan.m_members.find(port_alias) != vlan.m_members.end())
531-
{
532-
it = consumer.m_toSync.erase(it);
533-
continue;
534-
}
565+
/* Assert the port doesn't belong to any VLAN */
566+
assert(!port.m_vlan_id && !port.m_vlan_member_id);
535567

536-
/* Assert the port doesn't belong to any VLAN */
537-
assert(!port.m_vlan_id && !port.m_vlan_member_id);
568+
if (addVlanMember(vlan, port))
569+
it = consumer.m_toSync.erase(it);
570+
else
571+
it++;
572+
}
573+
else if (op == DEL_COMMAND)
574+
{
575+
if (vlan.m_members.find(port_alias) != vlan.m_members.end())
576+
{
577+
/* Assert the port belongs the a VLAN */
578+
assert(port.m_vlan_id && port.m_vlan_member_id);
538579

539-
if (addVlanMember(vlan, port))
580+
if (removeVlanMember(vlan, port))
540581
it = consumer.m_toSync.erase(it);
541582
else
542583
it++;
543584
}
544-
else if (op == DEL_COMMAND)
545-
{
546-
if (vlan.m_members.find(port_alias) != vlan.m_members.end())
547-
{
548-
/* Assert the port belongs the a VLAN */
549-
assert(port.m_vlan_id && port.m_vlan_member_id);
550-
551-
if (removeVlanMember(vlan, port))
552-
it = consumer.m_toSync.erase(it);
553-
else
554-
it++;
555-
}
556-
else
557-
/* Cannot locate the VLAN */
558-
it = consumer.m_toSync.erase(it);
559-
}
560585
else
561-
{
562-
SWSS_LOG_ERROR("Unknown operation type %s", op.c_str());
586+
/* Cannot locate the VLAN */
563587
it = consumer.m_toSync.erase(it);
564-
}
588+
}
589+
else
590+
{
591+
SWSS_LOG_ERROR("Unknown operation type %s", op.c_str());
592+
it = consumer.m_toSync.erase(it);
565593
}
566594
}
567595
}
@@ -732,6 +760,8 @@ void PortsOrch::doTask(Consumer &consumer)
732760
doPortTask(consumer);
733761
else if (table_name == APP_VLAN_TABLE_NAME)
734762
doVlanTask(consumer);
763+
else if (table_name == APP_VLAN_MEMBER_TABLE_NAME)
764+
doVlanMemberTask(consumer);
735765
else if (table_name == APP_LAG_TABLE_NAME)
736766
doLagTask(consumer);
737767
else if (table_name == APP_LAG_MEMBER_TABLE_NAME)

orchagent/portsorch.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class PortsOrch : public Orch, public Subject
6363
void doTask(Consumer &consumer);
6464
void doPortTask(Consumer &consumer);
6565
void doVlanTask(Consumer &consumer);
66+
void doVlanMemberTask(Consumer &consumer);
6667
void doLagTask(Consumer &consumer);
6768
void doLagMemberTask(Consumer &consumer);
6869

portsyncd/linksync.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ extern bool g_init;
3333
LinkSync::LinkSync(DBConnector *db) :
3434
m_portTableProducer(db, APP_PORT_TABLE_NAME),
3535
m_vlanTableProducer(db, APP_VLAN_TABLE_NAME),
36+
m_vlanMemberTableProducer(db, APP_VLAN_MEMBER_TABLE_NAME),
3637
m_lagTableProducer(db, APP_LAG_TABLE_NAME),
3738
m_portTableConsumer(db, APP_PORT_TABLE_NAME),
38-
m_vlanTableConsumer(db, APP_VLAN_TABLE_NAME),
39+
m_vlanMemberTableConsumer(db, APP_VLAN_MEMBER_TABLE_NAME),
3940
m_lagTableConsumer(db, APP_LAG_TABLE_NAME)
4041
{
4142
/* See the comments for g_portSet in portsyncd.cpp */
@@ -56,16 +57,11 @@ LinkSync::LinkSync(DBConnector *db) :
5657
}
5758

5859
vector<KeyOpFieldsValuesTuple> tuples;
59-
m_vlanTableConsumer.getTableContent(tuples);
60+
m_vlanMemberTableConsumer.getTableContent(tuples);
6061

6162
for (auto tuple : tuples)
6263
{
6364
vector<string> keys = tokenize(kfvKey(tuple), ':');
64-
if (keys.size() != 2)
65-
{
66-
continue;
67-
}
68-
6965
string vlan = keys[0];
7066
string member = keys[1];
7167

@@ -137,15 +133,15 @@ void LinkSync::onMsg(int nlmsg_type, struct nl_object *obj)
137133

138134
if (nlmsg_type == RTM_DELLINK) /* Will it happen? */
139135
{
140-
m_vlanTableProducer.del(member_key);
136+
m_vlanMemberTableProducer.del(member_key);
141137
}
142138
else /* RTM_NEWLINK */
143139
{
144140
vector<FieldValueTuple> fvVector;
145141
FieldValueTuple t("tagging_mode", "untagged");
146142
fvVector.push_back(t);
147143

148-
m_vlanTableProducer.set(member_key, fvVector);
144+
m_vlanMemberTableProducer.set(member_key, fvVector);
149145
}
150146
}
151147
}
@@ -158,7 +154,7 @@ void LinkSync::onMsg(int nlmsg_type, struct nl_object *obj)
158154
if (member_set.find(key) != member_set.end())
159155
{
160156
string member_key = (*i).first + ":" + key;
161-
m_vlanTableProducer.del(member_key);
157+
m_vlanMemberTableProducer.del(member_key);
162158
}
163159
}
164160
}

portsyncd/linksync.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ class LinkSync : public NetMsg
1919
virtual void onMsg(int nlmsg_type, struct nl_object *obj);
2020

2121
private:
22-
ProducerStateTable m_portTableProducer, m_vlanTableProducer, m_lagTableProducer;
23-
Table m_portTableConsumer, m_vlanTableConsumer, m_lagTableConsumer;
22+
ProducerStateTable m_portTableProducer, m_vlanTableProducer, m_vlanMemberTableProducer, m_lagTableProducer;
23+
Table m_portTableConsumer, m_vlanMemberTableConsumer, m_lagTableConsumer;
2424

2525
std::map<unsigned int, std::string> m_ifindexNameMap;
2626
};

0 commit comments

Comments
 (0)