Nathan Knuth | 418fdc8 | 2016-09-16 22:51:15 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | import logging |
| 4 | |
| 5 | from argparse import ArgumentParser |
| 6 | from store import ObjectStore |
| 7 | from backends.mock import MockBackend |
| 8 | from agent import Agent |
| 9 | |
| 10 | |
| 11 | def parse_options(): |
| 12 | parser = ArgumentParser("pyofagent - Python-based Open Flow Agent") |
| 13 | parser.add_argument("-c", "--controller", #dest="controller", |
| 14 | help="Controller host:port to connect to", metavar="HOST:PORT", |
| 15 | default="localhost:6633") |
| 16 | parser.add_argument("-d", "--devid", dest="datapath_id", |
| 17 | help="Device identified", metavar="DEVID", |
| 18 | default=42) |
| 19 | parser.add_argument("-v", "--verbose", action='store_true', #dest=verbose, |
| 20 | default="enable verbose logging (log-level is DEBUG)") |
| 21 | parser.add_argument("-I", "--in-out-iface", metavar="IN-OUT-IFACE", |
| 22 | help="Local interface to receve/send in-out frames",) |
| 23 | parser.add_argument("-S", "--in-out-stag", metavar="IN-OUT-STAG", |
| 24 | help="Expect/Apply given s-tag when receiving/sending frames"+ |
| 25 | "at the in-out interface") |
| 26 | return parser.parse_args() |
| 27 | |
| 28 | |
| 29 | def main(): |
| 30 | |
| 31 | args = parse_options() |
| 32 | |
| 33 | logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO) |
| 34 | |
| 35 | store = ObjectStore() |
| 36 | backend = MockBackend(store, in_out_iface=args.in_out_iface, |
| 37 | in_out_stag=None if args.in_out_stag is None else int(args.in_out_stag)) |
| 38 | agent = Agent(args.controller, int(args.datapath_id), store, backend) |
| 39 | store.set_agent(agent) |
| 40 | backend.set_agent(agent) |
| 41 | |
| 42 | try: |
| 43 | agent.run() |
| 44 | except KeyboardInterrupt: |
| 45 | logging.info("Ctrl-c received! Shutting down connection and exiting...") |
| 46 | agent.stop() |
| 47 | backend.stop() |
| 48 | |
| 49 | |
| 50 | if __name__ == '__main__': |
| 51 | main() |