blob: f404df5a6d1f13dbc65747a5018bb0526c837a70 [file] [log] [blame]
Nathan Knuth418fdc82016-09-16 22:51:15 -07001#!/usr/bin/env python
2
3import logging
4
5from argparse import ArgumentParser
6from store import ObjectStore
7from backends.mock import MockBackend
8from agent import Agent
9
10
11def 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
29def 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
50if __name__ == '__main__':
51 main()