@app.route('/config/acl/<rspId>', methods=['DELETE']) def remove_acl(rspId): check_nfq_classifier_state() nfq_classifier.remove_acl_rsp(rspId) return '', 200 # @app.route('/rsp', methods=['PUT']) # def update_rsp(): # r_json = flask.request.get_json() # nfq_classifier._set_rsp(r_json) # return '', 200 if __name__ == "__main__": try: classifier.start_classifier() nfq_classifier.set_fwd_socket('127.0.0.1') app.run(host='0.0.0.0', port=5100, debug=True, use_reloader=False) except: pass finally: classifier.clear_classifier() # not a great way how to exit, but it works and prevents the # `Exception ignored in: ...` message from beeing displayed os.kill(os.getpid(), signal.SIGTERM) ''' { "rsp":{ "rspId1": [], "rspId2": []
def main(): """Create a CLI parser for the SFC Agent and execute appropriate actions""" #: default values agent_port = 5000 odl_auto_sff = False ovs_local_sff_cp_ip = '0.0.0.0' debug_level = True #: setup parser ----------------------------------------------------------- parser = argparse.ArgumentParser(description='SFC Agent', usage=("\npython3.5 sfc_agent " "--rest " "--nfq-class " "--odl-get-sff " "--debug-level " "--NSH-type" "--legacy-vxlan" "--ovs-sff-cp-ip <local SFF IP dataplane address> " "--odl-ip-port=<ODL REST IP:port> --sff-name=<my SFF name>" "--sff-os=<agent os>" " --agent-port=<agent listening port>" "\n\nnote:\n" "root privileges are required " "if `--nfq-class` flag is used")) parser.add_argument('--odl-get-sff', action='store_true', help='Get SFF from ODL') parser.add_argument('--auto-sff-name', action='store_true', help='Automatically get SFF name') parser.add_argument('--nfq-class', action='store_true', help='Flag to use NFQ Classifier') parser.add_argument('-r', '--rest', action='store_true', help='Flag to use REST') parser.add_argument('--sff-name', help='Set SFF name') parser.add_argument('--debug-level', action='store_true', help='Set logging level to DEBUG') parser.add_argument('--odl-ip-port', help='Set ODL IP and port in form <IP>:<PORT>. ' 'Default is %s' % sfc_globals.get_odl_locator()) parser.add_argument('--NSH-type', choices=['1', '3'], help='Set NSH type ' 'Default is %s' % sfc_globals.get_nsh_type()) parser.add_argument('--legacy-vxlan', action='store_true', help='Using Vxlan header instead of Vxlan-gpe') parser.add_argument('--ovs-sff-cp-ip', help='Set local SFF Open vSwitch IP. ' 'Default is %s' % ovs_local_sff_cp_ip) parser.add_argument('--sff-os', choices=['XE', 'XR', 'OVS'], help='Set SFF switch OS') parser.add_argument('--agent-port', type=int, help='Set SFC Agent port. Default is %s' % agent_port) #: parse CMD arguments ---------------------------------------------------- args = parser.parse_args() if args.odl_ip_port is not None: sfc_globals.set_odl_locator(args.odl_ip_port) logger.info('ODL locator: %s', sfc_globals.get_odl_locator()) if args.agent_port is not None: agent_port = args.agent_port if args.ovs_sff_cp_ip is not None: ovs_local_sff_cp_ip = args.ovs_sff_cp_ip if args.auto_sff_name: odl_auto_sff = True args.odl_get_sff = True if args.sff_name is not None: sfc_globals.set_my_sff_name(args.sff_name) if args.NSH_type is not None: sfc_globals.set_nsh_type(args.NSH_type) if args.legacy_vxlan is not None: sfc_globals.set_legacy_vxlan(True) else: sfc_globals.set_legacy_vxlan(False) if args.debug_level is not None: debug_level = args.debug_level if args.sff_os is not None: sff_os = args.sff_os sfc_globals.set_sff_os(sff_os) if sff_os not in sfc_globals.sff_os_set: logger.error(sff_os + ' is an unsupported SFF switch OS') sys.exit() if sff_os == "OVS": ovs_cli.init_ovs() #: execute actions -------------------------------------------------------- try: #if debug_level: # logging.basicConfig(level=logging.DEBUG) #else: # logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.DEBUG) logger.info("\n\n====== STARTING SFC AGENT ======") logger.info("\n\nSFC Agent will listen to Opendaylight REST Messages and take any\n" "appropriate action such as creating, deleting, updating SFs, SFFs,\n " "or classifier. \n") if args.odl_get_sff: get_sffs_from_odl(sfc_globals.get_odl_locator()) if odl_auto_sff: auto_sff_name() if args.nfq_class: classifier.start_classifier() if args.rest: app.run(port=agent_port, host=ovs_local_sff_cp_ip, debug=False, use_reloader=False) except KeyboardInterrupt: pass finally: classifier.clear_classifier() # not a great way how to exit, but it works and prevents the # `Exception ignored in: ...` message from beeing displayed os.kill(os.getpid(), signal.SIGTERM)
def main(): """Create a CLI parser for the SFC Agent and execute appropriate actions""" #: default values agent_port = 5000 odl_auto_sff = False ovs_local_sff_cp_ip = '0.0.0.0' debug_level = False #: setup parser ----------------------------------------------------------- parser = argparse.ArgumentParser( description='SFC Agent', usage=("\npython3.5 sfc_agent " "--rest " "--nfq-class " "--odl-get-sff " "--debug-level " "--NSH-type" "--legacy-vxlan" "--ovs-sff-cp-ip <local SFF IP dataplane address> " "--odl-ip-port=<ODL REST IP:port> --sff-name=<my SFF name>" "--sff-os=<agent os>" " --agent-port=<agent listening port>" "\n\nnote:\n" "root privileges are required " "if `--nfq-class` flag is used")) parser.add_argument('--odl-get-sff', action='store_true', help='Get SFF from ODL') parser.add_argument('--auto-sff-name', action='store_true', help='Automatically get SFF name') parser.add_argument('--nfq-class', action='store_true', help='Flag to use NFQ Classifier') parser.add_argument('-r', '--rest', action='store_true', help='Flag to use REST') parser.add_argument('--sff-name', help='Set SFF name') parser.add_argument('--debug-level', action='store_true', help='Set logging level to DEBUG') parser.add_argument('--odl-ip-port', help='Set ODL IP and port in form <IP>:<PORT>. ' 'Default is %s' % sfc_globals.get_odl_locator()) parser.add_argument('--NSH-type', choices=['1', '3'], help='Set NSH type ' 'Default is %s' % sfc_globals.get_nsh_type()) parser.add_argument('--legacy-vxlan', action='store_true', help='Using Vxlan header instead of Vxlan-gpe') parser.add_argument('--ovs-sff-cp-ip', help='Set local SFF Open vSwitch IP. ' 'Default is %s' % ovs_local_sff_cp_ip) parser.add_argument('--sff-os', choices=['XE', 'XR', 'OVS'], help='Set SFF switch OS') parser.add_argument('--agent-port', type=int, help='Set SFC Agent port. Default is %s' % agent_port) #: parse CMD arguments ---------------------------------------------------- args = parser.parse_args() if args.odl_ip_port is not None: sfc_globals.set_odl_locator(args.odl_ip_port) logger.info('ODL locator: %s', sfc_globals.get_odl_locator()) if args.agent_port is not None: agent_port = args.agent_port if args.ovs_sff_cp_ip is not None: ovs_local_sff_cp_ip = args.ovs_sff_cp_ip if args.auto_sff_name: odl_auto_sff = True args.odl_get_sff = True if args.sff_name is not None: sfc_globals.set_my_sff_name(args.sff_name) if args.NSH_type is not None: sfc_globals.set_nsh_type(args.NSH_type) if args.legacy_vxlan is not None: sfc_globals.set_legacy_vxlan(True) else: sfc_globals.set_legacy_vxlan(False) if args.debug_level is not None: debug_level = args.debug_level if args.sff_os is not None: sff_os = args.sff_os sfc_globals.set_sff_os(sff_os) if sff_os not in sfc_globals.sff_os_set: logger.error(sff_os + ' is an unsupported SFF switch OS') sys.exit() if sff_os == "OVS": ovs_cli.init_ovs() #: execute actions -------------------------------------------------------- try: if debug_level: logging.basicConfig(level=logging.DEBUG) else: logging.basicConfig(level=logging.INFO) logger.info("\n\n====== STARTING SFC AGENT ======") logger.info( "\n\nSFC Agent will listen to Opendaylight REST Messages and take any\n" "appropriate action such as creating, deleting, updating SFs, SFFs,\n " "or classifier. \n") if args.odl_get_sff: get_sffs_from_odl(sfc_globals.get_odl_locator()) if odl_auto_sff: auto_sff_name() if args.nfq_class: classifier.start_classifier() if args.rest: app.run(port=agent_port, host=ovs_local_sff_cp_ip, debug=False, use_reloader=False) except KeyboardInterrupt: pass finally: classifier.clear_classifier() # not a great way how to exit, but it works and prevents the # `Exception ignored in: ...` message from beeing displayed os.kill(os.getpid(), signal.SIGTERM)