def __create_ospf6_global(tgen, input_dict, router, build=False, load_config=True): """ Helper API to create ospf global configuration. Parameters ---------- * `tgen` : Topogen object * `input_dict` : Input dict data, required when configuring from testcase * `router` : router id to be configured. * `build` : Only for initial setup phase this is set as True. Returns ------- True or False """ result = False logger.debug("Entering lib API: __create_ospf_global()") try: ospf_data = input_dict[router]["ospf6"] del_ospf_action = ospf_data.setdefault("delete", False) if del_ospf_action: config_data = ["no ipv6 router ospf"] result = create_common_configuration(tgen, router, config_data, "ospf", build, load_config) return result config_data = [] cmd = "router ospf" config_data.append(cmd) router_id = ospf_data.setdefault("router_id", None) del_router_id = ospf_data.setdefault("del_router_id", False) if del_router_id: config_data.append("no ospf router-id") if router_id: config_data.append("ospf router-id {}".format(router_id)) result = create_common_configuration(tgen, router, config_data, "ospf", build, load_config) except InvalidCLIError: # Traceback errormsg = traceback.format_exc() logger.error(errormsg) return errormsg logger.debug("Exiting lib API: create_ospf_global()") return result
def config_ospf_interface(tgen, topo, input_dict=None, build=False, load_config=True): """ API to configure ospf on router. Parameters ---------- * `tgen` : Topogen object * `topo` : json file data * `input_dict` : Input dict data, required when configuring from testcase * `build` : Only for initial setup phase this is set as True. * `load_config` : Loading the config to router this is set as True. Usage ----- r1_ospf_auth = { "r1": { "links": { "r2": { "ospf": { "authentication": "message-digest", "authentication-key": "ospf", "message-digest-key": "10" } } } } } result = config_ospf_interface(tgen, topo, r1_ospf_auth) Returns ------- True or False """ logger.debug("Enter lib config_ospf_interface") if not input_dict: input_dict = deepcopy(topo) else: input_dict = deepcopy(input_dict) for router in input_dict.keys(): config_data = [] for lnk in input_dict[router]["links"].keys(): if "ospf" not in input_dict[router]["links"][lnk]: logger.debug( "Router %s: ospf configs is not present in" "input_dict, passed input_dict", router, input_dict, ) continue ospf_data = input_dict[router]["links"][lnk]["ospf"] data_ospf_area = ospf_data.setdefault("area", None) data_ospf_auth = ospf_data.setdefault("authentication", None) data_ospf_dr_priority = ospf_data.setdefault("priority", None) data_ospf_cost = ospf_data.setdefault("cost", None) try: intf = topo["routers"][router]["links"][lnk]["interface"] except KeyError: intf = topo["switches"][router]["links"][lnk]["interface"] # interface cmd = "interface {}".format(intf) config_data.append(cmd) # interface area config if data_ospf_area: cmd = "ip ospf area {}".format(data_ospf_area) config_data.append(cmd) # interface ospf auth if data_ospf_auth: if data_ospf_auth == "null": cmd = "ip ospf authentication null" elif data_ospf_auth == "message-digest": cmd = "ip ospf authentication message-digest" else: cmd = "ip ospf authentication" if "del_action" in ospf_data: cmd = "no {}".format(cmd) config_data.append(cmd) if "message-digest-key" in ospf_data: cmd = "ip ospf message-digest-key {} md5 {}".format( ospf_data["message-digest-key"], ospf_data["authentication-key"]) if "del_action" in ospf_data: cmd = "no {}".format(cmd) config_data.append(cmd) if ("authentication-key" in ospf_data and "message-digest-key" not in ospf_data): cmd = "ip ospf authentication-key {}".format( ospf_data["authentication-key"]) if "del_action" in ospf_data: cmd = "no {}".format(cmd) config_data.append(cmd) # interface ospf dr priority if data_ospf_dr_priority in ospf_data: cmd = "ip ospf priority {}".format(ospf_data["priority"]) if "del_action" in ospf_data: cmd = "no {}".format(cmd) config_data.append(cmd) # interface ospf cost if data_ospf_cost in ospf_data: cmd = "ip ospf cost {}".format(ospf_data["cost"]) if "del_action" in ospf_data: cmd = "no {}".format(cmd) config_data.append(cmd) if build: return config_data else: result = create_common_configuration(tgen, router, config_data, "interface_config", build=build) logger.debug("Exiting lib API: create_igmp_config()") return result
def __create_ospf_global(tgen, input_dict, router, build=False, load_config=True): """ Helper API to create ospf global configuration. Parameters ---------- * `tgen` : Topogen object * `input_dict` : Input dict data, required when configuring from testcase * `router` : router to be configured. * `build` : Only for initial setup phase this is set as True. * `load_config` : Loading the config to router this is set as True. Returns ------- True or False """ result = False logger.debug("Entering lib API: __create_ospf_global()") try: ospf_data = input_dict[router]["ospf"] del_ospf_action = ospf_data.setdefault("delete", False) if del_ospf_action: config_data = ["no router ospf"] result = create_common_configuration(tgen, router, config_data, "ospf", build, load_config) return result config_data = [] cmd = "router ospf" config_data.append(cmd) # router id router_id = ospf_data.setdefault("router_id", None) del_router_id = ospf_data.setdefault("del_router_id", False) if del_router_id: config_data.append("no ospf router-id") if router_id: config_data.append("ospf router-id {}".format(router_id)) # redistribute command redistribute_data = ospf_data.setdefault("redistribute", {}) if redistribute_data: for redistribute in redistribute_data: if "redist_type" not in redistribute: logger.debug( "Router %s: 'redist_type' not present in " "input_dict", router) else: cmd = "redistribute {}".format(redistribute["redist_type"]) for red_type in redistribute_data: if "route_map" in red_type: cmd = cmd + " route-map {}".format( red_type["route_map"]) del_action = redistribute.setdefault("delete", False) if del_action: cmd = "no {}".format(cmd) config_data.append(cmd) # area information area_data = ospf_data.setdefault("area", {}) if area_data: for area in area_data: if "id" not in area: logger.debug( "Router %s: 'area id' not present in " "input_dict", router) else: cmd = "area {}".format(area["id"]) if "type" in area: cmd = cmd + " {}".format(area["type"]) del_action = area.setdefault("delete", False) if del_action: cmd = "no {}".format(cmd) config_data.append(cmd) # summary information summary_data = ospf_data.setdefault("summary-address", {}) if summary_data: for summary in summary_data: if "prefix" not in summary: logger.debug( "Router %s: 'summary-address' not present in " "input_dict", router, ) else: cmd = "summary {}/{}".format(summary["prefix"], summary["mask"]) _tag = summary.setdefault("tag", None) if _tag: cmd = "{} tag {}".format(cmd, _tag) _advertise = summary.setdefault("advertise", True) if not _advertise: cmd = "{} no-advertise".format(cmd) del_action = summary.setdefault("delete", False) if del_action: cmd = "no {}".format(cmd) config_data.append(cmd) result = create_common_configuration(tgen, router, config_data, "ospf", build, load_config) except InvalidCLIError: # Traceback errormsg = traceback.format_exc() logger.error(errormsg) return errormsg logger.debug("Exiting lib API: create_ospf_global()") return result
def __create_ospf_global(tgen, input_dict, router, build=False, load_config=True, ospf="ospf"): """ Helper API to create ospf global configuration. Parameters ---------- * `tgen` : Topogen object * `input_dict` : Input dict data, required when configuring from testcase * `router` : router to be configured. * `build` : Only for initial setup phase this is set as True. * `load_config` : Loading the config to router this is set as True. * `ospf` : either 'ospf' or 'ospf6' Usage ----- input_dict = { "routers": { "r1": { "links": { "r3": { "ipv6": "2013:13::1/64", "ospf6": { "hello_interval": 1, "dead_interval": 4, "network": "point-to-point" } } }, "ospf6": { "router_id": "1.1.1.1", "neighbors": { "r3": { "area": "1.1.1.1" } } } } } Returns ------- True or False """ result = False logger.debug("Entering lib API: __create_ospf_global()") try: ospf_data = input_dict[router][ospf] del_ospf_action = ospf_data.setdefault("delete", False) if del_ospf_action: config_data = ["no router {}".format(ospf)] result = create_common_configuration(tgen, router, config_data, ospf, build, load_config) return result config_data = [] cmd = "router {}".format(ospf) config_data.append(cmd) # router id router_id = ospf_data.setdefault("router_id", None) del_router_id = ospf_data.setdefault("del_router_id", False) if del_router_id: config_data.append("no {} router-id".format(ospf)) if router_id: config_data.append("{} router-id {}".format(ospf, router_id)) # redistribute command redistribute_data = ospf_data.setdefault("redistribute", {}) if redistribute_data: for redistribute in redistribute_data: if "redist_type" not in redistribute: logger.debug( "Router %s: 'redist_type' not present in " "input_dict", router) else: cmd = "redistribute {}".format(redistribute["redist_type"]) for red_type in redistribute_data: if "route_map" in red_type: cmd = cmd + " route-map {}".format( red_type["route_map"]) del_action = redistribute.setdefault("delete", False) if del_action: cmd = "no {}".format(cmd) config_data.append(cmd) # area information area_data = ospf_data.setdefault("area", {}) if area_data: for area in area_data: if "id" not in area: logger.debug( "Router %s: 'area id' not present in " "input_dict", router) else: cmd = "area {}".format(area["id"]) if "type" in area: cmd = cmd + " {}".format(area["type"]) del_action = area.setdefault("delete", False) if del_action: cmd = "no {}".format(cmd) config_data.append(cmd) # area interface information for ospf6d only if ospf == "ospf6": area_iface = ospf_data.setdefault("neighbors", {}) if area_iface: for neighbor in area_iface: if "area" in area_iface[neighbor]: iface = input_dict[router]["links"][neighbor][ "interface"] cmd = "interface {} area {}".format( iface, area_iface[neighbor]["area"]) if area_iface[neighbor].setdefault("delete", False): cmd = "no {}".format(cmd) config_data.append(cmd) # summary information summary_data = ospf_data.setdefault("summary-address", {}) if summary_data: for summary in summary_data: if "prefix" not in summary: logger.debug( "Router %s: 'summary-address' not present in " "input_dict", router, ) else: cmd = "summary {}/{}".format(summary["prefix"], summary["mask"]) _tag = summary.setdefault("tag", None) if _tag: cmd = "{} tag {}".format(cmd, _tag) _advertise = summary.setdefault("advertise", True) if not _advertise: cmd = "{} no-advertise".format(cmd) del_action = summary.setdefault("delete", False) if del_action: cmd = "no {}".format(cmd) config_data.append(cmd) result = create_common_configuration(tgen, router, config_data, ospf, build, load_config) except InvalidCLIError: # Traceback errormsg = traceback.format_exc() logger.error(errormsg) return errormsg logger.debug("Exiting lib API: create_ospf_global()") return result