Skip to content
Snippets Groups Projects
Unverified Commit 205efcfc authored by Alex's avatar Alex Committed by GitHub
Browse files

Merge pull request #4 from Networks-it-uc3m/quick-installation

Quick installation
parents 9c213409 63ea59c7
No related branches found
No related tags found
1 merge request!2repo: added new directory where utils scripts will be
apiVersion: apps/v1
kind: Deployment
metadata:
name: content-server
spec:
selector:
matchLabels:
app: test4
replicas: 1
template:
metadata:
labels:
app: test4
annotations:
k8s.v1.cni.cncf.io/networks: v-network-2
spec:
containers:
- name: content-server
image: alexdecb/video-server-test:1
command: ["/bin/sh", "-c", "ip a add 10.0.2.2/24 dev net1 && ip route add 10.0.1.0/24 via 10.0.2.1 dev net1 && trap : TERM INT; sleep infinity & wait"]
imagePullPolicy: Always
securityContext:
capabilities:
add: ["NET_ADMIN"]
#nodeName: test-l2sm-uc3m-polito-3
\ No newline at end of file
apiVersion: v1
kind: Pod
metadata:
name: router
labels:
app: test4
annotations:
k8s.v1.cni.cncf.io/networks: v-network-1, v-network-2
spec:
# securityContext:
# sysctls:
# - name: net.ipv4.ip_forward
# value: "1"
containers:
- name: router
command: ["/bin/ash", "-c"]
args: ["echo 'net.ipv4.ip_forward = 1' >> /etc/sysctl.conf && sysctl -p && ip addr add 10.0.1.1/24 dev net1 && ip addr add 10.0.2.1/24 dev net2 &&
trap : TERM INT; sleep infinity & wait"]
image: alpine:latest
securityContext:
privileged: true
capabilities:
add: ["NET_ADMIN"]
#nodeName: test-l2sm-uc3m-polito-2
apiVersion: "k8s.cni.cncf.io/v1"
kind: NetworkAttachmentDefinition
metadata:
name: v-network-1
spec:
config: '{
"cniVersion": "0.3.0",
"type": "l2sm",
"device": "l2sm-vNet"
}'
apiVersion: "k8s.cni.cncf.io/v1"
kind: NetworkAttachmentDefinition
metadata:
name: v-network-2
spec:
config: '{
"cniVersion": "0.3.0",
"type": "l2sm",
"device": "l2sm-vNet"
}'
# Use the official Nginx image as the base image
FROM nginx:latest
# Set the working directory to /usr/share/nginx/html
WORKDIR /usr/share/nginx/html
# Copy the video file into the container
COPY big_buck_bunny.avi .
# Create an Nginx configuration file to serve the video
RUN echo "server {" > /etc/nginx/conf.d/default.conf \
&& echo " listen 10.0.2.2:80;" >> /etc/nginx/conf.d/default.conf \
&& echo " location / {" >> /etc/nginx/conf.d/default.conf \
&& echo " root /usr/share/nginx/html;" >> /etc/nginx/conf.d/default.conf \
&& echo " index big_buck_bunny.avi;" >> /etc/nginx/conf.d/default.conf \
&& echo " autoindex on;" >> /etc/nginx/conf.d/default.conf \
&& echo " types {" >> /etc/nginx/conf.d/default.conf \
&& echo " video/avi avi;" >> /etc/nginx/conf.d/default.conf \
&& echo " }" >> /etc/nginx/conf.d/default.conf \
&& echo " }" >> /etc/nginx/conf.d/default.conf \
&& echo "}" >> /etc/nginx/conf.d/default.conf
RUN apt update && apt install -y iproute2
# Sleep indefinitely to keep the container running
CMD ["sleep", "infinity"]
File moved
kopf==1.37.0
kubernetes==28.1.0
PyMySQL==1.1.0
cryptography==3.4.8
requests==2.25.1
\ No newline at end of file
package main
import (
"errors"
"flag"
"fmt"
"os/exec"
"regexp"
)
// Script that takes two required arguments:
// the first one is the name in the cluster of the node where the script is running
// the second one is the path to the configuration file, in reference to the code.
func main() {
vethNumber, controllerIP, err := takeArguments()
if err != nil {
fmt.Println("Error with the arguments. Error:", err)
return
}
fmt.Println("Initializing switch, connected to controller: ", controllerIP)
err = initializeSwitch(controllerIP)
if err != nil {
fmt.Println("Could not initialize switch. Error:", err)
return
}
fmt.Println("Switch initialized and connected to the controller.")
// Set all virtual interfaces up, and connect them to the tunnel bridge:
for i := 1; i <= vethNumber; i++ {
veth := fmt.Sprintf("net%d", i)
cmd := exec.Command("ip", "link", "set", veth, "up") // i.e: ip link set veth1 up
if err := cmd.Run(); err != nil {
fmt.Println("Error:", err)
}
exec.Command("ovs-vsctl", "add-port", "brtun", veth).Run() // i.e: ovs-vsctl add-port brtun veth1
}
}
func takeArguments() (int, string, error) {
vethNumber := flag.Int("n_veths", 0, "number of pod interfaces that are going to be attached to the switch")
controllerIP := flag.String("controller_ip", "", "ip where the SDN controller is listening using the OpenFlow13 protocol. Required")
flag.Parse()
switch {
case *controllerIP == "":
return 0, "", errors.New("controller IP is not defined")
}
return *vethNumber, *controllerIP, nil
}
func initializeSwitch(controllerIP string) error {
re := regexp.MustCompile(`\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b`)
if !re.MatchString(controllerIP) {
out, _ := exec.Command("host", controllerIP).Output()
controllerIP = re.FindString(string(out))
}
var err error
err = exec.Command("ovs-vsctl", "add-br", "brtun").Run()
if err != nil {
return errors.New("could not create brtun interface")
}
err = exec.Command("ip", "link", "set", "brtun", "up").Run()
if err != nil {
return errors.New("could not set brtun interface up")
}
err = exec.Command("ovs-vsctl", "set", "bridge", "brtun", "protocols=OpenFlow13").Run()
if err != nil {
return errors.New("could not set brtun messaing protocol to OpenFlow13")
}
target := fmt.Sprintf("tcp:%s:6633", controllerIP)
err = exec.Command("ovs-vsctl", "set-controller", "brtun", target).Run()
if err != nil {
return errors.New("could not connect to controller")
}
return nil
}
...@@ -8,7 +8,6 @@ import ( ...@@ -8,7 +8,6 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"os/exec" "os/exec"
"regexp"
"strings" "strings"
) )
...@@ -23,33 +22,13 @@ type Node struct { ...@@ -23,33 +22,13 @@ type Node struct {
// the second one is the path to the configuration file, in reference to the code. // the second one is the path to the configuration file, in reference to the code.
func main() { func main() {
configDir, vethNumber, nodeName, controllerIP, err := takeArguments() configDir, nodeName, err := takeArguments()
if err != nil { if err != nil {
fmt.Println("Error with the arguments. Error:", err) fmt.Println("Error with the arguments. Error:", err)
return return
} }
fmt.Println("initializing switch, connected to controller: ", controllerIP)
err = initializeSwitch(controllerIP)
if err != nil {
fmt.Println("Could not initialize switch. Error:", err)
return
}
fmt.Println("Switch initialized and connected to the controller.")
// Set all virtual interfaces up, and connect them to the tunnel bridge:
for i := 1; i <= vethNumber; i++ {
veth := fmt.Sprintf("net%d", i)
cmd := exec.Command("ip", "link", "set", veth, "up") // i.e: ip link set veth1 up
if err := cmd.Run(); err != nil {
fmt.Println("Error:", err)
}
exec.Command("ovs-vsctl", "add-port", "brtun", veth).Run() // i.e: ovs-vsctl add-port brtun veth1
}
err = createVxlans(configDir, nodeName) err = createVxlans(configDir, nodeName)
if err != nil { if err != nil {
...@@ -58,63 +37,21 @@ func main() { ...@@ -58,63 +37,21 @@ func main() {
} }
} }
func takeArguments() (string, int, string, string, error) { func takeArguments() (string, string, error) {
configDir := os.Args[len(os.Args)-1] configDir := os.Args[len(os.Args)-1]
vethNumber := flag.Int("n_veths", 0, "number of pod interfaces that are going to be attached to the switch")
nodeName := flag.String("node_name", "", "name of the node the script is executed in. Required.") nodeName := flag.String("node_name", "", "name of the node the script is executed in. Required.")
controllerIP := flag.String("controller_ip", "", "ip where the SDN controller is listening using the OpenFlow13 protocol. Required")
flag.Parse() flag.Parse()
switch { switch {
case *nodeName == "": case *nodeName == "":
return "", 0, "", "", errors.New("Node name is not defined") return "", "", errors.New("node name is not defined")
case configDir == "": case configDir == "":
return "", 0, "", "", errors.New("Config directory is not defined") return "", "", errors.New("config directory is not defined")
case *controllerIP == "":
return "", 0, "", "", errors.New("Controller IP is not defined")
}
return configDir, *vethNumber, *nodeName, *controllerIP, nil
}
func initializeSwitch(controllerIP string) error {
re := regexp.MustCompile(`\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b`)
if !re.MatchString(controllerIP) {
out, _ := exec.Command("host", controllerIP).Output()
controllerIP = re.FindString(string(out))
}
var err error
err = exec.Command("ovs-vsctl", "add-br", "brtun").Run()
if err != nil {
return errors.New("Could not create brtun interface")
}
err = exec.Command("ip", "link", "set", "brtun", "up").Run()
if err != nil {
return errors.New("Could not set brtun interface up")
}
err = exec.Command("ovs-vsctl", "set", "bridge", "brtun", "protocols=OpenFlow13").Run()
if err != nil {
return errors.New("Couldnt set brtun messaing protocol to OpenFlow13")
} }
target := fmt.Sprintf("tcp:%s:6633", controllerIP) return configDir, *nodeName, nil
err = exec.Command("ovs-vsctl", "set-controller", "brtun", target).Run()
if err != nil {
return errors.New("Could not connect to controller")
}
return nil
} }
func createVxlans(configDir, nodeName string) error { func createVxlans(configDir, nodeName string) error {
...@@ -151,16 +88,16 @@ func createVxlans(configDir, nodeName string) error { ...@@ -151,16 +88,16 @@ func createVxlans(configDir, nodeName string) error {
"set", "interface", "set", "interface",
fmt.Sprintf("vxlan%d", vxlanNumber), fmt.Sprintf("vxlan%d", vxlanNumber),
"type=vxlan", "type=vxlan",
fmt.Sprintf("options:key=flow"), "options:key=flow",
fmt.Sprintf("options:remote_ip=%s", neighborIP), fmt.Sprintf("options:remote_ip=%s", neighborIP),
fmt.Sprintf("options:local_ip=%s", nodeIP), fmt.Sprintf("options:local_ip=%s", nodeIP),
"options:dst_port=7000", "options:dst_port=7000",
} }
_, err := exec.Command("ovs-vsctl", commandArgs...).Output() _, err := exec.Command("ovs-vsctl", commandArgs...).Output()
if err != nil { if err != nil {
return errors.New(fmt.Sprintf("Could not create vxlan between node %s and node %s.", node.Name, neighbor)) return fmt.Errorf("could not create vxlan between node %s and node %s", node.Name, neighbor)
} else { } else {
fmt.Println(fmt.Sprintf("Created vxlan between node %s and node %s.", node.Name, neighbor)) fmt.Printf("Created vxlan between node %s and node %s.\n", node.Name, neighbor)
} }
} }
vxlanNumber++ vxlanNumber++
......
File moved
...@@ -6,4 +6,7 @@ ovs-vsctl --db=unix:/var/run/openvswitch/db.sock --no-wait init ...@@ -6,4 +6,7 @@ ovs-vsctl --db=unix:/var/run/openvswitch/db.sock --no-wait init
ovs-vswitchd --pidfile=/var/run/openvswitch/ovs-vswitchd.pid --detach ovs-vswitchd --pidfile=/var/run/openvswitch/ovs-vswitchd.pid --detach
l2sm-br --n_veths=$NVETHS --node_name=$NODENAME --controller_ip=$CONTROLLERIP /etc/l2sm/switchConfig.json l2sm-init --n_veths=$NVETHS --controller_ip=$CONTROLLERIP
#l2sm-vxlans --node_name=$NODENAME /etc/l2sm/switchConfig.json
sleep infinity
File moved
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment