13 nw = ipaddr.IPv4Network(ip)
14 return "{}/{}".format(nw.network + 1, nw.prefixlen)
16 if __name__ == '__main__':
18 # Validate all parameters are present
19 parser = argparse.ArgumentParser()
20 parser.add_argument('--local',
21 help='Set up distributed mininet on local host with the specified switch')
22 parser.add_argument('--policy', action='store_true',
23 help='Configure the policy on the controller')
24 parser.add_argument('--controller', default='127.0.0.1',
25 help='Use the specified controller IP address')
26 args = parser.parse_args()
28 if (not args.local and not args.policy):
32 # switches is a list from config.py, when this script is called with --local (switch) and its present in config, it is added to the conf_switches
35 for switch in switches:
36 if switch['name'] == args.local:
37 conf_switches = [switch]
40 # Assuming we have switches defined (and hence conf_switches), start mininet with the "hosts" list also from config.py
42 if len(conf_switches) > 0:
43 net = mininet_gbp.startMininet(conf_switches, hosts, args.controller)
46 for switch in switches:
47 # This leverages a global from odl_gbp called "nodes", which appends "data" from this for loop
48 odl_gbp.get_node_config(switch['dpid'], switch['tunnelIp'])
49 #This also uses the global "nodes" from odl_gbp
50 odl_gbp.register_nodes(args.controller)
52 # TENANT, L3CTX, L2BD are imported from config.py
53 # get_tenant looks for the TENANT UUID in a global tenant dictionary in odl_gbp.
54 # If TENANT doesn't already exist in that dict. then a bunch of 'default' tenant data is defined, inluding
55 # subjects and classifiers (at writing specific to HTTP source/dest and ICMP)
56 tenant = odl_gbp.get_tenant(TENANT)
58 # Layer3 context and Layer BridgeDomain are SET into the tenant{} structure in odl_gbp
59 # TODO: (maybe call these set???)
60 odl_gbp.get_l3c(TENANT, L3CTX)
61 odl_gbp.get_bd(TENANT, L2BD, L3CTX)
63 # subnets and fds (flood domains)
66 # hosts comes from config.py, which contains target switch, IP Address, MAC address, tenant and EPG
69 if args.local and host['switch'] != args.local:
71 nw = ipaddr.IPv4Network(host['ip'])
72 snet = "{}/{}".format(nw.network + 1, nw.prefixlen)
73 router = "{}".format(nw.network + 1)
75 if snet not in subnets:
76 snid = str(uuid.uuid4())
77 fdid = str(uuid.uuid4())
78 # Sets flood domain where parent is L2BD from config.py
79 fds[fdid] = odl_gbp.get_fd(TENANT, fdid, L2BD)
81 # sets subnet from tenant, which also includes the flood domain
82 subnets[snet] = odl_gbp.get_subnet(TENANT, snid, fdid, snet, router)
84 # Sets the "network-domain" in global endpointGroups dict in odl_gbp.py
85 odl_gbp.get_epg(TENANT, host['endpointGroup'])["network-domain"] = snid
87 # Creates EP information and appends to endpoint list, a global
88 odl_gbp.get_ep(TENANT,
89 host['endpointGroup'],
91 re.sub(r'/\d+$', '', host['ip']),
94 int(net.get(host['switch']).dpid), host['port'])
96 # contracts is a global list from config.py.
97 # get_contract creates the specific subject, classifiers, rules etc for the contract
98 # and appends this to the global tenant list.
99 for contract in contracts:
100 odl_gbp.get_contract(TENANT,
101 contract['provider'], contract['consumer'],
104 # POST to the controller to register tenants
106 odl_gbp.register_tenants(args.controller)
108 # POST to controller to register EPS
109 # TODO: Should this be done on a per Tenant basis
110 odl_gbp.register_eps(args.controller)