GENIExperimenter/Tutorials/SystematicExprCaseStudy/SmallTopoQuagga/DesignSetup: ospfd-conf-gen.awk

File ospfd-conf-gen.awk, 2.2 KB (added by xliu@bbn.com, 10 years ago)
Line 
1# This script is to generate ospfd.conf for each VMs running xorp
2BEGIN {
3        iface_index = 0
4        ip_index = 0
5        count = 0
6        date = ARGV[2]
7        prefix = ARGV[3]
8        ARGV[2] = ""
9        ARGV[3] = ""
10        small = 255
11}
12{
13
14        if ( NR == 1) {
15                hostname = $0
16                #print hostname
17        }
18        else {
19                if ($1 ~ /eth/ && $1 != "eth0" ) {
20                        #getline;
21                        #print $1;
22                        iface_list[iface_index] = $1;
23                        getline;
24                        split($2, ip, ":")
25                        #print ip[2]
26                        ip_list[ip_index] = ip[2];
27                        count ++;
28                        iface_index++
29                        ip_index++
30                }
31
32        }
33   
34       
35} END {
36
37    for (i=0; i<count; i++) {
38                split(ip_list[i], a, ".")
39                if ( a[3] <= small ) {
40                        small = a[3]
41                }
42        }
43        #print small
44        for (i=0; i<count;i++) {
45                split(ip_list[i], a, ".")
46                if ( a[3] == small) {
47                        #print ip_list[i]
48                        router_id = ip_list[i]
49                        break
50                }
51        }
52
53        # print header
54        printf("/* OSPF configuration file for XORP \n *\n")
55    printf(" * Host: %s\n * DATE: %s\n * \n */\n\n", hostname, date)
56       
57        # print interface information
58        printf("interfaces {\n  restore-original-config-on-shutdown: false\n")
59        for (i = 0; i < count; i++) {
60                #printf("iface: %s ip: %s\n", iface_list[i], ip_list[i]);
61                printf("  interface %s { \n", iface_list[i])
62                printf("    description: \"%s-%s\"\n", "virtual interface", iface_list[i])
63                printf("    disable: false\n    discard: false\n")
64                printf("    vif %s {\n", iface_list[i])
65                printf("        disable: false\n        address %s {\n", ip_list[i])
66                printf("\t\t prefix-length: %s\n \t\t disable: false\n  \t}\n    }  \n  }\n", prefix)           
67
68        }
69        printf("}\n\n\n")
70
71        # print fea configuration
72        printf("fea {\n    unicast-forwarding4 {\n        disable: false\n    }\n}\n\n\n")
73
74        # print protocol configuration
75        printf("protocols {\n")
76        printf("    ospf4 {\n")
77        printf("        router-id: %s\n        area 0.0.0.0 {\n", router_id)
78        printf("            area-type:\"normal\"\n")
79        for (i = 0; i < count; i++) {
80                printf("            interface %s {\n", iface_list[i])
81                printf("                vif %s {\n", iface_list[i])
82                printf("                  address %s {\n", ip_list[i])
83                printf("                    interface-cost 10\n")
84                printf("                    hello-interval 5\n")
85                printf("                    router-dead-interval 10\n")
86                printf("                    disable: false\n")
87                printf("                  }\n")
88                printf("                }\n")
89                printf("            }\n")
90
91
92
93        }
94        printf("        }\n")
95        printf("    }\n")
96        printf("}\n")
97}