Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ospfd: Correct LSA parser which fulfill the TED #15026

Merged
merged 2 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 8 additions & 21 deletions ospfd/ospf_te.c
Original file line number Diff line number Diff line change
Expand Up @@ -980,8 +980,8 @@ static void ospf_mpls_te_nsm_change(struct ospf_neighbor *nbr, int old_state)
struct ospf_interface *oi = nbr->oi;
struct mpls_te_link *lp;

/* Process Neighbor only when its state is NSM Full */
if (nbr->state != NSM_Full)
/* Process Link only when neighbor old or new state is NSM Full */
if (nbr->state != NSM_Full && old_state != NSM_Full)
return;

/* Get interface information for Traffic Engineering */
Expand Down Expand Up @@ -1839,6 +1839,7 @@ static void ospf_te_delete_subnet(struct ls_ted *ted, struct in_addr addr)
p.family = AF_INET;
p.prefixlen = IPV4_MAX_BITLEN;
p.u.prefix4 = addr;
ote_debug(" |- Delete Subnet info. for Prefix %pFX", &p);
subnet = ls_find_subnet(ted, &p);

/* Remove subnet if found */
Expand All @@ -1851,8 +1852,7 @@ static void ospf_te_delete_subnet(struct ls_ted *ted, struct in_addr addr)

/**
* Parse Router LSA. This function will create or update corresponding Vertex,
* Edge and Subnet. It also remove Edge and Subnet if they are marked as Orphan
* once Router LSA is parsed.
* Edge and Subnet.
*
* @param ted Link State Traffic Engineering Database
* @param lsa OSPF Link State Advertisement
Expand All @@ -1864,9 +1864,6 @@ static int ospf_te_parse_router_lsa(struct ls_ted *ted, struct ospf_lsa *lsa)
struct router_lsa *rl;
enum ls_node_type type;
struct ls_vertex *vertex;
struct ls_edge *edge;
struct ls_subnet *subnet;
struct listnode *node;
int len, links;

/* Sanity Check */
Expand Down Expand Up @@ -1909,13 +1906,6 @@ static int ospf_te_parse_router_lsa(struct ls_ted *ted, struct ospf_lsa *lsa)
vertex->status = SYNC;
}

/* Mark outgoing Edge and Subnet as ORPHAN to detect deletion */
for (ALL_LIST_ELEMENTS_RO(vertex->outgoing_edges, node, edge))
edge->status = ORPHAN;

for (ALL_LIST_ELEMENTS_RO(vertex->prefixes, node, subnet))
subnet->status = ORPHAN;

/* Then, process Link Information */
len = lsa->size - OSPF_LSA_HEADER_SIZE - OSPF_ROUTER_LSA_MIN_SIZE;
links = ntohs(rl->links);
Expand Down Expand Up @@ -1948,11 +1938,6 @@ static int ospf_te_parse_router_lsa(struct ls_ted *ted, struct ospf_lsa *lsa)
break;
}
}
/* Clean remaining Orphan Edges or Subnets */
if (OspfMplsTE.export)
ls_vertex_clean(ted, vertex, zclient);
else
ls_vertex_clean(ted, vertex, NULL);

return 0;
}
Expand Down Expand Up @@ -2405,7 +2390,10 @@ static int ospf_te_delete_te(struct ls_ted *ted, struct ospf_lsa *lsa)
ote_debug(" |- Delete TE info. for Edge %pI4",
&edge->attributes->standard.local);

/* Remove Link State Attributes TE information */
/* First remove the associated Subnet */
ospf_te_delete_subnet(ted, attr->standard.local);

