def main(argv): """main method for standalone run""" config_generator = FaucetConfigGenerator() filepath = '/tmp/faucet_config_dump' egress = 2 access = 3 devices = 1 argv = argv[1:] try: opts, _ = getopt.getopt(argv, 'he:a:d:p:', ['egress=', 'access=', 'devices=', 'path=']) except getopt.GetoptError: print('<python3> build_config.py -e <egress_switches> -a' '<access_switches> -d <devices per switch> -p <config path>') sys.exit(2) for opt, arg in opts: if opt == '-h': print('<python3> build_config.py -e <egress_switches> -a ' '<access_switches> -d <devices per switch> -p <config path>') sys.exit() elif opt in ('-e', '--egress'): egress = int(arg) elif opt in ('-a', '--access'): access = int(arg) elif opt in ('-d', '--devices'): devices = int(arg) elif opt in ('-p', '--path'): filepath = arg config = proto_dict(config_generator._create_scale_faucet_config(egress, access, devices)) with open(filepath, 'w') as config_file: yaml.dump(config, config_file)
def process_network_state(self, network_state): """Process network state inputs""" self._network_state = proto_dict(network_state, True) sorted_rules = list(self._network_state.get("named_match_rules", {}).keys()) sorted_rules.sort() sys.stdout.write(f'{sorted_rules}\n') sorted_macs = list(self._network_state.get('device_mac_behaviors', {}).keys()) sorted_macs.sort() sys.stdout.write(f'{sorted_macs}\n')
def main(argv): """main method for standalone run""" config_generator = FaucetConfigGenerator() filepath = '/tmp/faucet_config_dump' egress = 2 access = 3 devices = 1 topo_type = STACK argv = argv[1:] help_msg = """ <python3> build_config.py -e <egress_switches> -a <access_switches> -d <devices per switch> -p <config path> -t <topology type (flat, corp, stack)> """ try: opts, _ = getopt.getopt( argv, 'he:a:d:p:t:', ['egress=', 'access=', 'devices=', 'path=', 'type=']) except getopt.GetoptError: print(help_msg) sys.exit(2) for opt, arg in opts: if opt == '-h': print(help_msg) sys.exit() elif opt in ('-e', '--egress'): egress = int(arg) elif opt in ('-a', '--access'): access = int(arg) elif opt in ('-d', '--devices'): devices = int(arg) elif opt in ('-p', '--path'): filepath = arg elif opt in ('-t', '--type'): topo_type = arg if topo_type == FLAT: faucet_config = config_generator.create_flat_faucet_config( access, devices) elif topo_type == CORP: faucet_config = config_generator.create_corp_faucet_config() elif topo_type == STACK: faucet_config = config_generator.create_scale_faucet_config( egress, access, devices) else: raise Exception('Unkown topology type: %s' % topo_type) config_map = cleanup_config(proto_dict(faucet_config)) with open(filepath, 'w') as config_file: yaml.dump(config_map, config_file)
def process_auth_result(self): """Prints Auth example object to out""" base_dir = os.getenv('FORCH_CONFIG_DIR') auth_ex_file = os.path.join(base_dir, 'auth_result.yaml') auth_list = None with open(auth_ex_file, 'r') as stream: try: auth_list = yaml.safe_load(stream).get('auth_list') except yaml.YAMLError as exc: LOGGER.error("Error loading yaml file: %s", exc, exc_info=True) for auth_obj in auth_list: auth_example = dict_proto(auth_obj, AuthResult) sys.stdout.write(str(proto_dict(auth_example)) + '\n')
def _get_system_summary(self, path): states = { 'cpn_state': proto_dict(self._cpn_collector.get_cpn_summary()), 'process_state': self._local_collector.get_process_summary(), 'dataplane_state': self._faucet_collector.get_dataplane_summary(), 'switch_state': self._faucet_collector.get_switch_summary(), 'list_hosts': self._faucet_collector.get_host_summary() } url_base = self._extract_url_base(path) for state in states: summary = states[state] summary['url'] = f'{url_base}/?{state}' return states
def get_sys_config(self, path, params): """Get overall config from faucet config file""" try: _, _, behavioral_config = self._get_faucet_config() faucet_config_map = { 'behavioral': behavioral_config, 'warnings': dict(self._faucet_config_summary.warnings) } reply = { 'faucet': faucet_config_map, 'forch': proto_dict(self._config), 'ryu': self._get_ryu_config() } if self._faucetizer: reply['faucet']['structural'] = self._faucetizer.get_structural_config() return self._augment_state_reply(reply, path) except Exception as e: return f"Cannot read faucet config: {e}"
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.devices = 5 self.switches = 9 self.sim_setup_cmd = 'bin/setup_scale' self.config_path = '/tmp/scale_config' config = proto_dict(FaucetConfigGenerator().create_scale_faucet_config( 2, self.switches, self.devices)) with open(self.config_path, 'w') as config_file: yaml.dump(config, config_file) self.stack_options.update({ 'switches': self.switches, 'mode': 'scale', 'overwrite-faucet-config': self.config_path, 'skip-conn-check': False })
def get_cpn_state(self): """Get CPN state""" cpn_nodes = {} with self._lock: for cpn_node, node_state in self._node_states.items(): cpn_node_map = cpn_nodes.setdefault(cpn_node, {}) cpn_node_map['attributes'] = proto_dict(node_state.get(KEY_NODE_ATTRIBUTES)) cpn_node_map['state'] = node_state.get(KEY_NODE_STATE) ping_result = node_state.get(KEY_NODE_PING_RES, {}).get('stdout') cpn_node_map['ping_results'] = CPNStateCollector._get_ping_summary(ping_result) cpn_node_map['state_change_count'] = node_state.get(KEY_NODE_STATE_COUNT) cpn_node_map['state_last_updated'] = node_state.get(KEY_NODE_STATE_UPDATE_TS) cpn_node_map['state_last_changed'] = node_state.get(KEY_NODE_STATE_CHANGE_TS) return dict_proto({ 'cpn_nodes': cpn_nodes, 'cpn_state': self._cpn_state.get(KEY_CPN_STATE), 'cpn_state_detail': self._cpn_state.get(KEY_CPN_STATE_DETAIL), 'cpn_state_change_count': self._cpn_state.get(KEY_CPN_STATE_COUNT), 'cpn_state_last_update': self._cpn_state.get(KEY_CPN_STATE_UPDATE_TS), 'cpn_state_last_changed': self._cpn_state.get(KEY_CPN_STATE_CHANGE_TS) }, CpnState)
def _get_controller_state(self): with self._active_state_lock: if not self._is_active: detail = 'This controller is inactive. Please view peer controller.' return constants.STATE_INACTIVE, detail cpn_state = self._cpn_collector.get_cpn_state() peer_controller = self._get_peer_controller_name() cpn_nodes = proto_dict(cpn_state).get('cpn_nodes') peer_controller_state = cpn_nodes.get(peer_controller, {}).get('state') if not peer_controller_state: LOGGER.error('Cannot get peer controller state: %s', peer_controller) if cpn_state.cpn_state == constants.STATE_INITIALIZING: detail = 'Initializing' return constants.STATE_INITIALIZING, detail if not peer_controller_state == constants.STATE_HEALTHY: detail = 'Lost reachability to peer controller.' return constants.STATE_SPLIT, detail return constants.STATE_ACTIVE, ''
def _process_devices_state(self, devices_state): devices_state_map = proto_dict(devices_state, including_default_value_fields=True) with self._lock: for mac, device_behavior in devices_state_map['device_mac_behaviors'].items(): self._received_mac_port_behaviors.append((mac, device_behavior['port_behavior']))