diff --git a/deploy/nats.sh b/deploy/nats.sh index cb3dd23183d0f3004e8ffb3c82b3cc91414bf704..b6df8066b2eb78263335a8a7831579e0e036b37a 100755 --- a/deploy/nats.sh +++ b/deploy/nats.sh @@ -69,8 +69,7 @@ function nats_deploy_single() { echo ">>> NATS is present; skipping step." else echo ">>> Deploy NATS" - helm3 install ${NATS_NAMESPACE} nats/nats --namespace ${NATS_NAMESPACE} --set nats.image=nats:2.9-alpine --set config.cluster.enabled=true --set config.cluster.tls.enabled=true - + helm3 install ${NATS_NAMESPACE} nats/nats --namespace ${NATS_NAMESPACE} --set nats.image=nats:2.9-alpine echo ">>> Waiting NATS statefulset to be created..." while ! kubectl get --namespace ${NATS_NAMESPACE} statefulset/${NATS_NAMESPACE} &> /dev/null; do diff --git a/deploy/tfs.sh b/deploy/tfs.sh index f396094080c8ec4a33b016b88bc0137a3a32e65c..a1429e443eaa70252ab2dd1f673ce46826b28744 100755 --- a/deploy/tfs.sh +++ b/deploy/tfs.sh @@ -153,7 +153,7 @@ kubectl create secret generic crdb-data --namespace ${TFS_K8S_NAMESPACE} --type= --from-literal=CRDB_SSLMODE=require printf "\n" -echo ">>> Create Secret with Apache Kakfa..." +echo ">>> Create Secret with Apache Kafka..." KFK_SERVER_PORT=$(kubectl --namespace ${KFK_NAMESPACE} get service kafka-service -o 'jsonpath={.spec.ports[0].port}') kubectl create secret generic kfk-kpi-data --namespace ${TFS_K8S_NAMESPACE} --type='Opaque' \ --from-literal=KFK_NAMESPACE=${KFK_NAMESPACE} \ diff --git a/hackfest5/.gitignore b/hackfest5/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..0ba4756f172b9aa58e2deebb9f62243d0b91e006 --- /dev/null +++ b/hackfest5/.gitignore @@ -0,0 +1,4 @@ +clab-*/ +*.clab.yml.bak +*.tar +*.tar.gz diff --git a/hackfest5/README.md b/hackfest5/README.md new file mode 100644 index 0000000000000000000000000000000000000000..1906a500583945142300256c55f70b06ec210a72 --- /dev/null +++ b/hackfest5/README.md @@ -0,0 +1,187 @@ +# Hackfest 5 - Control an Emulated DataPlane through TeraFlowSDN + + +## Prepare your VM +```bash +cd ~/tfs-ctrl +git checkout feat/hackfest5 +git pull +``` + + + +## ContainerLab Commands + +### Download and install ContainerLab +```bash +sudo bash -c "$(curl -sL https://get.containerlab.dev)" -- -v 0.59.0 +``` + +### Check available images in Docker +```bash +docker images | grep -E "ceos|multitool" +``` + +### Download hackfest5 cEOS image and create Docker image [already done] +- Note: Image to be downloaded for free from [Arista](https://www.arista.com/en/login) website. +```bash +docker import ~/tfs-ctrl/hackfest5/images/arista/cEOS64-lab-4.31.5M.tar ceos:4.31.5M +docker import ~/tfs-ctrl/hackfest5/images/arista/cEOS64-lab-4.32.2F.tar ceos:4.32.2F +``` + +### Deploy scenario +```bash +~/tfs-ctrl/hackfest5/clab-deploy.sh +``` + +### Inspect scenario +```bash +~/tfs-ctrl/hackfest5/clab-inspect.sh +``` + +### Show scenario's topology +```bash +~/tfs-ctrl/hackfest5/clab-graph.sh +``` + +### Destroy scenario +```bash +~/tfs-ctrl/hackfest5/clab-destroy.sh +``` + +### Access cEOS CLI +```bash +~/tfs-ctrl/hackfest5/clab-cli-r1.sh +``` + +### Access DC CLI +```bash +~/tfs-ctrl/hackfest5/clab-cli-dc1.sh +``` + +### Start pinging remote DC +```bash +~/tfs-ctrl/hackfest5/clab-cli-dc1.sh + ping 192.168.2.10 +``` + + + +## TeraFlowSDN Commands + +### Check status of MicroK8s +```bash +microk8s.status --wait-ready +``` + +### Start MicroK8s +```bash +microk8s.start +``` + +### Periodically report status of MicroK8s every second +```bash +watch -n 1 microk8s.status --wait-ready +``` + +### Periodically report status of workload in MicroK8s every second +```bash +watch -n 1 kubectl get all --all-namespaces +``` + +### Re-Deploy TeraFlowSDN +```bash +~/tfs-ctrl/hackfest5/redeploy-tfs.sh +``` + +### Show TeraFlowSDN Deployment status +```bash +source ~/tfs-ctrl/hackfest5/deploy_specs.sh +./deploy/show.sh +``` + +### Show log of a TeraFlowSDN component +```bash +source ~/tfs-ctrl/hackfest5/deploy_specs.sh +~/tfs-ctrl/scripts/show_logs_device.sh +``` + + + +## L3VPN Commands + +### Create a new IETF L3VPN through TeraFlowSDN NBI +```bash +cd ~/tfs-ctrl/hackfest5/data +curl -X POST \ + --header "Content-Type: application/json" \ + --data @ietf-l3vpn-service.json \ + --user "admin:admin" \ + http://127.0.0.1/restconf/data/ietf-l3vpn-svc:l3vpn-svc/vpn-services +``` + +### Get UUID of a IETF L3VPN through TeraFlowSDN NBI +```bash +curl --user "admin:admin" \ + http://127.0.0.1/restconf/data/ietf-l3vpn-svc:l3vpn-svc/vpn-services/vpn-service=ietf-l3vpn-svc/ +``` + +### Delete a IETF L3VPN through TeraFlowSDN NBI +```bash +curl -X DELETE --user "admin:admin" \ + http://127.0.0.1/restconf/data/ietf-l3vpn-svc:l3vpn-svc/vpn-services/vpn-service=ietf-l3vpn-svc/ +``` + +### Start pinging remote DC +```bash +~/tfs-ctrl/hackfest5/clab-cli-dc1.sh + ping 192.168.2.10 +``` + + + + +## gNMIc Commands + +### Install gNMIc +```bash +sudo bash -c "$(curl -sL https://get-gnmic.kmrd.dev)" +``` + +### gNMI Capabilities request +```bash +gnmic --address clab-hackfest5-r1 --port 6030 --username admin --password admin --insecure capabilities +``` + +### gNMI Get request +```bash +gnmic --address clab-hackfest5-r1 --port 6030 --username admin --password admin --insecure --encoding json_ietf get --path / > r1.json +gnmic --address clab-hackfest5-r1 --port 6030 --username admin --password admin --insecure --encoding json_ietf get --path /interfaces/interface > r1-ifaces.json +``` + +### gNMI Set request +```bash +gnmic --address clab-hackfest5-r1 --port 6030 --username admin --password admin --insecure --encoding json_ietf set --update-path /system/config/hostname --update-value "my-r1" +gnmic --address clab-hackfest5-r1 --port 6030 --username admin --password admin --insecure --encoding json_ietf get --path /system/config/hostname +``` + +### Subscribe request +```bash +gnmic --address clab-hackfest5-r1 --port 6030 --username admin --password admin --insecure --encoding json_ietf subscribe --path /interfaces/interface[name=Management0]/state/ + +# In another terminal, you can generate traffic opening SSH connection +ssh admin@clab-hackfest5-r1 +``` + +### Check configurations done: +```bash +gnmic --address clab-hackfest5-r1 --port 6030 --username admin --password admin --insecure --encoding json_ietf get --path '/network-instances' > r1-nis.json +gnmic --address clab-hackfest5-r1 --port 6030 --username admin --password admin --insecure --encoding json_ietf get --path '/interfaces' > r1-ifs.json +``` + +### Delete elements: +```bash +--address clab-hackfest5-r1 --port 6030 --username admin --password admin --insecure --encoding json_ietf set --delete '/network-instances/network-instance[name=b19229e8]' +--address clab-hackfest5-r1 --port 6030 --username admin --password admin --insecure --encoding json_ietf set --delete '/interfaces/interface[name=ethernet-1/1]/subinterfaces/subinterface[index=0]' +--address clab-hackfest5-r1 --port 6030 --username admin --password admin --insecure --encoding json_ietf set --delete '/interfaces/interface[name=ethernet-1/2]/subinterfaces/subinterface[index=0]' +``` diff --git a/hackfest5/clab-cli-dc1.sh b/hackfest5/clab-cli-dc1.sh new file mode 100755 index 0000000000000000000000000000000000000000..44631fa227462996b2b924e01d32f5d148610e4b --- /dev/null +++ b/hackfest5/clab-cli-dc1.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# Copyright 2022-2024 ETSI SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/) +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +docker exec -it clab-hackfest5-dc1 bash diff --git a/hackfest5/clab-cli-dc2.sh b/hackfest5/clab-cli-dc2.sh new file mode 100755 index 0000000000000000000000000000000000000000..56e1520142f3749069582bd519e1f425bacd3e4f --- /dev/null +++ b/hackfest5/clab-cli-dc2.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# Copyright 2022-2024 ETSI SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/) +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +docker exec -it clab-hackfest5-dc2 bash diff --git a/hackfest5/clab-cli-r1.sh b/hackfest5/clab-cli-r1.sh new file mode 100755 index 0000000000000000000000000000000000000000..f921809bfea80dffbc66b4a35fcbb7e786a90cdd --- /dev/null +++ b/hackfest5/clab-cli-r1.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# Copyright 2022-2024 ETSI SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/) +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +docker exec -it clab-hackfest5-r1 Cli diff --git a/hackfest5/clab-cli-r2.sh b/hackfest5/clab-cli-r2.sh new file mode 100755 index 0000000000000000000000000000000000000000..154179a636981ecd6d7831f7498873eca8d94274 --- /dev/null +++ b/hackfest5/clab-cli-r2.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# Copyright 2022-2024 ETSI SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/) +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +docker exec -it clab-hackfest5-r2 Cli diff --git a/hackfest5/clab-deploy.sh b/hackfest5/clab-deploy.sh new file mode 100755 index 0000000000000000000000000000000000000000..84b4d2c221f1f11cc46efd13818b37b5d0e492d3 --- /dev/null +++ b/hackfest5/clab-deploy.sh @@ -0,0 +1,17 @@ +#!/bin/bash +# Copyright 2022-2024 ETSI SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/) +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cd ~/tfs-ctrl/hackfest5 +sudo containerlab deploy --topo hackfest5.clab.yml diff --git a/hackfest5/clab-destroy.sh b/hackfest5/clab-destroy.sh new file mode 100755 index 0000000000000000000000000000000000000000..dc65a82e7cfd263fc25760b224403e0a31c68188 --- /dev/null +++ b/hackfest5/clab-destroy.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# Copyright 2022-2024 ETSI SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/) +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cd ~/tfs-ctrl/hackfest5 +sudo containerlab destroy --topo hackfest5.clab.yml +sudo rm -rf clab-hackfest5/ .hackfest5.clab.yml.bak diff --git a/hackfest5/clab-graph.sh b/hackfest5/clab-graph.sh new file mode 100755 index 0000000000000000000000000000000000000000..f0ad9693296970dbafab9abaa1f41af2c5ee5f4e --- /dev/null +++ b/hackfest5/clab-graph.sh @@ -0,0 +1,17 @@ +#!/bin/bash +# Copyright 2022-2024 ETSI SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/) +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cd ~/tfs-ctrl/hackfest5 +sudo containerlab graph --topo hackfest5.clab.yml diff --git a/hackfest5/clab-inspect.sh b/hackfest5/clab-inspect.sh new file mode 100755 index 0000000000000000000000000000000000000000..5e1fc7a623796c1c427abaae334352c38d98addb --- /dev/null +++ b/hackfest5/clab-inspect.sh @@ -0,0 +1,17 @@ +#!/bin/bash +# Copyright 2022-2024 ETSI SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/) +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cd ~/tfs-ctrl/hackfest5 +sudo containerlab inspect --topo hackfest5.clab.yml diff --git a/hackfest5/data/ietf-l3vpn-service.json b/hackfest5/data/ietf-l3vpn-service.json new file mode 100644 index 0000000000000000000000000000000000000000..9eb70db5465af56e9877eecf664da0aa7d1313ba --- /dev/null +++ b/hackfest5/data/ietf-l3vpn-service.json @@ -0,0 +1,83 @@ +{ + "ietf-l3vpn-svc:l3vpn-svc": { + "vpn-services": {"vpn-service": [{"vpn-id": "ietf-l3vpn-svc"}]}, + "sites": { + "site": [ + { + "site-id": "site_DC1", + "management": {"type": "ietf-l3vpn-svc:provider-managed"}, + "locations": {"location": [{"location-id": "DC1"}]}, + "devices": {"device": [{"device-id": "dc1", "location": "DC1"}]}, + "site-network-accesses": { + "site-network-access": [ + { + "site-network-access-id": "eth1", + "site-network-access-type": "ietf-l3vpn-svc:multipoint", + "device-reference": "dc1", + "vpn-attachment": {"vpn-id": "ietf-l3vpn-svc", "site-role": "ietf-l3vpn-svc:spoke-role"}, + "ip-connection": { + "ipv4": { + "address-allocation-type": "ietf-l3vpn-svc:static-address", + "addresses": { + "provider-address": "192.168.1.1", + "customer-address": "192.168.1.10", + "prefix-length": 24 + } + } + }, + "service": { + "svc-mtu": 1500, + "svc-input-bandwidth": 1000000000, + "svc-output-bandwidth": 1000000000, + "qos": {"qos-profile": {"classes": {"class": [{ + "class-id": "qos-realtime", + "direction": "ietf-l3vpn-svc:both", + "latency": {"latency-boundary": 10}, + "bandwidth": {"guaranteed-bw-percent": 100} + }]}}} + } + } + ] + } + }, + { + "site-id": "site_DC2", + "management": {"type": "ietf-l3vpn-svc:provider-managed"}, + "locations": {"location": [{"location-id": "DC2"}]}, + "devices": {"device": [{"device-id": "dc2", "location": "DC2"}]}, + "site-network-accesses": { + "site-network-access": [ + { + "site-network-access-id": "eth1", + "site-network-access-type": "ietf-l3vpn-svc:multipoint", + "device-reference": "dc2", + "vpn-attachment": {"vpn-id": "ietf-l3vpn-svc", "site-role": "ietf-l3vpn-svc:hub-role"}, + "ip-connection": { + "ipv4": { + "address-allocation-type": "ietf-l3vpn-svc:static-address", + "addresses": { + "provider-address": "192.168.2.1", + "customer-address": "192.168.2.10", + "prefix-length": 24 + } + } + }, + "service": { + "svc-mtu": 1500, + "svc-input-bandwidth": 1000000000, + "svc-output-bandwidth": 1000000000, + "qos": {"qos-profile": {"classes": {"class": [{ + "class-id": "qos-realtime", + "direction": "ietf-l3vpn-svc:both", + "latency": {"latency-boundary": 10}, + "bandwidth": {"guaranteed-bw-percent": 100} + }]}}} + } + } + ] + } + } + ] + } + } +} diff --git a/hackfest5/data/tfs-service.json b/hackfest5/data/tfs-service.json new file mode 100644 index 0000000000000000000000000000000000000000..397fc84789111932da047acd22c7bc787888657f --- /dev/null +++ b/hackfest5/data/tfs-service.json @@ -0,0 +1,26 @@ +{ + "services": [ + { + "service_id": { + "context_id": {"context_uuid": {"uuid": "admin"}}, "service_uuid": {"uuid": "tfs-l3vpn-svc"} + }, + "service_type": "SERVICETYPE_L3NM", + "service_status": {"service_status": "SERVICESTATUS_PLANNED"}, + "service_endpoint_ids": [ + {"device_id": {"device_uuid": {"uuid": "dc1"}}, "endpoint_uuid": {"uuid": "int"}}, + {"device_id": {"device_uuid": {"uuid": "dc2"}}, "endpoint_uuid": {"uuid": "int"}} + ], + "service_constraints": [], + "service_config": {"config_rules": [ + {"action": "CONFIGACTION_SET", "custom": { + "resource_key": "/device[dc1]/endpoint[eth1]/settings", + "resource_value": {"address_ip": "192.168.1.10", "address_prefix": 24, "index": 0} + }}, + {"action": "CONFIGACTION_SET", "custom": { + "resource_key": "/device[dc2]/endpoint[eth1]/settings", + "resource_value": {"address_ip": "192.168.2.10", "address_prefix": 24, "index": 0} + }} + ]} + } + ] +} diff --git a/hackfest5/data/tfs-topology.json b/hackfest5/data/tfs-topology.json new file mode 100644 index 0000000000000000000000000000000000000000..49df9de4244651d1eb08c24ca3fcbb53d41d2e34 --- /dev/null +++ b/hackfest5/data/tfs-topology.json @@ -0,0 +1,100 @@ +{ + "contexts": [ + {"context_id": {"context_uuid": {"uuid": "admin"}}} + ], + "topologies": [ + {"topology_id": {"context_id": {"context_uuid": {"uuid": "admin"}}, "topology_uuid": {"uuid": "admin"}}} + ], + "devices": [ + { + "device_id": {"device_uuid": {"uuid": "dc1"}}, "device_type": "emu-datacenter", + "device_drivers": ["DEVICEDRIVER_UNDEFINED"], + "device_config": {"config_rules": [ + {"action": "CONFIGACTION_SET", "custom": {"resource_key": "_connect/address", "resource_value": "127.0.0.1"}}, + {"action": "CONFIGACTION_SET", "custom": {"resource_key": "_connect/port", "resource_value": "0"}}, + {"action": "CONFIGACTION_SET", "custom": {"resource_key": "_connect/settings", "resource_value": {"endpoints": [ + {"uuid": "eth1", "type": "copper"}, {"uuid": "int", "type": "copper"} + ]}}} + ]} + }, + { + "device_id": {"device_uuid": {"uuid": "dc2"}}, "device_type": "emu-datacenter", + "device_drivers": ["DEVICEDRIVER_UNDEFINED"], + "device_config": {"config_rules": [ + {"action": "CONFIGACTION_SET", "custom": {"resource_key": "_connect/address", "resource_value": "127.0.0.1"}}, + {"action": "CONFIGACTION_SET", "custom": {"resource_key": "_connect/port", "resource_value": "0"}}, + {"action": "CONFIGACTION_SET", "custom": {"resource_key": "_connect/settings", "resource_value": {"endpoints": [ + {"uuid": "eth1", "type": "copper"}, {"uuid": "int", "type": "copper"} + ]}}} + ]} + }, + { + "device_id": {"device_uuid": {"uuid": "r1"}}, "device_type": "packet-router", + "device_drivers": ["DEVICEDRIVER_GNMI_OPENCONFIG"], + "device_config": {"config_rules": [ + {"action": "CONFIGACTION_SET", "custom": {"resource_key": "_connect/address", "resource_value": "172.20.20.101"}}, + {"action": "CONFIGACTION_SET", "custom": {"resource_key": "_connect/port", "resource_value": "6030"}}, + {"action": "CONFIGACTION_SET", "custom": {"resource_key": "_connect/settings", "resource_value": { + "username": "admin", "password": "admin", "use_tls": false + }}} + ]} + }, + { + "device_id": {"device_uuid": {"uuid": "r2"}}, "device_type": "packet-router", + "device_drivers": ["DEVICEDRIVER_GNMI_OPENCONFIG"], + "device_config": {"config_rules": [ + {"action": "CONFIGACTION_SET", "custom": {"resource_key": "_connect/address", "resource_value": "172.20.20.102"}}, + {"action": "CONFIGACTION_SET", "custom": {"resource_key": "_connect/port", "resource_value": "6030"}}, + {"action": "CONFIGACTION_SET", "custom": {"resource_key": "_connect/settings", "resource_value": { + "username": "admin", "password": "admin", "use_tls": false + }}} + ]} + } + ], + "links": [ + { + "link_id": {"link_uuid": {"uuid": "r1/Ethernet2==r2/Ethernet1"}}, + "link_endpoint_ids": [ + {"device_id": {"device_uuid": {"uuid": "r1"}}, "endpoint_uuid": {"uuid": "Ethernet2"}}, + {"device_id": {"device_uuid": {"uuid": "r2"}}, "endpoint_uuid": {"uuid": "Ethernet1"}} + ] + }, + { + "link_id": {"link_uuid": {"uuid": "r2/Ethernet1==r1/Ethernet2"}}, + "link_endpoint_ids": [ + {"device_id": {"device_uuid": {"uuid": "r2"}}, "endpoint_uuid": {"uuid": "Ethernet1"}}, + {"device_id": {"device_uuid": {"uuid": "r1"}}, "endpoint_uuid": {"uuid": "Ethernet2"}} + ] + }, + + { + "link_id": {"link_uuid": {"uuid": "r1/Ethernet10==dc1/eth1"}}, + "link_endpoint_ids": [ + {"device_id": {"device_uuid": {"uuid": "r1"}}, "endpoint_uuid": {"uuid": "Ethernet10"}}, + {"device_id": {"device_uuid": {"uuid": "dc1"}}, "endpoint_uuid": {"uuid": "eth1"}} + ] + }, + { + "link_id": {"link_uuid": {"uuid": "dc1/eth1==r1/Ethernet10"}}, + "link_endpoint_ids": [ + {"device_id": {"device_uuid": {"uuid": "dc1"}}, "endpoint_uuid": {"uuid": "eth1"}}, + {"device_id": {"device_uuid": {"uuid": "r1"}}, "endpoint_uuid": {"uuid": "Ethernet10"}} + ] + }, + + { + "link_id": {"link_uuid": {"uuid": "r2/Ethernet10==dc2/eth1"}}, + "link_endpoint_ids": [ + {"device_id": {"device_uuid": {"uuid": "r2"}}, "endpoint_uuid": {"uuid": "Ethernet10"}}, + {"device_id": {"device_uuid": {"uuid": "dc2"}}, "endpoint_uuid": {"uuid": "eth1"}} + ] + }, + { + "link_id": {"link_uuid": {"uuid": "dc2/eth1==r2/Ethernet10"}}, + "link_endpoint_ids": [ + {"device_id": {"device_uuid": {"uuid": "dc2"}}, "endpoint_uuid": {"uuid": "eth1"}}, + {"device_id": {"device_uuid": {"uuid": "r2"}}, "endpoint_uuid": {"uuid": "Ethernet10"}} + ] + } + ] +} diff --git a/hackfest5/deploy_specs.sh b/hackfest5/deploy_specs.sh new file mode 100755 index 0000000000000000000000000000000000000000..e9565218a725fbd416ac9fd2e7a9ca432ef20a96 --- /dev/null +++ b/hackfest5/deploy_specs.sh @@ -0,0 +1,208 @@ +#!/bin/bash +# Copyright 2022-2024 ETSI SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/) +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +# ----- TeraFlowSDN ------------------------------------------------------------ + +# Set the URL of the internal MicroK8s Docker registry where the images will be uploaded to. +export TFS_REGISTRY_IMAGES="http://localhost:32000/tfs/" + +# Set the list of components, separated by spaces, you want to build images for, and deploy. +#export TFS_COMPONENTS="context device pathcomp service slice nbi webui load_generator" +export TFS_COMPONENTS="context device pathcomp service nbi webui" + +# Uncomment to activate Monitoring (old) +export TFS_COMPONENTS="${TFS_COMPONENTS} monitoring" + +# Uncomment to activate Monitoring Framework (new) +#export TFS_COMPONENTS="${TFS_COMPONENTS} kpi_manager kpi_value_writer kpi_value_api telemetry analytics automation" + +# Uncomment to activate QoS Profiles +#export TFS_COMPONENTS="${TFS_COMPONENTS} qos_profile" + +# Uncomment to activate BGP-LS Speaker +#export TFS_COMPONENTS="${TFS_COMPONENTS} bgpls_speaker" + +# Uncomment to activate Optical Controller +# To manage optical connections, "service" requires "opticalcontroller" to be deployed +# before "service", thus we "hack" the TFS_COMPONENTS environment variable prepending the +# "opticalcontroller" only if "service" is already in TFS_COMPONENTS, and re-export it. +#if [[ "$TFS_COMPONENTS" == *"service"* ]]; then +# BEFORE="${TFS_COMPONENTS% service*}" +# AFTER="${TFS_COMPONENTS#* service}" +# export TFS_COMPONENTS="${BEFORE} opticalcontroller service ${AFTER}" +#fi + +# Uncomment to activate ZTP +#export TFS_COMPONENTS="${TFS_COMPONENTS} ztp" + +# Uncomment to activate Policy Manager +#export TFS_COMPONENTS="${TFS_COMPONENTS} policy" + +# Uncomment to activate Optical CyberSecurity +#export TFS_COMPONENTS="${TFS_COMPONENTS} dbscanserving opticalattackmitigator opticalattackdetector opticalattackmanager" + +# Uncomment to activate L3 CyberSecurity +#export TFS_COMPONENTS="${TFS_COMPONENTS} l3_attackmitigator l3_centralizedattackdetector" + +# Uncomment to activate TE +#export TFS_COMPONENTS="${TFS_COMPONENTS} te" + +# Uncomment to activate Forecaster +#export TFS_COMPONENTS="${TFS_COMPONENTS} forecaster" + +# Uncomment to activate E2E Orchestrator +#export TFS_COMPONENTS="${TFS_COMPONENTS} e2e_orchestrator" + +# Uncomment to activate DLT and Interdomain +#export TFS_COMPONENTS="${TFS_COMPONENTS} interdomain dlt" +#if [[ "$TFS_COMPONENTS" == *"dlt"* ]]; then +# export KEY_DIRECTORY_PATH="src/dlt/gateway/keys/priv_sk" +# export CERT_DIRECTORY_PATH="src/dlt/gateway/keys/cert.pem" +# export TLS_CERT_PATH="src/dlt/gateway/keys/ca.crt" +#fi + +# Uncomment to activate QKD App +# To manage QKD Apps, "service" requires "qkd_app" to be deployed +# before "service", thus we "hack" the TFS_COMPONENTS environment variable prepending the +# "qkd_app" only if "service" is already in TFS_COMPONENTS, and re-export it. +#if [[ "$TFS_COMPONENTS" == *"service"* ]]; then +# BEFORE="${TFS_COMPONENTS% service*}" +# AFTER="${TFS_COMPONENTS#* service}" +# export TFS_COMPONENTS="${BEFORE} qkd_app service ${AFTER}" +#fi + + +# Set the tag you want to use for your images. +export TFS_IMAGE_TAG="dev" + +# Set the name of the Kubernetes namespace to deploy TFS to. +export TFS_K8S_NAMESPACE="tfs" + +# Set additional manifest files to be applied after the deployment +export TFS_EXTRA_MANIFESTS="manifests/nginx_ingress_http.yaml" + +# Uncomment to monitor performance of components +#export TFS_EXTRA_MANIFESTS="${TFS_EXTRA_MANIFESTS} manifests/servicemonitors.yaml" + +# Uncomment when deploying Optical CyberSecurity +#export TFS_EXTRA_MANIFESTS="${TFS_EXTRA_MANIFESTS} manifests/cachingservice.yaml" + +# Set the new Grafana admin password +export TFS_GRAFANA_PASSWORD="admin123+" + +# Disable skip-build flag to rebuild the Docker images. +export TFS_SKIP_BUILD="" + + +# ----- CockroachDB ------------------------------------------------------------ + +# Set the namespace where CockroackDB will be deployed. +export CRDB_NAMESPACE="crdb" + +# Set the external port CockroackDB Postgre SQL interface will be exposed to. +export CRDB_EXT_PORT_SQL="26257" + +# Set the external port CockroackDB HTTP Mgmt GUI interface will be exposed to. +export CRDB_EXT_PORT_HTTP="8081" + +# Set the database username to be used by Context. +export CRDB_USERNAME="tfs" + +# Set the database user's password to be used by Context. +export CRDB_PASSWORD="tfs123" + +# Set CockroachDB installation mode to 'single'. This option is convenient for development and testing. +# See ./deploy/all.sh or ./deploy/crdb.sh for additional details +export CRDB_DEPLOY_MODE="single" + +# Disable flag for dropping database, if it exists. +export CRDB_DROP_DATABASE_IF_EXISTS="YES" + +# Disable flag for re-deploying CockroachDB from scratch. +export CRDB_REDEPLOY="" + + +# ----- NATS ------------------------------------------------------------------- + +# Set the namespace where NATS will be deployed. +export NATS_NAMESPACE="nats" + +# Set the external port NATS Client interface will be exposed to. +export NATS_EXT_PORT_CLIENT="4222" + +# Set the external port NATS HTTP Mgmt GUI interface will be exposed to. +export NATS_EXT_PORT_HTTP="8222" + +# Set NATS installation mode to 'single'. This option is convenient for development and testing. +# See ./deploy/all.sh or ./deploy/nats.sh for additional details +export NATS_DEPLOY_MODE="single" + +# Disable flag for re-deploying NATS from scratch. +export NATS_REDEPLOY="" + + +# ----- QuestDB ---------------------------------------------------------------- + +# Set the namespace where QuestDB will be deployed. +export QDB_NAMESPACE="qdb" + +# Set the external port QuestDB Postgre SQL interface will be exposed to. +export QDB_EXT_PORT_SQL="8812" + +# Set the external port QuestDB Influx Line Protocol interface will be exposed to. +export QDB_EXT_PORT_ILP="9009" + +# Set the external port QuestDB HTTP Mgmt GUI interface will be exposed to. +export QDB_EXT_PORT_HTTP="9000" + +# Set the database username to be used for QuestDB. +export QDB_USERNAME="admin" + +# Set the database user's password to be used for QuestDB. +export QDB_PASSWORD="quest" + +# Set the table name to be used by Monitoring for KPIs. +export QDB_TABLE_MONITORING_KPIS="tfs_monitoring_kpis" + +# Set the table name to be used by Slice for plotting groups. +export QDB_TABLE_SLICE_GROUPS="tfs_slice_groups" + +# Disable flag for dropping tables if they exist. +export QDB_DROP_TABLES_IF_EXIST="YES" + +# Disable flag for re-deploying QuestDB from scratch. +export QDB_REDEPLOY="" + + +# ----- K8s Observability ------------------------------------------------------ + +# Set the external port Prometheus Mgmt HTTP GUI interface will be exposed to. +export PROM_EXT_PORT_HTTP="9090" + +# Set the external port Grafana HTTP Dashboards will be exposed to. +export GRAF_EXT_PORT_HTTP="3000" + + +# ----- Apache Kafka ----------------------------------------------------------- + +# Set the namespace where Apache Kafka will be deployed. +#export KFK_NAMESPACE="kafka" + +# Set the port Apache Kafka server will be exposed to. +#export KFK_SERVER_PORT="9092" + +# Set the flag to YES for redeploying of Apache Kafka +#export KFK_REDEPLOY="" diff --git a/hackfest5/hackfest5.clab.yml b/hackfest5/hackfest5.clab.yml new file mode 100644 index 0000000000000000000000000000000000000000..acc58e9d01c245108e85ca786427eeac5442203f --- /dev/null +++ b/hackfest5/hackfest5.clab.yml @@ -0,0 +1,67 @@ +# Copyright 2022-2024 ETSI SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/) +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# TFS - Arista devices + Linux clients + +name: hackfest5 + +mgmt: + network: mgmt-net + ipv4-subnet: 172.20.20.0/24 + +topology: + kinds: + arista_ceos: + kind: arista_ceos + #image: ceos:4.30.4M + #image: ceos:4.31.2F + image: ceos:4.31.5M + #image: ceos:4.32.0F + #image: ceos:4.32.2F + #image: ceos:4.32.2.1F + linux: + kind: linux + image: ghcr.io/hellt/network-multitool:latest + + nodes: + r1: + kind: arista_ceos + mgmt-ipv4: 172.20.20.101 + startup-config: r1-startup.cfg + + r2: + kind: arista_ceos + mgmt-ipv4: 172.20.20.102 + startup-config: r2-startup.cfg + + dc1: + kind: linux + mgmt-ipv4: 172.20.20.201 + exec: + - ip link set address 00:c1:ab:00:01:01 dev eth1 + - ip address add 192.168.1.10/24 dev eth1 + - ip route add 192.168.2.0/24 via 192.168.1.1 + + dc2: + kind: linux + mgmt-ipv4: 172.20.20.202 + exec: + - ip link set address 00:c1:ab:00:02:01 dev eth1 + - ip address add 192.168.2.10/24 dev eth1 + - ip route add 192.168.1.0/24 via 192.168.2.1 + + links: + - endpoints: ["r1:eth2", "r2:eth1"] + - endpoints: ["r1:eth10", "dc1:eth1"] + - endpoints: ["r2:eth10", "dc2:eth1"] diff --git a/hackfest5/images/arista/.gitignore b/hackfest5/images/arista/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..284b64ce5902e2c74c656fb0c7256bc11a59575d --- /dev/null +++ b/hackfest5/images/arista/.gitignore @@ -0,0 +1,3 @@ +!.gitkeep +*.tar +*.tar.gz diff --git a/hackfest5/images/arista/.gitkeep b/hackfest5/images/arista/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/hackfest5/r1-startup.cfg b/hackfest5/r1-startup.cfg new file mode 100644 index 0000000000000000000000000000000000000000..2d1964f5f6505411674890acafeb05e574f49aa5 --- /dev/null +++ b/hackfest5/r1-startup.cfg @@ -0,0 +1,39 @@ +! device: r1 (cEOSLab, EOS-4.31.2F-35442176.4312F (engineering build)) +! +no aaa root +! +username admin privilege 15 role network-admin secret sha512 $6$tUMBMqI5iPca5XcJ$5QU/R83S.zjpHQyeB3H63BGWOgxewjqZ1NsxdaWPo3gLwRXVTrgYvMmwwZlzjYoqrD7yp7e9YD073/.FKLYEY1 +! +transceiver qsfp default-mode 4x10G +! +service routing protocols model multi-agent +! +hostname r1 +! +spanning-tree mode mstp +! +system l1 + unsupported speed action error + unsupported error-correction action error +! +management api http-commands + no shutdown +! +management api gnmi + transport grpc default +! +management api netconf + transport ssh default +! +interface Ethernet2 +! +interface Ethernet10 +! +interface Management0 + ip address 172.20.20.101/24 +! +ip routing +! +ip route 0.0.0.0/0 172.20.20.1 +! +end diff --git a/hackfest5/r2-startup.cfg b/hackfest5/r2-startup.cfg new file mode 100644 index 0000000000000000000000000000000000000000..7acd56bf64ebc45a437b438f1b13c4aa4182b794 --- /dev/null +++ b/hackfest5/r2-startup.cfg @@ -0,0 +1,39 @@ +! device: r2 (cEOSLab, EOS-4.31.2F-35442176.4312F (engineering build)) +! +no aaa root +! +username admin privilege 15 role network-admin secret sha512 $6$Z/om4jI3S5BmwxfB$igaSOaJnh3m36TbSMHKCusA77m07CU8JJxalupXIUFuy7HaGt6k.C1kfSJsPqjn1AhLaL.LvLkt/hcqTFgpjG. +! +transceiver qsfp default-mode 4x10G +! +service routing protocols model multi-agent +! +hostname r2 +! +spanning-tree mode mstp +! +system l1 + unsupported speed action error + unsupported error-correction action error +! +management api http-commands + no shutdown +! +management api gnmi + transport grpc default +! +management api netconf + transport ssh default +! +interface Ethernet1 +! +interface Ethernet10 +! +interface Management0 + ip address 172.20.20.102/24 +! +ip routing +! +ip route 0.0.0.0/0 172.20.20.1 +! +end diff --git a/hackfest5/redeploy-tfs.sh b/hackfest5/redeploy-tfs.sh new file mode 100755 index 0000000000000000000000000000000000000000..ff55bed3f55e355293e842b2f92c5547715cb247 --- /dev/null +++ b/hackfest5/redeploy-tfs.sh @@ -0,0 +1,52 @@ +#!/bin/bash +# Copyright 2022-2024 ETSI SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/) +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +source ~/tfs-ctrl/hackfest5/deploy_specs.sh + +echo "Cleaning-up old NATS and Kafka deployments..." +helm3 uninstall --namespace ${NATS_NAMESPACE} ${NATS_NAMESPACE} +kubectl delete namespace ${NATS_NAMESPACE} --ignore-not-found +kubectl delete namespace kafka --ignore-not-found +printf "\n" + +echo "Deployting TeraFlowSDN..." + +# Deploy CockroachDB +./deploy/crdb.sh + +# Deploy NATS +./deploy/nats.sh + +# Deploy QuestDB +./deploy/qdb.sh + +# Expose Dashboard +./deploy/expose_dashboard.sh + +# Deploy TeraFlowSDN +./deploy/tfs.sh + +# Show deploy summary +./deploy/show.sh + +printf "\n" + +echo "Waiting for Context to be subscribed to NATS..." +while ! kubectl --namespace $TFS_K8S_NAMESPACE logs deployment/contextservice -c server 2>&1 | grep -q 'Subscriber is Ready? True'; do + printf "%c" "." + sleep 1 +done +kubectl --namespace $TFS_K8S_NAMESPACE logs deployment/contextservice -c server +printf "\n" diff --git a/src/device/service/drivers/gnmi_openconfig/handlers/Interface.py b/src/device/service/drivers/gnmi_openconfig/handlers/Interface.py index fda3ab71be3b2c82020e93f92cf159da38e5eef4..a52c84691c00b0c09336e2400dbeb94a9ca310ed 100644 --- a/src/device/service/drivers/gnmi_openconfig/handlers/Interface.py +++ b/src/device/service/drivers/gnmi_openconfig/handlers/Interface.py @@ -69,7 +69,6 @@ class InterfaceHandler(_Handler): yang_ipv4_addr : libyang.DContainer = yang_ipv4_addrs.create_path(yang_ipv4_addr_path) yang_ipv4_addr.create_path('config/ip', address_ip) yang_ipv4_addr.create_path('config/prefix-length', address_prefix) - if mtu is not None: yang_ipv4_addr.create_path('config/mtu', mtu) str_path = '/interfaces/interface[name={:s}]'.format(if_name) str_data = yang_if.print_mem('json') diff --git a/src/service/service/service_handlers/l3nm_gnmi_openconfig/ConfigRuleComposer.py b/src/service/service/service_handlers/l3nm_gnmi_openconfig/ConfigRuleComposer.py index c8227975f3633ede1ee48cb1175e439615cb0543..277d6d7e1a574afafa138d517cfec4c644e25023 100644 --- a/src/service/service/service_handlers/l3nm_gnmi_openconfig/ConfigRuleComposer.py +++ b/src/service/service/service_handlers/l3nm_gnmi_openconfig/ConfigRuleComposer.py @@ -21,7 +21,9 @@ from service.service.service_handler_api.AnyTreeTools import TreeNode LOGGER = logging.getLogger(__name__) -NETWORK_INSTANCE = 'teraflowsdn' +#NETWORK_INSTANCE = 'teraflowsdn' # TODO: investigate; sometimes it does not create/delete static rules properly +NETWORK_INSTANCE = 'default' +DEFAULT_NETWORK_INSTANCE = 'default' RE_IF = re.compile(r'^\/interface\[([^\]]+)\]$') RE_SUBIF = re.compile(r'^\/interface\[([^\]]+)\]\/subinterface\[([^\]]+)\]$') @@ -108,12 +110,21 @@ class EndpointComposer: if self.ipv4_address is None: return [] if self.ipv4_prefix_len is None: return [] json_config_rule = json_config_rule_delete if delete else json_config_rule_set - config_rules = [ - json_config_rule(*_network_instance_interface( + + config_rules : List[Dict] = list() + if network_instance_name != DEFAULT_NETWORK_INSTANCE: + config_rules.append(json_config_rule(*_network_instance_interface( network_instance_name, self.objekt.name, self.sub_interface_index - )), - ] - if not delete: + ))) + + if delete: + config_rules.extend([ + json_config_rule(*_interface( + self.objekt.name, index=self.sub_interface_index, address_ip=None, + address_prefix=None, enabled=False + )), + ]) + else: config_rules.extend([ json_config_rule(*_interface( self.objekt.name, index=self.sub_interface_index, address_ip=self.ipv4_address, @@ -128,6 +139,12 @@ class EndpointComposer: 'address_ip' : self.ipv4_address, 'address_prefix': self.ipv4_prefix_len, } + + def __str__(self): + data = {'uuid': self.uuid} + if self.objekt is not None: data['name'] = self.objekt.name + data.update(self.dump()) + return json.dumps(data) class DeviceComposer: def __init__(self, device_uuid : str) -> None: @@ -187,7 +204,8 @@ class DeviceComposer: endpoint.ipv4_prefix_len = ipv4_prefix_len endpoint.sub_interface_index = int(subif_index) endpoint_ip_network = netaddr.IPNetwork('{:s}/{:d}'.format(ipv4_network, ipv4_prefix_len)) - self.connected.add(str(endpoint_ip_network.cidr)) + if '0.0.0.0/' not in str(endpoint_ip_network.cidr): + self.connected.add(str(endpoint_ip_network.cidr)) match = RE_SR.match(config_rule_custom.resource_key) if match is not None: @@ -211,9 +229,9 @@ class DeviceComposer: if self.objekt.device_type not in SELECTED_DEVICES: return [] json_config_rule = json_config_rule_delete if delete else json_config_rule_set - config_rules = [ + config_rules : List[Dict] = list() + if network_instance_name != DEFAULT_NETWORK_INSTANCE: json_config_rule(*_network_instance(network_instance_name, 'L3VRF')) - ] for endpoint in self.endpoints.values(): config_rules.extend(endpoint.get_config_rules(network_instance_name, delete=delete)) if len(self.static_routes) > 0: @@ -240,6 +258,12 @@ class DeviceComposer: 'static_routes' : self.static_routes, } + def __str__(self): + data = {'uuid': self.uuid} + if self.objekt is not None: data['name'] = self.objekt.name + data.update(self.dump()) + return json.dumps(data) + class ConfigRuleComposer: def __init__(self) -> None: self.objekt : Optional[Service] = None diff --git a/src/service/service/service_handlers/l3nm_gnmi_openconfig/L3NMGnmiOpenConfigServiceHandler.py b/src/service/service/service_handlers/l3nm_gnmi_openconfig/L3NMGnmiOpenConfigServiceHandler.py index 8aa3781a4c3c0d238d38491fb31d8dfdf9102368..4099675fa57df11b11302c210113189f0153b599 100644 --- a/src/service/service/service_handlers/l3nm_gnmi_openconfig/L3NMGnmiOpenConfigServiceHandler.py +++ b/src/service/service/service_handlers/l3nm_gnmi_openconfig/L3NMGnmiOpenConfigServiceHandler.py @@ -65,8 +65,9 @@ class L3NMGnmiOpenConfigServiceHandler(_ServiceHandler): self.__endpoint_map[(device_uuid, endpoint_uuid)] = (device_obj.name, endpoint_obj.name) + LOGGER.debug('[pre] config_rule_composer = {:s}'.format(json.dumps(self.__config_rule_composer.dump()))) self.__static_route_generator.compose(endpoints) - LOGGER.debug('config_rule_composer = {:s}'.format(json.dumps(self.__config_rule_composer.dump()))) + LOGGER.debug('[post] config_rule_composer = {:s}'.format(json.dumps(self.__config_rule_composer.dump()))) def _do_configurations( self, config_rules_per_device : Dict[str, List[Dict]], endpoints : List[Tuple[str, str, Optional[str]]], @@ -110,8 +111,8 @@ class L3NMGnmiOpenConfigServiceHandler(_ServiceHandler): #network_instance_name = service_uuid.split('-')[0] #config_rules_per_device = self.__config_rule_composer.get_config_rules(network_instance_name, delete=False) config_rules_per_device = self.__config_rule_composer.get_config_rules(delete=False) - LOGGER.debug('config_rules_per_device={:s}'.format(str(config_rules_per_device))) - results = self._do_configurations(config_rules_per_device, endpoints) + LOGGER.debug('config_rules_per_device={:s}'.format(json.dumps(config_rules_per_device))) + results = self._do_configurations(config_rules_per_device, endpoints, delete=False) LOGGER.debug('results={:s}'.format(str(results))) return results @@ -128,7 +129,7 @@ class L3NMGnmiOpenConfigServiceHandler(_ServiceHandler): #network_instance_name = service_uuid.split('-')[0] #config_rules_per_device = self.__config_rule_composer.get_config_rules(network_instance_name, delete=True) config_rules_per_device = self.__config_rule_composer.get_config_rules(delete=True) - LOGGER.debug('config_rules_per_device={:s}'.format(str(config_rules_per_device))) + LOGGER.debug('config_rules_per_device={:s}'.format(json.dumps(config_rules_per_device))) results = self._do_configurations(config_rules_per_device, endpoints, delete=True) LOGGER.debug('results={:s}'.format(str(results))) return results diff --git a/src/service/service/service_handlers/l3nm_gnmi_openconfig/StaticRouteGenerator.py b/src/service/service/service_handlers/l3nm_gnmi_openconfig/StaticRouteGenerator.py index 201f22e637556eee9e5e78c83db23b5e3d56c85f..b315c7f4d44c7f806a68b8466c393c1668d1d3bb 100644 --- a/src/service/service/service_handlers/l3nm_gnmi_openconfig/StaticRouteGenerator.py +++ b/src/service/service/service_handlers/l3nm_gnmi_openconfig/StaticRouteGenerator.py @@ -63,12 +63,20 @@ class StaticRouteGenerator: def _compute_link_endpoints( self, connection_hop_list : List[Tuple[str, str, Optional[str]]] ) -> List[Tuple[Tuple[str, str, Optional[str]], Tuple[str, str, Optional[str]]]]: + # In some cases connection_hop_list might contain repeated endpoints, remove them here. + added_connection_hops = set() + filtered_connection_hop_list = list() + for connection_hop in connection_hop_list: + if connection_hop in added_connection_hops: continue + filtered_connection_hop_list.append(connection_hop) + added_connection_hops.add(connection_hop) + connection_hop_list = filtered_connection_hop_list + num_connection_hops = len(connection_hop_list) if num_connection_hops % 2 != 0: raise Exception('Number of connection hops must be even') if num_connection_hops < 4: raise Exception('Number of connection hops must be >= 4') - # Skip service endpoints (first and last) - it_connection_hops = iter(connection_hop_list[1:-1]) + it_connection_hops = iter(connection_hop_list) return list(zip(it_connection_hops, it_connection_hops)) def _compute_link_addresses( @@ -130,6 +138,7 @@ class StaticRouteGenerator: if endpoint.ipv4_address is None: continue ip_network = _compose_ipv4_network(endpoint.ipv4_address, endpoint.ipv4_prefix_len) + if '0.0.0.0/' in str(ip_network.cidr): continue device.connected.add(str(ip_network.cidr)) def _compute_static_routes( diff --git a/src/service/tests/test_l3nm_gnmi_static_rule_gen/MockServiceHandler.py b/src/service/tests/test_l3nm_gnmi_static_rule_gen/MockServiceHandler.py index 22da218ab53c4a9d08c07dbf2553b9d8bbf407a8..a480f6b31884610782b15340ff1c40b6209b062d 100644 --- a/src/service/tests/test_l3nm_gnmi_static_rule_gen/MockServiceHandler.py +++ b/src/service/tests/test_l3nm_gnmi_static_rule_gen/MockServiceHandler.py @@ -19,6 +19,7 @@ from common.tools.object_factory.Connection import json_connection_id from common.tools.object_factory.Device import json_device_id from common.type_checkers.Checkers import chk_type from service.service.service_handler_api._ServiceHandler import _ServiceHandler +#from service.service.service_handler_api.AnyTreeTools import TreeNode from service.service.service_handler_api.SettingsHandler import SettingsHandler from service.service.service_handler_api.Tools import get_device_endpoint_uuids, get_endpoint_matching from .MockTaskExecutor import MockTaskExecutor @@ -45,6 +46,10 @@ class MockServiceHandler(_ServiceHandler): service_settings = self.__settings_handler.get_service_settings() self.__config_rule_composer.configure(self.__service, service_settings) + #prev_endpoint_obj = None + #prev_endpoint = None + #settings_for_next = None + #for i,endpoint in enumerate(endpoints): for endpoint in endpoints: device_uuid, endpoint_uuid = get_device_endpoint_uuids(endpoint) @@ -60,8 +65,35 @@ class MockServiceHandler(_ServiceHandler): _endpoint = _device.get_endpoint(endpoint_obj.name) _endpoint.configure(endpoint_obj, endpoint_settings) + #if settings_for_next is not None: + # _endpoint.configure(endpoint_obj, settings_for_next) + # settings_for_next = None + + #if endpoint_settings is not None and 'neighbor_address' in endpoint_settings.value: + # _neighbor_settings = {'address_ip': endpoint_settings.value['neighbor_address']} + # + # if 'address_prefix' in endpoint_settings.value: + # _neighbor_settings['address_prefix'] = endpoint_settings.value['address_prefix'] + # elif 'prefix_length' in endpoint_settings.value: + # _neighbor_settings['address_prefix'] = endpoint_settings.value['prefix_length'] + # else: + # MSG = 'IP Address Prefix not found. Tried: address_prefix and prefix_length. endpoint_settings.value={:s}' + # raise Exception(MSG.format(str(endpoint_settings.value))) + # + # neighbor_settings = TreeNode('.') + # neighbor_settings.value = _neighbor_settings + # if i % 2 == 0: + # # configure in next endpoint + # settings_for_next = neighbor_settings + # else: + # # configure in previous endpoint + # prev_endpoint.configure(prev_endpoint_obj, neighbor_settings) + self.__endpoint_map[(device_uuid, endpoint_uuid)] = (device_obj.name, endpoint_obj.name) + #prev_endpoint = _endpoint + #prev_endpoint_obj = endpoint_obj + self.__static_route_generator.compose(endpoints) LOGGER.debug('config_rule_composer = {:s}'.format(json.dumps(self.__config_rule_composer.dump()))) @@ -106,7 +138,7 @@ class MockServiceHandler(_ServiceHandler): #network_instance_name = service_uuid.split('-')[0] #config_rules_per_device = self.__config_rule_composer.get_config_rules(network_instance_name, delete=False) config_rules_per_device = self.__config_rule_composer.get_config_rules(delete=False) - LOGGER.debug('config_rules_per_device={:s}'.format(str(config_rules_per_device))) + LOGGER.debug('config_rules_per_device={:s}'.format(json.dumps(config_rules_per_device))) results = self._do_configurations(config_rules_per_device, endpoints) LOGGER.debug('results={:s}'.format(str(results))) return results @@ -123,7 +155,7 @@ class MockServiceHandler(_ServiceHandler): #network_instance_name = service_uuid.split('-')[0] #config_rules_per_device = self.__config_rule_composer.get_config_rules(network_instance_name, delete=True) config_rules_per_device = self.__config_rule_composer.get_config_rules(delete=True) - LOGGER.debug('config_rules_per_device={:s}'.format(str(config_rules_per_device))) + LOGGER.debug('config_rules_per_device={:s}'.format(json.dumps(config_rules_per_device))) results = self._do_configurations(config_rules_per_device, endpoints, delete=True) LOGGER.debug('results={:s}'.format(str(results))) return results diff --git a/src/service/tests/test_l3nm_gnmi_static_rule_gen/test_unitary_sns4sns.py b/src/service/tests/test_l3nm_gnmi_static_rule_gen/test_unitary_sns4sns.py index 0177500e2a3963fb00b3aabc27b2aa0bcaa0f12d..64035f1bbf4bb80bb5192488bffcbb4962458617 100644 --- a/src/service/tests/test_l3nm_gnmi_static_rule_gen/test_unitary_sns4sns.py +++ b/src/service/tests/test_l3nm_gnmi_static_rule_gen/test_unitary_sns4sns.py @@ -37,27 +37,23 @@ SERVICE = Service(**json_service_l3nm_planned( json_endpoint_id(json_device_id('edge-net'), 'eth1'), ], config_rules=[ + json_config_rule_set('/settings', {'address_families': ['IPV4'], 'mtu': 1500}), + json_config_rule_set('/static_routing', {}), + json_config_rule_set('/device[core-net]/endpoint[eth1]/settings', { - 'address_ip': '10.10.10.0', 'address_prefix': 24, 'index': 0 - }), - json_config_rule_set('/device[r1]/endpoint[eth10]/settings', { - 'address_ip': '10.10.10.229', 'address_prefix': 24, 'index': 0 - }), - json_config_rule_set('/device[r2]/endpoint[eth10]/settings', { - 'address_ip': '10.158.72.229', 'address_prefix': 24, 'index': 0 + 'address_ip': '10.10.10.0', 'neighbor_address': '10.10.10.229', 'address_prefix': 24, 'index': 0 }), json_config_rule_set('/device[edge-net]/endpoint[eth1]/settings', { - 'address_ip': '10.158.72.0', 'address_prefix': 24, 'index': 0 + 'address_ip': '10.158.72.0', 'neighbor_address': '10.158.72.229', 'address_prefix': 24, 'index': 0 }), ] )) CONNECTION_ENDPOINTS : List[Tuple[str, str, Optional[str]]] = [ #('core-net', 'int', None), - ('core-net', 'eth1', None), - ('r1', 'eth10', None), ('r1', 'eth2', None), - ('r2', 'eth1', None), ('r2', 'eth10', None), - ('edge-net', 'eth1', None), + ('core-net', 'eth1', None), ('r1', 'eth10', None), + ('r1', 'eth2', None), ('r2', 'eth1', None), + ('r2', 'eth10', None), ('edge-net', 'eth1', None), #('edge-net', 'int', None), ] diff --git a/src/tests/sns4sns24/02-ietf-l3vpn-nbi.json b/src/tests/sns4sns24/02-ietf-l3vpn-nbi.json index 31d7e0a6d1636af4572b10dd07cecc9a2aedeb9d..0d34cfe9adab63afc37bf4c618a5a6fc25dadbc7 100644 --- a/src/tests/sns4sns24/02-ietf-l3vpn-nbi.json +++ b/src/tests/sns4sns24/02-ietf-l3vpn-nbi.json @@ -11,7 +11,7 @@ "site-network-accesses": { "site-network-access": [ { - "site-network-access-id": "int", + "site-network-access-id": "eth1", "site-network-access-type": "ietf-l3vpn-svc:multipoint", "device-reference": "core-net", "vpn-attachment": {"vpn-id": "ietf-l3vpn-edge-core", "site-role": "ietf-l3vpn-svc:spoke-role"}, @@ -48,7 +48,7 @@ "site-network-accesses": { "site-network-access": [ { - "site-network-access-id": "int", + "site-network-access-id": "eth1", "site-network-access-type": "ietf-l3vpn-svc:multipoint", "device-reference": "edge-net", "vpn-attachment": {"vpn-id": "ietf-l3vpn-edge-core", "site-role": "ietf-l3vpn-svc:hub-role"},