]> git.puffer.fish Git - matthieu/frr.git/commitdiff
ldpd: change the sorting algorithm of adjacencies
authorRenato Westphal <renato@opensourcerouting.org>
Sat, 18 Mar 2017 20:05:35 +0000 (17:05 -0300)
committerRenato Westphal <renato@opensourcerouting.org>
Tue, 21 Mar 2017 00:42:14 +0000 (21:42 -0300)
Now the "show mpls ldp discovery" command will display all LDP
adjancencies sorted by address family, neighbor ID and then type (link
or targeted).

Example:
vtysh# show mpls ldp discovery
AF   ID              Type     Source           Holdtime
ipv4 3.3.3.3         Link     rt2-eth1               15
ipv4 3.3.3.3         Link     rt2-eth2               15
ipv4 4.4.4.4         Link     rt2-eth1               15
ipv6 1.1.1.1         Link     rt2-eth0               15
ipv6 3.3.3.3         Link     rt2-eth1               15
ipv6 3.3.3.3         Link     rt2-eth2               15
ipv6 4.4.4.4         Link     rt2-eth1               15

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
ldpd/adjacency.c
ldpd/hello.c
ldpd/ldpe.h

index 2e7b43296a2d4d1e9f5edc25678b14bd3e1c42af..244d0f55a272cc6d112fb63af5cdefc7ce0ce26e 100644 (file)
@@ -41,6 +41,16 @@ RB_GENERATE(tnbr_head, tnbr, entry, tnbr_compare)
 static __inline int
 adj_compare(struct adj *a, struct adj *b)
 {
+       if (adj_get_af(a) < adj_get_af(b))
+               return (-1);
+       if (adj_get_af(a) > adj_get_af(b))
+               return (1);
+
+       if (ntohl(a->lsr_id.s_addr) < ntohl(b->lsr_id.s_addr))
+               return (-1);
+       if (ntohl(a->lsr_id.s_addr) > ntohl(b->lsr_id.s_addr))
+               return (1);
+
        if (a->source.type < b->source.type)
                return (-1);
        if (a->source.type > b->source.type)
@@ -54,21 +64,13 @@ adj_compare(struct adj *a, struct adj *b)
                if (strcmp(a->source.link.ia->iface->name,
                    b->source.link.ia->iface->name) > 0)
                        return (1);
-               if (a->source.link.ia->af < b->source.link.ia->af)
-                       return (-1);
-               if (a->source.link.ia->af > b->source.link.ia->af)
-                       return (1);
                return (ldp_addrcmp(a->source.link.ia->af,
                    &a->source.link.src_addr, &b->source.link.src_addr));
        case HELLO_TARGETED:
-               if (a->source.target->af < b->source.target->af)
-                       return (-1);
-               if (a->source.target->af > b->source.target->af)
-                       return (1);
                return (ldp_addrcmp(a->source.target->af,
                    &a->source.target->addr, &b->source.target->addr));
        default:
-               fatalx("adj_get_af: unknown hello type");
+               fatalx("adj_compare: unknown hello type");
        }
 
        return (0);
@@ -150,9 +152,10 @@ adj_del(struct adj *adj, uint32_t notif_status)
 }
 
 struct adj *
-adj_find(struct hello_source *source)
+adj_find(struct in_addr lsr_id, struct hello_source *source)
 {
        struct adj       adj;
+       adj.lsr_id = lsr_id;
        adj.source = *source;
        return (RB_FIND(global_adj_head, &global.adj_tree, &adj));
 }
index e7935899b71fe8e96763188f516ff0056ca2ff71..19e3013bb8b0c889b1b3226bd7c3e00d46b0aa36 100644 (file)
@@ -291,7 +291,7 @@ recv_hello(struct in_addr lsr_id, struct ldp_msg *msg, int af,
                source.link.src_addr = *src;
        }
 
-       adj = adj_find(&source);
+       adj = adj_find(lsr_id, &source);
        nbr = nbr_find_ldpid(lsr_id.s_addr);
 
        /* check dual-stack tlv */
index 8f2d1931d900daddb1dac646c6b9d792fb0aec5f..4cac18f0b90584755b62a4244b093193a0e175c3 100644 (file)
@@ -232,7 +232,7 @@ in_addr_t    if_get_ipv4_addr(struct iface *);
 struct adj     *adj_new(struct in_addr, struct hello_source *,
                    union ldpd_addr *);
 void            adj_del(struct adj *, uint32_t);
-struct adj     *adj_find(struct hello_source *);
+struct adj     *adj_find(struct in_addr, struct hello_source *);
 int             adj_get_af(struct adj *adj);
 void            adj_start_itimer(struct adj *);
 void            adj_stop_itimer(struct adj *);