Implements proper RID handling in OSPFv3.

This commit is contained in:
Ondrej Zajicek 2009-09-17 12:18:03 +02:00
parent c15e569065
commit 9f0ba7b1c7
3 changed files with 195 additions and 106 deletions

View file

@ -225,10 +225,12 @@ process_prefixes(struct ospf_area *oa)
continue; continue;
px = en->lsa_body; px = en->lsa_body;
/* FIXME: for router LSA, we should find the first one */
src = ospf_hash_find(po->gr, oa->areaid, /* For router prefix-LSA, we would like to find the first router-LSA */
((px->ref_type == LSA_T_RT) ? px->ref_rt : px->ref_id), if (px->ref_type == LSA_T_RT)
px->ref_rt, px->ref_type); src = ospf_hash_find_rt(po->gr, oa->areaid, px->ref_rt);
else
src = ospf_hash_find(po->gr, oa->areaid, px->ref_id, px->ref_rt, px->ref_type);
if (!src) if (!src)
continue; continue;
@ -253,78 +255,23 @@ process_prefixes(struct ospf_area *oa)
} }
#endif #endif
static void static void
ospf_rt_spfa(struct ospf_area *oa) ospf_rt_spfa_rtlinks(struct ospf_area *oa, struct top_hash_entry *act, struct top_hash_entry *en)
{ {
u32 i, *rts;
struct ospf_lsa_rt *rt;
struct ospf_lsa_rt_link *rtl, *rr;
struct proto *p = &oa->po->proto; struct proto *p = &oa->po->proto;
struct proto_ospf *po = oa->po; struct proto_ospf *po = oa->po;
struct ospf_lsa_net *ln;
orta nf; orta nf;
struct ospf_iface *iface; u32 i;
struct top_hash_entry *act, *tmp;
node *n;
if (oa->rt == NULL) struct ospf_lsa_rt *rt = en->lsa_body;
return; struct ospf_lsa_rt_link *rr = (struct ospf_lsa_rt_link *) (rt + 1);
OSPF_TRACE(D_EVENTS, "Starting routing table calculation for area %R", oa->areaid); for (i = 0; i < lsa_rt_count(&en->lsa); i++)
if (oa->rt->dist != LSINFINITY)
bug("Aging was not processed.");
/* 16.1. (1) */
init_list(&oa->cand); /* Empty list of candidates */
oa->trcap = 0;
DBG("LSA db prepared, adding me into candidate list.\n");
oa->rt->dist = 0;
oa->rt->color = CANDIDATE;
add_head(&oa->cand, &oa->rt->cn);
DBG("RT LSA: rt: %R, id: %R, type: %u\n",
oa->rt->lsa.rt, oa->rt->lsa.id, oa->rt->lsa.type);
while (!EMPTY_LIST(oa->cand))
{ {
n = HEAD(oa->cand); struct ospf_lsa_rt_link *rtl = rr + i;
act = SKIP_BACK(struct top_hash_entry, cn, n); struct top_hash_entry *tmp = NULL;
rem_node(n);
DBG("Working on LSA: rt: %R, id: %R, type: %u\n",
act->lsa.rt, act->lsa.id, act->lsa.type);
act->color = INSPF;
switch (act->lsa.type)
{
case LSA_T_RT:
/* FIXME - in OSPFv3 we should process all RT LSAs from that router */
rt = (struct ospf_lsa_rt *) act->lsa_body;
if (rt->options & OPT_RT_V)
oa->trcap = 1;
/* FIXME - in OSPFv3, should we add all routers, or just ABRs an ASBRs? */
if ((rt->options & OPT_RT_V) || (rt->options & OPT_RT_E))
{
nf.type = RTS_OSPF;
nf.options = rt->options;
nf.metric1 = act->dist;
nf.metric2 = LSINFINITY;
nf.tag = 0;
nf.oa = oa;
nf.ar = act;
nf.nh = act->nh;
nf.ifa = act->nhi;
ri_install(po, ipa_from_rid(act->lsa.rt), MAX_PREFIX_LENGTH, ORT_ROUTER, &nf, NULL);
}
rr = (struct ospf_lsa_rt_link *) (rt + 1);
for (i = 0; i < lsa_rt_count(&act->lsa); i++)
{
tmp = NULL;
rtl = (rr + i);
DBG(" Working on link: %R (type: %u) ", rtl->id, rtl->type); DBG(" Working on link: %R (type: %u) ", rtl->id, rtl->type);
switch (rtl->type) switch (rtl->type)
{ {
@ -368,10 +315,11 @@ ospf_rt_spfa(struct ospf_area *oa)
ipa_mklen(ipa_from_u32(rtl->data)), ORT_NET, &nf, NULL); ipa_mklen(ipa_from_u32(rtl->data)), ORT_NET, &nf, NULL);
break; break;
#endif #endif
case LSART_NET: case LSART_NET:
#ifdef OSPFv2 #ifdef OSPFv2
/* In OSPFv2, rtl->id is IP addres of DR, router ID is not known */ /* In OSPFv2, rtl->id is IP addres of DR, Router ID is not known */
tmp = ospf_hash_find(po->gr, oa->areaid, rtl->id, 0, LSA_T_NET); tmp = ospf_hash_find_net(po->gr, oa->areaid, rtl->id);
#else /* OSPFv3 */ #else /* OSPFv3 */
tmp = ospf_hash_find(po->gr, oa->areaid, rtl->nif, rtl->id, LSA_T_NET); tmp = ospf_hash_find(po->gr, oa->areaid, rtl->nif, rtl->id, LSA_T_NET);
#endif #endif
@ -383,9 +331,7 @@ ospf_rt_spfa(struct ospf_area *oa)
case LSART_VLNK: case LSART_VLNK:
case LSART_PTP: case LSART_PTP:
/* FIXME - in OSPFv3, find lowest LSA ID */ tmp = ospf_hash_find_rt(po->gr, oa->areaid, rtl->id);
tmp = ospf_hash_find(po->gr, oa->areaid, rtl->id, rtl->id, LSA_T_RT);
DBG("PTP found.\n"); DBG("PTP found.\n");
break; break;
default: default:
@ -397,6 +343,81 @@ ospf_rt_spfa(struct ospf_area *oa)
tmp->dist, act->dist + rtl->metric); tmp->dist, act->dist + rtl->metric);
add_cand(&oa->cand, tmp, act, act->dist + rtl->metric, oa); add_cand(&oa->cand, tmp, act, act->dist + rtl->metric, oa);
} }
}
static void
ospf_rt_spfa(struct ospf_area *oa)
{
struct proto *p = &oa->po->proto;
struct proto_ospf *po = oa->po;
struct ospf_lsa_rt *rt;
struct ospf_lsa_net *ln;
struct ospf_iface *iface;
struct top_hash_entry *act, *tmp;
u32 i, *rts;
orta nf;
node *n;
if (oa->rt == NULL)
return;
OSPF_TRACE(D_EVENTS, "Starting routing table calculation for area %R", oa->areaid);
if (oa->rt->dist != LSINFINITY)
bug("Aging was not processed.");
/* 16.1. (1) */
init_list(&oa->cand); /* Empty list of candidates */
oa->trcap = 0;
DBG("LSA db prepared, adding me into candidate list.\n");
oa->rt->dist = 0;
oa->rt->color = CANDIDATE;
add_head(&oa->cand, &oa->rt->cn);
DBG("RT LSA: rt: %R, id: %R, type: %u\n",
oa->rt->lsa.rt, oa->rt->lsa.id, oa->rt->lsa.type);
while (!EMPTY_LIST(oa->cand))
{
n = HEAD(oa->cand);
act = SKIP_BACK(struct top_hash_entry, cn, n);
rem_node(n);
DBG("Working on LSA: rt: %R, id: %R, type: %u\n",
act->lsa.rt, act->lsa.id, act->lsa.type);
act->color = INSPF;
switch (act->lsa.type)
{
case LSA_T_RT:
rt = (struct ospf_lsa_rt *) act->lsa_body;
if (rt->options & OPT_RT_V)
oa->trcap = 1;
/* FIXME - in OSPFv3, should we add all routers, or just ABRs an ASBRs? */
if ((rt->options & OPT_RT_V) || (rt->options & OPT_RT_E))
{
nf.type = RTS_OSPF;
nf.options = rt->options;
nf.metric1 = act->dist;
nf.metric2 = LSINFINITY;
nf.tag = 0;
nf.oa = oa;
nf.ar = act;
nf.nh = act->nh;
nf.ifa = act->nhi;
ri_install(po, ipa_from_rid(act->lsa.rt), MAX_PREFIX_LENGTH, ORT_ROUTER, &nf, NULL);
}
#ifdef OSPFv2
ospf_rt_spfa_rtlinks(oa, act, act);
#else /* OSPFv3 */
for (tmp = ospf_hash_find_rt_first(po->gr, act->domain, act->lsa.rt);
tmp; tmp = ospf_hash_find_rt_next(tmp))
ospf_rt_spfa_rtlinks(oa, act, tmp);
#endif
break; break;
case LSA_T_NET: case LSA_T_NET:
ln = act->lsa_body; ln = act->lsa_body;
@ -410,8 +431,7 @@ ospf_rt_spfa(struct ospf_area *oa)
for (i = 0; i < lsa_net_count(&act->lsa); i++) for (i = 0; i < lsa_net_count(&act->lsa); i++)
{ {
DBG(" Working on router %R ", rts[i]); DBG(" Working on router %R ", rts[i]);
/* FIXME - in OSPFv3, find any LSA ID */ tmp = ospf_hash_find_rt(po->gr, oa->areaid, rts[i]);
tmp = ospf_hash_find(po->gr, oa->areaid, rts[i], rts[i], LSA_T_RT);
if (tmp != NULL) if (tmp != NULL)
DBG("Found :-)\n"); DBG("Found :-)\n");
else else
@ -431,8 +451,7 @@ ospf_rt_spfa(struct ospf_area *oa)
{ {
if ((iface->type == OSPF_IT_VLINK) && (iface->voa == oa)) if ((iface->type == OSPF_IT_VLINK) && (iface->voa == oa))
{ {
/* FIXME in OSPFv3, different LSAID */ if ((tmp = ospf_hash_find_rt(po->gr, oa->areaid, iface->vid)) &&
if ((tmp = ospf_hash_find(po->gr, oa->areaid, iface->vid, iface->vid, LSA_T_RT)) &&
(!ipa_equal(tmp->lb, IPA_NONE))) (!ipa_equal(tmp->lb, IPA_NONE)))
{ {
if ((iface->state != OSPF_IS_PTP) || (iface->iface != tmp->nhi->iface) || (!ipa_equal(iface->vip, tmp->lb))) if ((iface->state != OSPF_IS_PTP) || (iface->iface != tmp->nhi->iface) || (!ipa_equal(iface->vip, tmp->lb)))
@ -1187,8 +1206,7 @@ again1:
{ {
if ((ifa->type == OSPF_IT_VLINK) && ipa_equal(ifa->vip, nf->n.nh)) if ((ifa->type == OSPF_IT_VLINK) && ipa_equal(ifa->vip, nf->n.nh))
{ {
/* FIXME in OSPFv3, may be different LSA ID */ if ((en = ospf_hash_find_rt(po->gr, ifa->voa->areaid, ifa->vid))
if ((en = ospf_hash_find(po->gr, ifa->voa->areaid, ifa->vid, ifa->vid, LSA_T_RT))
&& (!ipa_equal(en->nh, IPA_NONE))) && (!ipa_equal(en->nh, IPA_NONE)))
{ {
a0.gw = en->nh; a0.gw = en->nh;

View file

@ -1303,15 +1303,19 @@ static inline unsigned
ospf_top_hash(struct top_graph *f, u32 domain, u32 lsaid, u32 rtrid, u32 type) ospf_top_hash(struct top_graph *f, u32 domain, u32 lsaid, u32 rtrid, u32 type)
{ {
/* In OSPFv2, we don't know Router ID when looking for network LSAs. /* In OSPFv2, we don't know Router ID when looking for network LSAs.
dirty patch to make rt table calculation work. */ In OSPFv3, we don't know LSA ID when looking for router LSAs.
In both cases, there is (usually) just one (or small number)
appropriate LSA, so we just clear unknown part of key. */
return (ospf_top_hash_u32(lsaid) + type + return (
#ifdef OSPFv2 #ifdef OSPFv2
((type == LSA_T_NET) ? 0 : ospf_top_hash_u32(rtrid)) + ((type == LSA_T_NET) ? 0 : ospf_top_hash_u32(rtrid)) +
ospf_top_hash_u32(lsaid) +
#else /* OSPFv3 */ #else /* OSPFv3 */
ospf_top_hash_u32(rtrid) + ospf_top_hash_u32(rtrid) +
((type == LSA_T_RT) ? 0 : ospf_top_hash_u32(lsaid)) +
#endif #endif
domain) & f->hash_mask; type + domain) & f->hash_mask;
/* /*
return (ospf_top_hash_u32(lsaid) + ospf_top_hash_u32(rtrid) + return (ospf_top_hash_u32(lsaid) + ospf_top_hash_u32(rtrid) +
@ -1423,27 +1427,81 @@ struct top_hash_entry *
ospf_hash_find(struct top_graph *f, u32 domain, u32 lsa, u32 rtr, u32 type) ospf_hash_find(struct top_graph *f, u32 domain, u32 lsa, u32 rtr, u32 type)
{ {
struct top_hash_entry *e; struct top_hash_entry *e;
e = f->hash_table[ospf_top_hash(f, domain, lsa, rtr, type)]; e = f->hash_table[ospf_top_hash(f, domain, lsa, rtr, type)];
#ifdef OSPFv2
/* dirty patch to make rt table calculation work. */
if (type == LSA_T_NET)
{
while (e && (e->lsa.id != lsa || e->lsa.type != LSA_T_NET || e->domain != domain))
e = e->next;
return e;
}
#endif
while (e && (e->lsa.id != lsa || e->lsa.type != type || e->lsa.rt != rtr || e->domain != domain)) while (e && (e->lsa.id != lsa || e->lsa.type != type || e->lsa.rt != rtr || e->domain != domain))
e = e->next; e = e->next;
return e; return e;
} }
#ifdef OSPFv2
/* In OSPFv2, sometimes we don't know Router ID when looking for network LSAs.
There should be just one, so we find any match. */
struct top_hash_entry *
ospf_hash_find_net(struct top_graph *f, u32 domain, u32 lsa)
{
struct top_hash_entry *e;
e = f->hash_table[ospf_top_hash(f, domain, lsa, 0, LSA_T_NET)];
while (e && (e->lsa.id != lsa || e->lsa.type != LSA_T_NET || e->domain != domain))
e = e->next;
return e;
}
#endif
#ifdef OSPFv3
/* In OSPFv3, usually we don't know LSA ID when looking for router
LSAs. We return matching LSA with smallest LSA ID. */
struct top_hash_entry *
ospf_hash_find_rt(struct top_graph *f, u32 domain, u32 rtr)
{
struct top_hash_entry *rv = NULL;
struct top_hash_entry *e;
e = f->hash_table[ospf_top_hash(f, domain, 0, rtr, LSA_T_RT)];
while (e)
{
if (e->lsa.rt == rtr && e->lsa.type == LSA_T_RT && e->domain == domain)
if (!rv || e->lsa.id < rv->lsa.id)
rv = e;
e = e->next;
}
return rv;
}
static inline struct top_hash_entry *
find_matching_rt(struct top_hash_entry *e, u32 domain, u32 rtr)
{
while (e && (e->lsa.rt != rtr || e->lsa.type != LSA_T_RT || e->domain != domain))
e = e->next;
return e;
}
struct top_hash_entry *
ospf_hash_find_rt_first(struct top_graph *f, u32 domain, u32 rtr)
{
struct top_hash_entry *e;
e = f->hash_table[ospf_top_hash(f, domain, 0, rtr, LSA_T_RT)];
return find_matching_rt(e, domain, rtr);
}
struct top_hash_entry *
ospf_hash_find_rt_next(struct top_hash_entry *e)
{
return find_matching_rt(e->next, e->domain, e->lsa.rt);
}
#endif
struct top_hash_entry * struct top_hash_entry *
ospf_hash_get(struct top_graph *f, u32 domain, u32 lsa, u32 rtr, u32 type) ospf_hash_get(struct top_graph *f, u32 domain, u32 lsa, u32 rtr, u32 type)
{ {

View file

@ -72,7 +72,20 @@ void check_sum_lsa(struct proto_ospf *po, ort *nf, int);
void originate_sum_lsa(struct ospf_area *oa, struct fib_node *fn, int type, int metric, u32 options); void originate_sum_lsa(struct ospf_area *oa, struct fib_node *fn, int type, int metric, u32 options);
void flush_sum_lsa(struct ospf_area *oa, struct fib_node *fn, int type); void flush_sum_lsa(struct ospf_area *oa, struct fib_node *fn, int type);
#ifdef OSPFv2
struct top_hash_entry * ospf_hash_find_net(struct top_graph *f, u32 domain, u32 lsa);
static inline struct top_hash_entry *
ospf_hash_find_rt(struct top_graph *f, u32 domain, u32 rtr)
{
return ospf_hash_find(f, domain, rtr, rtr, LSA_T_RT);
}
#else /* OSPFv3 */
struct top_hash_entry * ospf_hash_find_rt(struct top_graph *f, u32 domain, u32 rtr);
struct top_hash_entry * ospf_hash_find_rt_first(struct top_graph *f, u32 domain, u32 rtr);
struct top_hash_entry * ospf_hash_find_rt_next(struct top_hash_entry *e);
#endif
#endif /* _BIRD_OSPF_TOPOLOGY_H_ */ #endif /* _BIRD_OSPF_TOPOLOGY_H_ */