diff --git a/hack/configVxlans.sh b/hack/configVxlans.sh new file mode 100755 index 0000000000000000000000000000000000000000..f9bf41c6ee2a9365b2ce1aa7815e8c58e42e5911 --- /dev/null +++ b/hack/configVxlans.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# Path to the configuration file +configFilePath="./configs/switchConfig.json" + +# Use kubectl to get pods and grep for those starting with 'l2sm-switch' +# Then, use awk to extract the pod name and node name by matching an IP pattern and taking the next column as the node +mapfile -t podInfo < <(kubectl get pods -o wide | grep 'l2sm-switch' | awk '{for (i=1; i<=NF; i++) { if ($i ~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/) { print $1 ":" $(i+1); break; } }}') + +# Declare an associative array to store pod names and their respective nodes +declare -A pods + +# Fill the associative array with pod names as keys and node names as values +for entry in "${podInfo[@]}" +do + podName="${entry%%:*}" + nodeName="${entry##*:}" + pods["$podName"]=$nodeName +done + +# Loop through the array +for pod in "${!pods[@]}" +do + nodeName=${pods[$pod]} + + # Copy the configuration file to the pod + echo "Copying config file to $pod..." + kubectl cp "$configFilePath" "$pod:/etc/l2sm/switchConfig.json" + + # Execute the script inside the pod + echo "Executing configuration script on $pod..." + kubectl exec -it "$pod" -- /bin/bash -c "l2sm-vxlans --node_name=$nodeName /etc/l2sm/switchConfig.json" +done + +echo "Configuration deployment completed." diff --git a/hack/generateConfig.sh b/hack/generateConfig.sh new file mode 100755 index 0000000000000000000000000000000000000000..7996ae44546d330be9f37b0f8fed66448a63d32a --- /dev/null +++ b/hack/generateConfig.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +# Filename for the JSON config +jsonConfigPath="./configs/switchConfig.json" + +# Use kubectl to get pods, grep for those starting with 'l2sm-switch', and parse with awk +mapfile -t podInfo < <(kubectl get pods -o wide | grep 'l2sm-switch' | awk '{for (i=1; i<=NF; i++) { if ($i ~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/) { print $(i+1) ":" $i; break; } }}') + +# Associative array to store node names and their respective IPs +declare -A nodeIPs + +# Fill the associative array with node names as keys and IPs as values +for entry in "${podInfo[@]}" +do + nodeName="${entry%%:*}" + nodeIP="${entry##*:}" + nodeIPs["$nodeName"]=$nodeIP +done + +# Prepare Nodes array +nodesArray=() +for nodeName in "${!nodeIPs[@]}" +do + nodesArray+=("{\"name\": \"$nodeName\", \"nodeIP\": \"${nodeIPs[$nodeName]}\"}") +done + +# Prepare Links array +linksArray=() +declare -A linkPairs +for srcNode in "${!nodeIPs[@]}" +do + for dstNode in "${!nodeIPs[@]}" + do + if [[ "$srcNode" != "$dstNode" && -z ${linkPairs["$srcNode:$dstNode"]} && -z ${linkPairs["$dstNode:$srcNode"]} ]]; then + linksArray+=("{\"endpointA\": \"$srcNode\", \"endpointB\": \"$dstNode\"}") + linkPairs["$srcNode:$dstNode"]=1 + fi + done +done + +# Generate JSON output +echo "{ + \"Nodes\": [ + $(IFS=,; echo "${nodesArray[*]}") + ], + \"Links\": [ + $(IFS=,; echo "${linksArray[*]}") + ] +}" > $jsonConfigPath + +echo "Network topology configuration has been generated at $jsonConfigPath."