Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
destinations={
"destination": "10.60.125.45",
"config":[]
}
for request in requests:
# Configure Source Endpoint
temp_source = request["service_config"]["config_rules"][1]["custom"]["resource_value"]
endpoints = request["service_endpoint_ids"]
config = {
"ni_name": temp_source["ni_name"],
"remote_router": temp_source["remote_router"],
"interface": endpoints[0]["endpoint_uuid"]["uuid"].replace("0/0/0-", ""),
"vlan" : temp_source["vlan_id"],
"number" : temp_source["vlan_id"] % 10 + 1
}
sources["config"].append(config)
# Configure Destination Endpoint
temp_destiny = request["service_config"]["config_rules"][2]["custom"]["resource_value"]
config = {
"ni_name": temp_destiny["ni_name"],
"remote_router": temp_destiny["remote_router"],
"interface": endpoints[1]["endpoint_uuid"]["uuid"].replace("0/0/3-", ""),
"vlan" : temp_destiny["vlan_id"],
"number" : temp_destiny["vlan_id"] % 10 + 1
}
destinations["config"].append(config)
#cisco_source = cisco_connector(source_address, ni_name, remote_router, vlan, vlan % 10 + 1)
cisco_source = cisco_connector(sources["source"], sources["config"])
commands = cisco_source.full_create_command_template()
cisco_source.execute_commands(commands)
#cisco_destiny = cisco_connector(destination_address, ni_name, remote_router, vlan, vlan % 10 + 1)
cisco_destiny = cisco_connector(destinations["destination"], destinations["config"])
commands = cisco_destiny.full_create_command_template()
cisco_destiny.execute_commands(commands)
def __tfs_l2vpn_delete(self):
"""
Delete L2VPN configurations from Cisco devices.
This method removes L2VPN configurations from Cisco routers
Notes:
- Uses cisco_connector to generate and execute deletion commands
- Clears Network Interface (NI) settings
"""
# Delete Source Endpoint Configuration
source_address = "10.60.125.44"
cisco_source = cisco_connector(source_address)
cisco_source.execute_commands(cisco_source.create_command_template_delete())
# Delete Destination Endpoint Configuration
destination_address = "10.60.125.45"
cisco_destiny = cisco_connector(destination_address)
cisco_destiny.execute_commands(cisco_destiny.create_command_template_delete())
def __tfs_l3vpn(self, ietf_intent):
"""
Translate L3VPN (Layer 3 Virtual Private Network) intent into a TeraFlow service request.
Similar to __tfs_l2vpn, but configured for Layer 3 VPN:
1. Defines endpoint routers
2. Loads service template
3. Generates unique service UUID
4. Configures service endpoints
5. Adds QoS constraints
6. Prepares configuration rules for network interfaces
Args:
ietf_intent (dict): IETF-formatted network slice intent.
Returns:
dict: A TeraFlow service request for L3VPN configuration.
"""
# Hardcoded router endpoints
# TODO should be dynamically determined
origin_router_id = ietf_intent["ietf-network-slice-service:network-slice-services"]["slice-service"][0]["sdps"]["sdp"][0]["attachment-circuits"]["attachment-circuit"][0]["sdp-peering"]["peer-sap-id"]
origin_router_if = '0/0/0-GigabitEthernet0/0/0/0'
destination_router_id = ietf_intent["ietf-network-slice-service:network-slice-services"]["slice-service"][0]["sdps"]["sdp"][1]["attachment-circuits"]["attachment-circuit"][0]["sdp-peering"]["peer-sap-id"]
# Load L3VPN service template
self.__load_template(2, os.path.join(TEMPLATES_PATH, "L3-VPN_template_empty.json"))
tfs_request = json.loads(str(self.__teraflow_template))["services"][0]
# Generate unique service UUID
tfs_request["service_id"]["service_uuid"]["uuid"] += "-" + str(int(datetime.now().timestamp() * 1e7))
# Configure service endpoints
for endpoint in tfs_request["service_endpoint_ids"]:
endpoint["device_id"]["device_uuid"]["uuid"] = origin_router_id if endpoint is tfs_request["service_endpoint_ids"][0] else destination_router_id
endpoint["endpoint_uuid"]["uuid"] = origin_router_if if endpoint is tfs_request["service_endpoint_ids"][0] else destination_router_if
for i, constraint in enumerate(ietf_intent["ietf-network-slice-service:network-slice-services"]["slo-sle-templates"]["slo-sle-template"][0]["slo-policy"]["metric-bound"]):
bound = ietf_intent["ietf-network-slice-service:network-slice-services"]["slo-sle-templates"]["slo-sle-template"][0]["slo-policy"]["metric-bound"][i]["bound"]
metric_type = ietf_intent["ietf-network-slice-service:network-slice-services"]["slo-sle-templates"]["slo-sle-template"][0]["slo-policy"]["metric-bound"][i]["metric-type"]
metric_unit = ietf_intent["ietf-network-slice-service:network-slice-services"]["slo-sle-templates"]["slo-sle-template"][0]["slo-policy"]["metric-bound"][i]["metric-unit"]
service_constraint ={
"custom": {
"constraint_type": f"{metric_type}[{metric_unit}]",
"constraint_value": f"{bound}"
}
}
self.answer[self.subnet]["QoS Requirements"].append(service_constraint["custom"])
tfs_request["service_constraints"].append(service_constraint)
# Add configuration rules
for i, config_rule in enumerate(tfs_request["service_config"]["config_rules"][1:], start=1):
router_id = origin_router_id if i == 1 else destination_router_id
router_if = origin_router_if if i == 1 else destination_router_if
resource_value = config_rule["custom"]["resource_value"]
sdp_index = i - 1
vlan_value = ietf_intent["ietf-network-slice-service:network-slice-services"]["slice-service"][0]["sdps"]["sdp"][sdp_index]["service-match-criteria"]["match-criterion"][0]["value"]
resource_value["router_id"] = destination_router_id if i == 1 else origin_router_id
resource_value["vlan_id"] = int(vlan_value)
resource_value["address_ip"] = destination_router_id if i == 1 else origin_router_id
resource_value["policy_AZ"] = "policyA"
resource_value["policy_ZA"] = "policyB"
resource_value["ni_name"] = 'ELAN{:s}'.format(str(vlan_value))
config_rule["custom"]["resource_key"] = f"/device[{router_id}]/endpoint[{router_if}]/settings"
logging.info(f"L3VPN Intent realized\n")
self.answer[self.subnet]["VLAN"] = vlan_value
with open(os.path.join(TEMPLATES_PATH, "L3-VPN_template_example.json"), "w") as archivo:
archivo.write(json.dumps(tfs_request,indent=2))
def __ixia(self, ietf_intent):
"""
Prepare an Ixia service request based on the IETF intent.
This method configures an Ixia service request by:
1. Defining endpoint routers
2. Loading a service template
3. Generating a unique service UUID
4. Configuring service endpoints
5. Adding QoS constraints
Args:
ietf_intent (dict): IETF-formatted network slice intent.
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
Returns:
dict: An Ixia service request for configuration.
"""
self.answer[self.subnet]["QoS Requirements"] = []
# Add service constraints
for i, constraint in enumerate(ietf_intent["ietf-network-slice-service:network-slice-services"]["slo-sle-templates"]["slo-sle-template"][0]["slo-policy"]["metric-bound"]):
bound = ietf_intent["ietf-network-slice-service:network-slice-services"]["slo-sle-templates"]["slo-sle-template"][0]["slo-policy"]["metric-bound"][i]["bound"]
metric_type = ietf_intent["ietf-network-slice-service:network-slice-services"]["slo-sle-templates"]["slo-sle-template"][0]["slo-policy"]["metric-bound"][i]["metric-type"]
metric_unit = ietf_intent["ietf-network-slice-service:network-slice-services"]["slo-sle-templates"]["slo-sle-template"][0]["slo-policy"]["metric-bound"][i]["metric-unit"]
service_constraint ={
"custom": {
"constraint_type": f"{metric_type}[{metric_unit}]",
"constraint_value": f"{bound}"
}
}
self.answer[self.subnet]["QoS Requirements"].append(service_constraint["custom"])
self.answer[self.subnet]["VLAN"] = ietf_intent["ietf-network-slice-service:network-slice-services"]["slice-service"][0]["sdps"]["sdp"][0]["service-match-criteria"]["match-criterion"][0]["value"]
# Extraer la lista de métricas de forma segura
metric_bounds = ietf_intent.get("ietf-network-slice-service:network-slice-services", {}) \
.get("slo-sle-templates", {}) \
.get("slo-sle-template", [{}])[0] \
.get("slo-policy", {}) \
.get("metric-bound", [])
# Inicializar valores
bandwidth = None
latency = None
tolerance = None
# Asignar valores según el tipo de métrica
for metric in metric_bounds:
metric_type = metric.get("metric-type")
bound = metric.get("bound")
if metric_type == "one-way-bandwidth":
bandwidth = bound
elif metric_type == "one-way-delay-maximum":
latency = bound
elif metric_type == "one-way-delay-variation-maximum":
tolerance = bound
# Construcción del diccionario intent
intent = {
"src_node_ip": ietf_intent.get("ietf-network-slice-service:network-slice-services", {})
.get("slice-service", [{}])[0]
.get("sdps", {}).get("sdp", [{}])[0]
.get("attachment-circuits", {}).get("attachment-circuit", [{}])[0]
.get("sdp-peering", {}).get("peer-sap-id"),
"dst_node_ip": ietf_intent.get("ietf-network-slice-service:network-slice-services", {})
.get("slice-service", [{}])[0]
.get("sdps", {}).get("sdp", [{}, {}])[1]
.get("attachment-circuits", {}).get("attachment-circuit", [{}])[0]
.get("sdp-peering", {}).get("peer-sap-id"),
"vlan_id": ietf_intent.get("ietf-network-slice-service:network-slice-services", {})
.get("slice-service", [{}])[0]
.get("sdps", {}).get("sdp", [{}])[0]
.get("service-match-criteria", {}).get("match-criterion", [{}])[0]
.get("value"),
"bandwidth": bandwidth,
"latency": latency,
"tolerance": tolerance,
"latency_version": ietf_intent.get("ietf-network-slice-service:network-slice-services", {})
.get("slo-sle-templates", {}).get("slo-sle-template", [{}])[0]
.get("description"),
"reliability": ietf_intent.get("ietf-network-slice-service:network-slice-services", {})
.get("slo-sle-templates", {}).get("slo-sle-template", [{}])[0]
.get("sle-policy", {}).get("reliability"),
}
logging.info(f"IXIA Intent realized\n")
return intent