/* Then ,remove Link State Attributes TE information */
memset(&attr->standard, 0, sizeof(struct ls_standard));
attr->flags &= 0x0FFFF;
memset(&attr->extended, 0, sizeof(struct ls_extended));
Expand All @@ -2420,7 +2408,6 @@ static int ospf_te_delete_te(struct ls_ted *ted, struct ospf_lsa *lsa)
edge->status = SYNC;
} else {
/* Remove completely the Edge if Segment Routing is not set */
ospf_te_delete_subnet(ted, attr->standard.local);
edge->status = DELETE;
ospf_te_export(LS_MSG_TYPE_ATTRIBUTES, edge);
ls_edge_del_all(ted, edge);
Expand Down
4 changes: 2 additions & 2 deletions tests/topotests/ospf_te_topo1/r1/ospfd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
interface lo
ip ospf area 0.0.0.0
!
interface r1-eth0
interface eth0
ip ospf network point-to-point
ip ospf hello-interval 2
ip ospf dead-interval 10
ip ospf area 0.0.0.0
!
interface r1-eth1
interface eth1
ip ospf network point-to-point
ip ospf hello-interval 2
ip ospf dead-interval 10
Expand Down
4 changes: 2 additions & 2 deletions tests/topotests/ospf_te_topo1/r1/zebra.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
interface lo
ip address 10.0.255.1/32
!
interface r1-eth0
interface eth0
ip address 10.0.0.1/24
link-params
metric 20
Expand All @@ -12,7 +12,7 @@ interface r1-eth0
enable
exit-link-params
!
interface r1-eth1
interface eth1
ip address 10.0.1.1/24
link-params
enable
Expand Down
8 changes: 4 additions & 4 deletions tests/topotests/ospf_te_topo1/r2/ospfd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@
interface lo
ip ospf area 0.0.0.0
!
interface r2-eth0
interface eth0
ip ospf network point-to-point
ip ospf hello-interval 2
ip ospf dead-interval 10
ip ospf area 0.0.0.0
!
interface r2-eth1
interface eth1
ip ospf network point-to-point
ip ospf hello-interval 2
ip ospf dead-interval 10
ip ospf area 0.0.0.0
!
interface r2-eth2
interface eth2
ip ospf network point-to-point
ip ospf area 0.0.0.0
ip ospf hello-interval 2
ip ospf dead-interval 10
!
interface r2-eth3
interface eth3
ip ospf network point-to-point
ip ospf hello-interval 2
ip ospf dead-interval 10
Expand Down
8 changes: 4 additions & 4 deletions tests/topotests/ospf_te_topo1/r2/zebra.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@
interface lo
ip address 10.0.255.2/32
!
interface r2-eth0
interface eth0
ip address 10.0.0.2/24
link-params
enable
exit-link-params
!
interface r2-eth1
interface eth1
ip address 10.0.1.2/24
link-params
enable
exit-link-params
!
interface r2-eth2
interface eth2
ip address 10.0.3.2/24
link-params
enable
exit-link-params
!
interface r2-eth3
interface eth3
ip address 10.0.4.2/24
link-params
metric 30
Expand Down
4 changes: 2 additions & 2 deletions tests/topotests/ospf_te_topo1/r3/ospfd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
interface lo
ip ospf area 0.0.0.0
!
interface r3-eth0
interface eth0
ip ospf network point-to-point
ip ospf area 0.0.0.0
ip ospf hello-interval 2
ip ospf dead-interval 10
!
interface r3-eth1
interface eth1
ip ospf network point-to-point
ip ospf area 0.0.0.0
ip ospf hello-interval 2
Expand Down
4 changes: 2 additions & 2 deletions tests/topotests/ospf_te_topo1/r3/zebra.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
interface lo
ip address 10.0.255.3/32
!
interface r3-eth0
interface eth0
ip address 10.0.3.1/24
link-params
enable
admin-grp 0x20
exit-link-params
!
interface r3-eth1
interface eth1
ip address 10.0.5.1/24
link-params
enable
Expand Down
2 changes: 1 addition & 1 deletion tests/topotests/ospf_te_topo1/r4/ospfd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
interface lo
ip ospf area 0.0.0.0
!
interface r4-eth0
interface eth0
ip ospf network point-to-point
ip ospf hello-interval 2
ip ospf dead-interval 10
Expand Down
2 changes: 1 addition & 1 deletion tests/topotests/ospf_te_topo1/r4/zebra.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
interface lo
ip address 10.0.255.4/32
!
interface r4-eth0
interface eth0
ip address 10.0.4.1/24
link-params
enable
Expand Down
52 changes: 22 additions & 30 deletions tests/topotests/ospf_te_topo1/test_ospf_te_topo1.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@
| 10.0.225.1 |
| |
+------------+
r1-eth0| |r1-eth1
eth0| |eth1
| |
10.0.0.0/24| |10.0.1.0/24
| |
r2-eth0| |r2-eth1
eth0| |eth1
+------------+ +------------+
| | | |
| R2 |r2-eth2 r3-eth0| R3 |
| R2 |eth2 eth0| R3 |
| 10.0.255.2 +------------------+ 10.0.255.3 |
| | 10.0.3.0/24 | |
+------------+ +------+-----+
r2-eth3| r3-eth1|
eth3| eth1|
| |
10.0.4.0/24| 10.0.5.0/24|
| |
r4-eth0| V
eth0| V
+------------+ ASBR 10.0.255.5
| |
| R4 |
Expand Down Expand Up @@ -70,30 +70,24 @@ def build_topo(tgen):
"Build function"

# Create 4 routers
for routern in range(1, 5):
tgen.add_router("r{}".format(routern))
r1 = tgen.add_router("r1")
r2 = tgen.add_router("r2")
r3 = tgen.add_router("r3")
r4 = tgen.add_router("r4")

# Interconect router 1 and 2 with 2 links
switch = tgen.add_switch("s1")
switch.add_link(tgen.gears["r1"])
switch.add_link(tgen.gears["r2"])
switch = tgen.add_switch("s2")
switch.add_link(tgen.gears["r1"])
switch.add_link(tgen.gears["r2"])
tgen.add_link(r1, r2, ifname1="eth0", ifname2="eth0")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you continue to use the r1-eth0, r2-eth0 naming scheme rather than removing the rX- prefix? If you do that here and below, then none of the config files need to change and this PR gets a lot smaller -- from 10 files changed to 2.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also what are the default names assigned if you don't specify the ifname[12] keywords?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My first intention was to keep the interface name. Unfortunately, if you set the ifname1 & 2 with ifname1="r1-eth0" for example, pytest crash with an error about the name of the interface. I don't try to not specify the ifname[12] keyword, but it seems that the default value will not be of the form rX-ethY

tgen.add_link(r1, r2, ifname1="eth1", ifname2="eth1")

# Interconect router 3 and 2
switch = tgen.add_switch("s3")
switch.add_link(tgen.gears["r3"])
switch.add_link(tgen.gears["r2"])
tgen.add_link(r2, r3, ifname1="eth2", ifname2="eth0")

# Interconect router 4 and 2
switch = tgen.add_switch("s4")
switch.add_link(tgen.gears["r4"])
switch.add_link(tgen.gears["r2"])
tgen.add_link(r2, r4, ifname1="eth3", ifname2="eth0")

# Interconnect router 3 with next AS
switch = tgen.add_switch("s5")
switch.add_link(tgen.gears["r3"])
s1 = tgen.add_switch("s1")
tgen.add_link(r3, s1, ifname1="eth1", ifname2="eth0")


def setup_module(mod):
Expand Down Expand Up @@ -174,8 +168,7 @@ def test_step2():

tgen = setup_testcase("Step2: Shutdown interface between r1 & r2")

tgen.net["r1"].cmd('vtysh -c "conf t" -c "interface r1-eth1" -c "shutdown"')
tgen.net["r2"].cmd('vtysh -c "conf t" -c "interface r2-eth1" -c "shutdown"')
tgen.net["r1"].cmd('vtysh -c "conf t" -c "interface eth1" -c "shutdown"')

for rname in ["r1", "r2", "r3", "r4"]:
compare_ted_json_output(tgen, rname, "ted_step2.json")
Expand Down Expand Up @@ -227,28 +220,27 @@ def test_step5():

tgen = setup_testcase("Step5: Re-enable interface between r1 & r2")

tgen.net["r1"].cmd('vtysh -c "conf t" -c "interface r1-eth1" -c "no shutdown"')
tgen.net["r2"].cmd('vtysh -c "conf t" -c "interface r2-eth1" -c "no shutdown"')
tgen.net["r1"].cmd('vtysh -c "conf t" -c "interface eth1" -c "no shutdown"')

for rname in ["r1", "r2", "r3", "r4"]:
compare_ted_json_output(tgen, rname, "ted_step5.json")


def test_step6():
"Step6: Set delay and jitter for interface r4-eth0 on r4, remove use-bw \
for interface r2-eth3 on r2 and verify that corresponding Edges are \
"Step6: Set delay and jitter for interface eth0 on r4, remove use-bw \
for interface eth3 on r2 and verify that corresponding Edges are \
updated in the TED on all routers"

tgen = setup_testcase("Step6: Modify link parameters on r2 & r4")

tgen.net["r2"].cmd(
'vtysh -c "conf t" -c "interface r2-eth3" -c "link-params" -c "no use-bw"'
'vtysh -c "conf t" -c "interface eth3" -c "link-params" -c "no use-bw"'
)
tgen.net["r4"].cmd(
'vtysh -c "conf t" -c "interface r4-eth0" -c "link-params" -c "delay 20000"'
'vtysh -c "conf t" -c "interface eth0" -c "link-params" -c "delay 20000"'
)
tgen.net["r4"].cmd(
'vtysh -c "conf t" -c "interface r4-eth0" -c "link-params" -c "delay-variation 10000"'
'vtysh -c "conf t" -c "interface eth0" -c "link-params" -c "delay-variation 10000"'
)

for rname in ["r1", "r2", "r3", "r4"]:
Expand Down
Loading