|
1 | 1 | #!/usr/bin/python
|
2 | 2 |
|
| 3 | +from argparse import ArgumentParser |
3 | 4 | import os
|
4 | 5 | import shutil
|
| 6 | +from dotenv import load_dotenv |
5 | 7 | from mininet.topo import Topo
|
6 | 8 | from mininet.node import Host
|
7 | 9 | from mininet.net import Mininet
|
|
16 | 18 |
|
17 | 19 | PRIVDIR = '/var/priv'
|
18 | 20 |
|
| 21 | +START_NODE_MANAGERS = False |
| 22 | +NODE_MANAGER_PATH = '' |
| 23 | + |
| 24 | +# Load environment variables from .env file |
| 25 | +load_dotenv() |
| 26 | + |
| 27 | +# Get node manager path |
| 28 | +NODE_MANAGER_PATH = os.getenv('NODE_MANAGER_PATH') |
| 29 | +NODE_MANAGER_PATH.join(NODE_MANAGER_PATH, 'srv6_manager.py') |
| 30 | +# Get gRPC server port |
| 31 | +NODE_MANAGER_GRPC_PORT = os.getenv('NODE_MANAGER_GRPC_PORT') |
| 32 | +NODE_MANAGER_GRPC_PORT.join(NODE_MANAGER_GRPC_PORT, 'srv6_manager.py') |
| 33 | + |
| 34 | + |
19 | 35 | class BaseNode(Host):
|
20 | 36 |
|
21 | 37 | def __init__(self, name, *args, **kwargs):
|
@@ -86,6 +102,15 @@ class Router(BaseNode):
|
86 | 102 | def __init__(self, name, *args, **kwargs):
|
87 | 103 | BaseNode.__init__(self, name, *args, **kwargs)
|
88 | 104 |
|
| 105 | + def config(self, **kwargs): |
| 106 | + # Init steps |
| 107 | + BaseNode.config(self, **kwargs) |
| 108 | + # Start node managers |
| 109 | + if START_NODE_MANAGERS: |
| 110 | + self.cmd('python %s --grpc_port %s' |
| 111 | + % (NODE_MANAGER_PATH % NODE_MANAGER_GRPC_PORT)) |
| 112 | + |
| 113 | + |
89 | 114 | # the add_link function creates a link and assigns the interface names
|
90 | 115 | # as node1-node2 and node2-node1
|
91 | 116 | def add_link (my_net, node1, node2):
|
@@ -216,8 +241,41 @@ def simpleTest():
|
216 | 241 | stopAll()
|
217 | 242 |
|
218 | 243 |
|
| 244 | +def parse_arguments(): |
| 245 | + # Get parser |
| 246 | + parser = ArgumentParser( |
| 247 | + description='Emulation of a Mininet topology (8 routers running ' |
| 248 | + 'IS-IS, 1 controller in-band' |
| 249 | + ) |
| 250 | + parser.add_argument( |
| 251 | + '--start-node-managers', dest='start_node_managers', |
| 252 | + action='store_true', default=False, |
| 253 | + help='Define whether to start node manager on routers or not' |
| 254 | + ) |
| 255 | + # Parse input parameters |
| 256 | + args = parser.parse_args() |
| 257 | + # Return the arguments |
| 258 | + return args |
| 259 | + |
219 | 260 |
|
220 | 261 | if __name__ == '__main__':
|
| 262 | + # Parse command-line arguments |
| 263 | + args = parse_arguments() |
| 264 | + # Define whether to start node manager on routers or not |
| 265 | + START_NODE_MANAGERS = args.start_node_managers |
| 266 | + if START_NODE_MANAGERS: |
| 267 | + if NODE_MANAGER_PATH: |
| 268 | + print('Error: --start-node-managers requires NODE_MANAGER_PATH ' |
| 269 | + 'variable') |
| 270 | + print('NODE_MANAGER_PATH variable is not set in .env file or ' |
| 271 | + 'the variable points to a non existing folder') |
| 272 | + exit(-2) |
| 273 | + if NODE_MANAGER_GRPC_PORT: |
| 274 | + print('Error: --start-node-managers requires ' |
| 275 | + 'NODE_MANAGER_GRPC_PORT variable') |
| 276 | + print('NODE_MANAGER_GRPC_PORT variable is not set in .env file or ' |
| 277 | + 'the variable points to a non existing folder') |
| 278 | + exit(-2) |
221 | 279 | # Tell mininet to print useful information
|
222 | 280 | setLogLevel('info')
|
223 | 281 | simpleTest()
|
0 commit comments