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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
|
{%- set switch_name = options["switch"] %}
{%- import "vars.conf" as v with context %}
{% include "global.conf" %}
{%- set floor_distros = [
'd1.floor',
'd2.floor',
'd3.floor',
'd4.floor',
'd5.floor',
'd6.floor',
]
%}
{%- set all_networks = [] -%}
{%- set networks = {} -%}
{%- set vlans_on_ae = {} -%}
{# SECTION: FIND AND UTSKUTT DISTROS #}
{%- for switchname, interface in v.device_tree[switch_name].items() -%}
{# {{ switchname }}: #}
{%- if "distro-utskutt" in v.switches2[switchname].tags -%}
{%- do all_networks.append(switchname) -%}
{%- if switchname in v.device_tree -%}
{%- for edge_switch_name, interface2 in v.device_tree[switchname].items() -%}
{# {{ edge_switch_name }} #}
{%- do all_networks.append(edge_switch_name) -%}
{%- endfor -%}
{%- endif -%}
{%- else -%}
{%- do all_networks.append(switchname) -%}
{%- endif -%}
{%- endfor -%}
{# SECTION: FIND AND ADD INTERFACES #}
{%- for edge_network_name in all_networks -%}
{%- set net = v.distro_networks[edge_network_name] -%}
{%- set edge_device = objects["public/switches"].switches[edge_network_name] -%}
{%- set port = v.device_tree[switch_name][edge_network_name] -%}
{# dette er hvis kant nettverket er direkte på distro (ikke utskutt) #}
{%- set interfaces = {} -%}
{%- if edge_device.distro_name == switch_name -%}
{%- if switch_name in floor_distros -%}
{%- set ge0 = "-0/0/" ~ v.create_interface_ge0(port) -%}
{%- set ge1 = "-1/0/" ~ v.create_interface_ge0(port) -%}
{%- set ge2 = "-2/0/" ~ v.create_interface_ge0(port) -%}
{%- elif "distro-utskutt" in edge_device.tags -%}
{%- set fpc = v.create_interface_vc(port) -%}
{%- if fpc in ("1", "4") -%} {# FPC 1 and 4 is ex4600 #}
{%- set ge0 = "-" ~ v.create_interface_vc(port) ~ "/0/" ~ v.create_interface_ge0(port) -%}
{%- set ge1 = "-" ~ v.create_interface_vc(port) ~ "/0/" ~ v.create_interface_ge1(port) -%}
{%- else -%}
{%- set ge0 = "-" ~ v.create_interface_vc(port) ~ "/2/" ~ v.create_interface_ge0(port) -%}
{%- set ge1 = "-" ~ v.create_interface_vc(port) ~ "/2/" ~ v.create_interface_ge1(port) -%}
{%- endif -%}
{%- elif switch_name == 'd1.ring' -%}
{%- set ge0 = "-" ~ v.create_interface_vc(port) ~ "/0/" ~ v.create_interface_ge0(port) -%}
{%- set ge1 = "-" ~ v.create_interface_vc(port) ~ "/0/" ~ v.create_interface_ge1(port) -%}
{%- else -%}
{%- set ge0 = "-0/0/" ~ v.create_interface_ge0(port) -%}
{%- set ge1 = "-0/0/" ~ v.create_interface_ge1(port) -%}
{%- endif -%}
{#- må bruke tags fra downstream switch -#}
{%- set if_prefix = 'ge' -%}
{%- if "multirate" in edge_device.tags and "10g-copper" in edge_device.tags -%}
{%- set if_prefix = 'mge' -%}
{%- elif "10g-uplink" in edge_device.tags -%}
{%- set if_prefix = 'xe' -%}
{%- endif -%}
{%- set ae = "ae" ~ v.create_interface_ae(port) -%}
{%- if "distro-utskutt" in edge_device.tags -%}
{%- set ae = v.ustkutt_distro_ae[edge_network_name] -%}
{%- elif "distro-utskutt" in v.switch_tags -%}
{%- set ae = "ae{}".format(net.vlan) -%}
{%- elif switch_name not in floor_distros -%}
{%- set ae = "ae{}".format(net.vlan) -%}
{%- endif -%}
{%- set interfaces = {'ge0': "{}{}".format(if_prefix, ge0), 'ge1': "{}{}".format(if_prefix, ge1), 'ge2': "{}{}".format(if_prefix, ge2)} -%}
{%- else -%}
{% set ae = networks[v.switches[edge_network_name]['distro_name']]['ae'] -%}
{%- endif -%}
{# SECTION: FIND AND ADD VLANS #}
{%- if ae not in vlans_on_ae -%}
{%- do vlans_on_ae.update({ae: []}) -%}
{%- endif -%}
{%- do vlans_on_ae[ae].append(edge_network_name) -%}
{%- if "wifi" in edge_device.tags -%}
{%- do vlans_on_ae[ae].append("aps-mgmt") -%}
{%- do vlans_on_ae[ae].append("ssid-the-gathering") -%}
{% endif %}
{%- if "net-event-arena" in edge_device.tags -%}
{%- do vlans_on_ae[ae].append("event-arena") -%}
{%- endif -%}
{%- if "net-event-artnet" in edge_device.tags -%}
{%- do vlans_on_ae[ae].append("event-artnet") -%}
{%- endif -%}
{%- if "net-event-activities" in edge_device.tags -%}
{%- do vlans_on_ae[ae].append("event-activites") -%}
{%- endif -%}
{%- if "net-location-beredskap" in edge_device.tags -%}
{%- do vlans_on_ae[ae].append("location-beredskap") -%}
{%- endif -%}
{# uggc Mapping edge '{{ edge_network_name }}' Downlink: {{ ae }} If:{{ interfaces }} Edge tags: {{ edge_device.tags }} Vlans on AE: {{ vlans_on_ae[ae] }} #}
{%- do networks.update({ edge_network_name:
{'l3_device': 'r1.tele',
'ae' : ae,
'vlan_id': net.vlan if net else none,
'if_prefix' : if_prefix,
'interfaces' : interfaces,
'edge_switch_tags' : edge_device.tags,
'distro' : switch_name
}})
%}
{%- endfor %}
{# SECTION: JUNOS CONFIG#}
{%- if switch_name in floor_distros %}
interfaces {
interface-range aps {
{% if "multirate" in v.switch_tags %}
member-range mge-0/0/46 to mge-0/0/47;
member-range mge-1/0/46 to mge-1/0/47;
member-range mge-2/0/46 to mge-2/0/47;
description "C: AP - VLAN 777 untagged (mgmt) - VLAN 778 tagged";
unit 0 {
family ethernet-switching {
port-mode trunk;
native-vlan-id 777;
vlan {
members [ ssid-the-gathering ];
}
}
}
{% elif switch_name in floor_distros %}
member-range ge-0/0/36 to ge-0/0/47;
member-range ge-1/0/36 to ge-1/0/47;
member-range ge-2/0/36 to ge-2/0/47;
description "C: AP - VLAN 777 untagged (mgmt) - VLAN 778 tagged";
unit 0 {
family ethernet-switching {
native-vlan-id 777;
port-mode trunk;
vlan {
members [ ssid-the-gathering ];
}
}
}
{% endif %}
}
}
{%- endif %}
{# SECTION: JUNOS DOWNSTREAM-INTERFACES #}
interfaces {
{% for network_name, network in networks.items() %}
{% if network.distro == switch_name and network.interfaces|length > 0 %}
{{ network.interfaces['ge0'] }} {
description "G: {{ network_name }} {{ network.if_prefix }}-0/0/44 ({{ network.ae }})";
{# This is due to FAP. One uplink to switch can't be in LAG since its
not configured on the other end. And for FAP to work it has to be able
to be able to get DHCP. Therefor, we check if the AE to switch is UP.
If it is not then we configure one link to not be in the LAG #}
{% if v.states[network.distro] is defined and v.states[network.distro].ifs[network.ae] is defined and v.states[network.distro].ifs[network.ae].live is defined %}
ether-options {
802.3ad {{ network.ae }};
}
inactive: unit 0 {
family ethernet-switching {
port-mode access;
vlan {
members edge-mgmt;
}
}
}
{% else %}
inactive: ether-options {
802.3ad {{ network.ae }};
}
unit 0 {
family ethernet-switching {
port-mode access;
vlan {
members edge-mgmt;
}
}
}
{% endif %}
}
{% if "2-uplinks" in network.edge_switch_tags or "3-uplinks" in network.edge_switch_tags %}
{{ network.interfaces['ge1'] }} {
description "G: {{ network_name }} {{ network.if_prefix }}-0/0/45 ({{ network.ae }})";
ether-options {
802.3ad {{ network.ae }};
}
}
{% endif %}
{% if "3-uplinks" in network.edge_switch_tags %}
{{ network.interfaces['ge2'] }} {
description "G: {{ network_name }} {{ network.if_prefix }}-0/0/46 ({{ network.ae }})";
ether-options {
802.3ad {{ network.ae }};
}
}
{% endif %}
{{ network.ae }} {
description "B: {{ network_name }} ae0";
aggregated-ether-options {
lacp {
active;
}
}
unit 0 {
family ethernet-switching {
port-mode trunk;
vlan {
members [ edge-mgmt {% if "distro-utskutt" in network.edge_switch_tags %} distro-mgmt {% endif %} {% for net in vlans_on_ae[network.ae] %}{% if net == network_name and "distro-utskutt" in network.edge_switch_tags %}{% else %}{{ net }} {% endif %}{% endfor %} ];
}
}
}
}
{% endif %}
{% endfor %}
}
{# SECTION: JUNOS CORE-INTERFACES #}
interfaces {
{{ v.distrodata[switch_name]['if1'] }} {
description "G: {{v.distrodata[switch_name]['uplink_device']}} {{ v.distrodata[switch_name]['remote_phy1'] }} (ae0)";
ether-options {
802.3ad ae0;
}
}
{{ v.distrodata[switch_name]['if2'] }} {
description "G: {{v.distrodata[switch_name]['uplink_device']}} {{ v.distrodata[switch_name]['remote_phy2'] }} (ae0)";
ether-options {
802.3ad ae0;
}
}
ae0 {
description "B: {{v.distrodata[switch_name]['uplink_device']}} {{ v.distrodata[switch_name]['remote_ae'] }}";
aggregated-ether-options {
lacp {
active;
}
}
unit 0 {
family ethernet-switching {
port-mode trunk;
vlan {
members all;
}
}
}
}
}
event-options {
{% for network_name, network in networks.items() %}
{% if network.distro == switch_name and network.interfaces|length > 0 %}
policy {{ network.ae }}down {
events snmp_trap_link_down;
attributes-match {
snmp_trap_link_down.interface-name matches "{{ network.ae }}$";
}
then {
change-configuration {
retry count 10 interval 10;
commands {
"activate interfaces {{ network.interfaces['ge0'] }} unit 0";
"deactivate interfaces {{ network.interfaces['ge0'] }} ether-options";
}
user-name tech;
commit-options {
log "Autoconfig-script: {{ network.ae }} went down so removed {{ network.interfaces['ge0'] }} from bundle";
}
}
}
}
policy {{ network.ae }}up {
events snmp_trap_link_up;
attributes-match {
snmp_trap_link_up.interface-name matches "{{ network.ae }}$";
}
then {
change-configuration {
retry count 10 interval 10;
commands {
"deactivate interfaces {{ network.interfaces['ge0'] }} unit 0";
"activate interfaces {{ network.interfaces['ge0'] }} ether-options";
}
user-name tech;
commit-options {
log "Autoconfig-script: {{ network.ae }} came up so added {{ network.interfaces['ge0'] }} to bundle";
}
}
}
}
{% endif %}
{% endfor %}
}
vlans {
{% if switch_name == 'd1.ring' %}
southcam {
vlan-id 10;
}
tele-ipmi {
vlan-id 11;
}
{% endif %}
{% if switch_name not in floor_distros %}
event-arena {
vlan-id 3000;
}
event-artnet {
vlan-id 3001;
}
event-activites {
vlan-id 3002;
}
location-beredskap {
vlan-id 3003;
}
{% endif %}
edge-mgmt {
vlan-id 666;
}
distro-mgmt {
vlan-id 667;
l3-interface vlan.667;
}
{% for network_name, network in networks.items() %}
{%- if network.vlan_id is not none %}
{{ network_name }} {
vlan-id {{ network.vlan_id }};
}
{% endif %}
{% endfor %}
aps-mgmt {
vlan-id 777;
}
ssid-the-gathering {
vlan-id 778;
}
}
protocols {
lldp {
port-id-subtype interface-name;
port-description-type interface-description;
interface all;
}
}
interfaces {
vlan {
unit 667 {
description "switch management";
family inet {
filter {
input mgmt-v4;
}
address {{ v.switches[switch_name]['mgmt_v4_addr'] }}/{{ v.switch_management_network['subnet4'] | cidr }};
}
family inet6 {
filter {
input mgmt-v6;
}
address {{ v.switches[switch_name]['mgmt_v6_addr'] }}/{{ v.switch_management_network['subnet6'] | cidr }};
}
}
}
}
routing-options {
rib inet.0 {
static {
route 0.0.0.0/0 next-hop {{ v.switch_management_network.gw4 }};
}
}
rib inet6.0 {
static {
route ::/0 next-hop {{ v.switch_management_network.gw6 }};
}
}
}
protocols {
rstp {
{% if "distro-utskutt" in v.switch_tags %}
bridge-priority 4k;
{% else %}
bridge-priority 8k;
{% endif %}
}
}
ethernet-switching-options {
storm-control {
{% for network_name, network in networks.items() %}
{%- if network.ae is defined %}
interface {{ network.ae }};
{% endif %}
{% endfor %}
}
secure-access-port {
vlan edge-mgmt {
dhcp-option82 {
circuit-id {
prefix hostname;
use-vlan-id;
}
}
}
}
}
{# some static ports on d1.ring #}
{% if switch_name == 'd1.ring' %}
interfaces {
ge-0/0/23 {
description "C: southcam - VLAN 10 (static-ip)";
unit 0 {
family ethernet-switching {
vlan {
members southcam;
}
}
}
}
ge-5/0/22 {
description "C: bamsemums-ipmi - VLAN 11";
unit 0 {
family ethernet-switching {
vlan {
members tele-ipmi;
}
}
}
}
ge-5/0/23 {
description "C: krokodille-ipmi - VLAN 11";
unit 0 {
family ethernet-switching {
vlan {
members tele-ipmi;
}
}
}
}
}
{% endif %}
{% if v.vc_config[switch_name] %}
virtual-chassis {
preprovisioned;
vcp-snmp-statistics;
{% for member in v.vc_config[switch_name] %}
member {{ loop.index-1 }} {
serial-number {{ member.sn }};
{% if member.re %}
role routing-engine;
{% else %}
role line-card;
{% endif %}
{% if member.loc is defined %}
location {{ member.loc }};
{% endif %}
}
{% endfor %}
}
{% endif %}
|