blob: c828535c547a96364d771fea9fc2e66c9037ce1e [file] [log] [blame]
Nathan Knuth418fdc82016-09-16 22:51:15 -07001#!/usr/bin/env python
Zack Williams41513bf2018-07-07 20:08:35 -07002# Copyright 2017-present Open Networking Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
Nathan Knuth418fdc82016-09-16 22:51:15 -070015
16import logging
17
18from argparse import ArgumentParser
19from store import ObjectStore
20from backends.mock import MockBackend
21from agent import Agent
22
23
24def parse_options():
25 parser = ArgumentParser("pyofagent - Python-based Open Flow Agent")
26 parser.add_argument("-c", "--controller", #dest="controller",
27 help="Controller host:port to connect to", metavar="HOST:PORT",
28 default="localhost:6633")
29 parser.add_argument("-d", "--devid", dest="datapath_id",
30 help="Device identified", metavar="DEVID",
31 default=42)
32 parser.add_argument("-v", "--verbose", action='store_true', #dest=verbose,
33 default="enable verbose logging (log-level is DEBUG)")
34 parser.add_argument("-I", "--in-out-iface", metavar="IN-OUT-IFACE",
35 help="Local interface to receve/send in-out frames",)
36 parser.add_argument("-S", "--in-out-stag", metavar="IN-OUT-STAG",
37 help="Expect/Apply given s-tag when receiving/sending frames"+
38 "at the in-out interface")
39 return parser.parse_args()
40
41
42def main():
43
44 args = parse_options()
45
46 logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO)
47
48 store = ObjectStore()
49 backend = MockBackend(store, in_out_iface=args.in_out_iface,
50 in_out_stag=None if args.in_out_stag is None else int(args.in_out_stag))
51 agent = Agent(args.controller, int(args.datapath_id), store, backend)
52 store.set_agent(agent)
53 backend.set_agent(agent)
54
55 try:
56 agent.run()
57 except KeyboardInterrupt:
58 logging.info("Ctrl-c received! Shutting down connection and exiting...")
59 agent.stop()
60 backend.stop()
61
62
63if __name__ == '__main__':
64 main()