-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathadvert.c
165 lines (136 loc) · 5.25 KB
/
advert.c
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
/*
* =====================================================================================
*
* Filename: advert.c
*
* Description: This file implements the routing to distribute node's config/info to other nodes in the network
*
* Version: 1.0
* Created: Sunday 08 October 2017 01:37:36 IST
* Revision: 1.0
* Compiler: gcc
*
* Author: Er. Abhishek Sagar, Networking Developer (AS), [email protected]
* Company: Brocade Communications(Jul 2012- Mar 2016), Current : Juniper Networks(Apr 2017 - Present)
*
* This file is part of the SPFComputation distribution (https://github.com/sachinites).
* Copyright (c) 2017 Abhishek Sagar.
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that 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/>.
*
* =====================================================================================
*/
#include <assert.h>
#include <unistd.h>
#include "advert.h"
#include "instance.h"
#include "spfutil.h"
#include "Queue.h"
#include "spftrace.h"
#include "LinuxMemoryManager/uapi_mm.h"
char *
advert_id_str(ADVERT_ID_T advert_id){
switch(advert_id)
{
case TLV128:
return "TLV128";
case TLV2:
return "TLV2";
default:
assert(0);
}
}
void
lsp_distribution_routine(node_t *lsp_generator,
node_t *lsp_receiver,
dist_info_hdr_t *dist_info){
switch(dist_info->advert_id){
case TLV128:
partial_spf_run(lsp_receiver, dist_info->info_dist_level);
break;
case TLV2:
spf_computation(lsp_receiver, &lsp_receiver->spf_info, dist_info->info_dist_level, FULL_RUN, 0);
break;
case OVERLOAD:
/*Trigger full spf run if router overloads/or unoverloads*/
spf_computation(lsp_receiver, &lsp_receiver->spf_info, dist_info->info_dist_level, FULL_RUN, 0);
break;
default:
;
}
}
void
init_instance_traversal(instance_t * instance){
singly_ll_node_t *list_node = NULL;
node_t *node = NULL;
ITERATE_LIST_BEGIN(instance->instance_node_list, list_node){
node = (node_t *)list_node->data;
node->traversing_bit = 0;
}ITERATE_LIST_END;
}
static void
init_instance_lsp_distribution_traversal(instance_t * instance){
singly_ll_node_t *list_node = NULL;
node_t *node = NULL;
ITERATE_LIST_BEGIN(instance->instance_node_list, list_node){
node = (node_t *)list_node->data;
node->lsp_distribution_bit = 0;
}ITERATE_LIST_END;
}
/*fn to simulate LSP generation and distribution at its simplest.*/
void
generate_lsp(instance_t *instance,
node_t *lsp_generator,
info_dist_fn_ptr fn_ptr, dist_info_hdr_t *dist_info){
node_t *curr_node = NULL,
*nbr_node = NULL,
*pn_node = NULL;
edge_t *edge1 = NULL, /*Edge connecting curr node with PN*/
*edge2 = NULL; /*Edge connecting PN to its nbr*/
LEVEL level_of_info_dist = dist_info->info_dist_level,
level_it = LEVEL_UNKNOWN;
/*distribute the info to self*/
fn_ptr(lsp_generator, lsp_generator, dist_info);
/*distribute info in the network at a given level*/
Queue_t *q = initQ();
for(level_it = LEVEL1 ; level_it < MAX_LEVEL; level_it++){
if(!IS_LEVEL_SET(level_of_info_dist, level_it))
continue;
init_instance_lsp_distribution_traversal(instance);
lsp_generator->lsp_distribution_bit = 1;
enqueue(q, lsp_generator);
unsigned int propogation_delay = 0;
while(!is_queue_empty(q)){
curr_node = deque(q);
sleep(propogation_delay); /*Let us introduce some delay in information propogation*/
ITERATE_NODE_PHYSICAL_NBRS_BEGIN(curr_node, nbr_node, pn_node, edge1,
edge2, level_it){
if(nbr_node->lsp_distribution_bit){
ITERATE_NODE_PHYSICAL_NBRS_CONTINUE(curr_node, nbr_node, pn_node, level_it);
}
#ifdef __ENABLE_TRACE__
sprintf(instance->traceopts->b, "LSP Distribution Src : %s, Des Node : %s",
lsp_generator->node_name, nbr_node->node_name);
trace(instance->traceopts, SPF_EVENTS_BIT);
#endif
fn_ptr(lsp_generator, nbr_node, dist_info);
nbr_node->lsp_distribution_bit = 1;
enqueue(q, nbr_node);
}
ITERATE_NODE_PHYSICAL_NBRS_END(curr_node, nbr_node, pn_node, level_it);
}
assert(is_queue_empty(q));
reuse_q(q);
}
XFREE(q);
q = NULL;
}