Skip to content

Commit

Permalink
Merge pull request #643 from nik-netlox/main
Browse files Browse the repository at this point in the history
Misc: changes related to SCTP MH
  • Loading branch information
UltraInstinct14 authored Apr 18, 2024
2 parents 7d9fb77 + 6092e11 commit ef38a03
Show file tree
Hide file tree
Showing 18 changed files with 659 additions and 25 deletions.
Binary file modified cicd/common/sctp_client
Binary file not shown.
88 changes: 75 additions & 13 deletions cicd/common/sctp_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ int main(int argc, char* argv[])
{

struct sockaddr_in servaddr = {0};
struct sockaddr_in laddr = {0};
int sockfd, in, flags;
char *saddr;
int sport, lport, error = 0, secs = 0;
struct sockaddr_in laddr[10] = {0};
int sockfd, in, flags, count = 1;
char *saddr, *laddrs, *addr;
int sport, lport, error = 0, secs = 0, i = 0;
struct sctp_status status = {0};
struct sctp_sndrcvinfo sndrcvinfo = {0};
struct sctp_event_subscribe events = {0};
Expand All @@ -29,13 +29,35 @@ int main(int argc, char* argv[])
socklen_t opt_len;
socklen_t slen = (socklen_t) sizeof(struct sockaddr_in);


if (argc < 5) {
printf("Usage: %s localaddr1<,localaddr2..> localport serverIP serverport <delay> <count>\n", argv[0]);
exit(1);
}
sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP);
lport = atoi(argv[2]);

laddr.sin_family = AF_INET;
laddr.sin_addr.s_addr = inet_addr(argv[1]);
laddr.sin_port = lport?htons(lport):0;
laddrs = argv[1];
memset(laddr, 0, sizeof(laddr));
if (strstr(laddrs, ",")) {
i = 0;
addr = strtok(laddrs, ",\n");
laddr[0].sin_family = AF_INET;
laddr[0].sin_port = lport?htons(lport):0;
laddr[0].sin_addr.s_addr = inet_addr(addr);
//printf("%s\n", addr);
addr = strtok(NULL, ",\n");
while(addr != NULL) {
i++;
//printf("%s\n", addr);
laddr[i].sin_family = AF_INET;
laddr[i].sin_port = lport?htons(lport):0;
laddr[i].sin_addr.s_addr = inet_addr(addr);
addr = strtok(NULL, ",\n");
}
} else {
laddr[0].sin_family = AF_INET;
laddr[0].sin_addr.s_addr = inet_addr(argv[1]);
laddr[0].sin_port = lport?htons(lport):0;
}

//bind to local address
error = bind(sockfd, (struct sockaddr *)&laddr, sizeof(struct sockaddr_in));
Expand All @@ -45,15 +67,31 @@ int main(int argc, char* argv[])
exit(1);
}

int j = 1;
while(j <= i) {
error = sctp_bindx(sockfd,(struct sockaddr*) &laddr[j], j, SCTP_BINDX_ADD_ADDR);
if (error != 0) {
printf("\n\n\t\t***r: error adding addrs:"
" %s. ***\n", strerror(errno));
exit(1);
} else {
//printf("Bind OK\n");
}
j++;
}

//set the association options
initmsg.sinit_num_ostreams = 1;
setsockopt( sockfd, IPPROTO_SCTP, SCTP_INITMSG, &initmsg,sizeof(initmsg));

saddr = argv[3];
sport = atoi(argv[4]);
if (argv[5]) {
if (argc >=6 ) { /* Delay before exit */
secs = atoi(argv[5]);
}
if (argc == 7) { /* count for sending 1pps*/
count = atoi(argv[6]);
}
bzero( (void *)&servaddr, sizeof(servaddr) );
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(sport);
Expand All @@ -65,11 +103,25 @@ int main(int argc, char* argv[])
opt_len = (socklen_t) sizeof(struct sctp_status);
getsockopt(sockfd, IPPROTO_SCTP, SCTP_STATUS, &status, &opt_len);

while(1)
fd_set fds; // will be checked for being ready to read
FD_ZERO(&fds);
FD_SET(sockfd, &fds);
struct timeval tv = { 0 };
tv.tv_sec = 1;
tv.tv_usec = 0;

while(count)
{
strncpy (msg, "hello", strlen("hello"));
//printf("Sending msg to server: %s", msg);
sctp_sendmsg(sockfd, (const void *)msg, strlen(msg), NULL, 0,htonl(PPID), 0, 0 , 0, 0);
//printf("Sending msg to server: %s", msg);
//
int ret = select( sockfd + 1, &fds, NULL, NULL, &tv );
if (ret <= 0) {
printf("Timeout\n");
count--;
sleep(1);
} else if (FD_ISSET( sockfd, &fds )) {

in = sctp_recvmsg(sockfd, (void*)buff, RECVBUFSIZE,
(struct sockaddr *)&servaddr,
Expand All @@ -79,7 +131,17 @@ int main(int argc, char* argv[])
buff[in] = 0;
printf("%s",buff);
fflush(stdout);
break;
count--;
if(!count)
break;
else {
printf("\n");
fflush(stdout);
sleep(1);
}
}
} else {
break;
}
}
if(secs) sleep(secs);
Expand Down
Binary file modified cicd/common/sctp_server
Binary file not shown.
9 changes: 5 additions & 4 deletions cicd/common/sctp_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ int main(int argc, char* argv[]) {
if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int)) < 0)
perror("setsockopt(SO_REUSEADDR) failed");

i = 1;
if (strstr(saddrs, ",")) {
saddr = strtok(saddrs, ",\n");
laddr[0].sin_family = AF_INET;
laddr[0].sin_port = htons(lport);
laddr[0].sin_addr.s_addr = inet_addr(saddr);
printf("%s\n", saddr);
saddr = strtok(NULL, ",\n");
i = 1;
while(saddr != NULL) {
printf("%s\n", saddr);
laddr[i].sin_family = AF_INET;
Expand All @@ -77,14 +77,15 @@ int main(int argc, char* argv[]) {
" %s. ***\n", strerror(errno));
exit(1);
}

if (i > 1) {
error = sctp_bindx(sockfd,(struct sockaddr*) &laddr[1], i - 1, SCTP_BINDX_ADD_ADDR);
int j = 1;
while(j <= i) {
error = sctp_bindx(sockfd,(struct sockaddr*) &laddr[j], j - 1, SCTP_BINDX_ADD_ADDR);
if (error != 0) {
printf("\n\n\t\t***r: error adding addrs:"
" %s. ***\n", strerror(errno));
exit(1);
}
j++;
}
listen(sockfd, 1);

Expand Down
20 changes: 20 additions & 0 deletions cicd/k3s-flannel-multus/multus/multus-sctp-pod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: v1
kind: Pod
metadata:
name: sctp-pod-01
labels:
app: sctp-pod-01
annotations:
k8s.v1.cni.cncf.io/networks: '[{
"name": "macvlan1",
"default-route": ["4.0.6.149"]
}]'
spec:
containers:
- name: sctp-test
image: loxilbio/sctp-darn:latest
imagePullPolicy: Always
#command: ["/bin/sh", "-ec", "while :; do echo '.'; sleep 6 ; done"]
command: ["sctp_darn","-H", "0.0.0.0","-P", "9999", "-l"]
ports:
- containerPort: 9999
18 changes: 18 additions & 0 deletions cicd/k3s-flannel-multus/multus/multus-sctp-service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: v1
kind: Service
metadata:
name: multus-sctp-service
annotations:
loxilb.io/num-secondary-networks: "2"
loxilb.io/multus-nets: macvlan1,macvlan2
loxilb.io/lbmode: "fullnat"
spec:
externalTrafficPolicy: Local
loadBalancerClass: loxilb.io/loxilb
selector:
app: sctp-pod-01
ports:
- port: 55002
protocol: SCTP
targetPort: 9999
type: LoadBalancer
6 changes: 5 additions & 1 deletion cicd/k3s-sctpmh/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ $hexec r1 ip route add 20.20.20.1/32 via 11.11.11.11
# Route back to user
sudo ip route add 11.11.11.0/24 via 14.14.14.1
sudo ip route add 123.123.123.0/24 via 14.14.14.1
sudo ip route add 124.124.124.0/24 via 14.14.14.1
sudo ip route add 125.125.125.0/24 via 14.14.14.1

# Change default route in llb1
$hexec llb1 ip route del default
Expand Down Expand Up @@ -132,7 +134,9 @@ else
echo "Start K3s installation"

# Install k3s without external cloud-manager and disabled servicelb
curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=v1.22.9+k3s1 INSTALL_K3S_EXEC="server --disable traefik --disable servicelb --disable-cloud-controller --kubelet-arg cloud-provider=external" K3S_KUBECONFIG_MODE="644" sh -
sudo apt install ipset ipvsadm
curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="--disable traefik,metrics-server,servicelb" K3S_KUBECONFIG_MODE="644" sh -s - server --kube-proxy-arg proxy-mode=ipvs
#curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=v1.22.9+k3s1 INSTALL_K3S_EXEC="server --disable traefik --disable servicelb --disable-cloud-controller --kubelet-arg cloud-provider=external" K3S_KUBECONFIG_MODE="644" sh -
#curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="server --disable traefik --disable servicelb --disable-cloud-controller --kubelet-arg cloud-provider=external" K3S_KUBECONFIG_MODE="644" sh -

sleep 10
Expand Down
2 changes: 1 addition & 1 deletion cicd/k3s-sctpmh/rmconfig.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ if [[ -f "/usr/local/bin/k3s-uninstall.sh" ]]; then
/usr/local/bin/k3s-uninstall.sh
fi

sudo apt-get remove bird2 --yes
sudo apt-get remove bird2 ipvsadm ipset --yes
docker image rm loxilb-io/sctp-server
docker images -a | grep "loxilb-io" | awk '{print $3}' | xargs docker rmi
echo "#########################################"
Expand Down
1 change: 1 addition & 0 deletions cicd/k8s-calico-ipvs2-ha-ka-sync/rmconfig.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ vagrant destroy -f worker1
vagrant destroy -f master
vagrant destroy -f llb1
vagrant destroy -f llb2
vagrant destroy -f host
96 changes: 96 additions & 0 deletions cicd/sctpmh/config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/bin/bash

source ../common.sh

echo "#########################################"
echo "Spawning all hosts"
echo "#########################################"

spawn_docker_host --dock-type loxilb --dock-name llb1
spawn_docker_host --dock-type host --dock-name ep1
spawn_docker_host --dock-type host --dock-name r1
spawn_docker_host --dock-type host --dock-name r2
spawn_docker_host --dock-type host --dock-name r3
spawn_docker_host --dock-type host --dock-name r4
spawn_docker_host --dock-type host --dock-name sw1
spawn_docker_host --dock-type host --dock-name sw2
spawn_docker_host --dock-type host --dock-name user

echo "#########################################"
echo "Connecting and configuring hosts"
echo "#########################################"

connect_docker_hosts user r1
connect_docker_hosts user r2
connect_docker_hosts r1 sw1
connect_docker_hosts r2 sw1
connect_docker_hosts sw1 llb1
connect_docker_hosts llb1 sw2
connect_docker_hosts sw2 r3
connect_docker_hosts sw2 r4
connect_docker_hosts r3 ep1
connect_docker_hosts r4 ep1

create_docker_host_cnbridge --host1 sw1 --host2 llb1
create_docker_host_cnbridge --host1 sw1 --host2 r1
create_docker_host_cnbridge --host1 sw1 --host2 r2

create_docker_host_cnbridge --host1 sw2 --host2 llb1
create_docker_host_cnbridge --host1 sw2 --host2 r3
create_docker_host_cnbridge --host1 sw2 --host2 r4

#node1 config
config_docker_host --host1 user --host2 r1 --ptype phy --addr 1.1.1.1/24 --gw 1.1.1.254
config_docker_host --host1 user --host2 r2 --ptype phy --addr 2.2.2.1/24
config_docker_host --host1 r1 --host2 user --ptype phy --addr 1.1.1.254/24
config_docker_host --host1 r2 --host2 user --ptype phy --addr 2.2.2.254/24

create_docker_host_vlan --host1 llb1 --host2 sw1 --id 11 --ptype untagged
create_docker_host_vlan --host1 r1 --host2 sw1 --id 11 --ptype untagged
create_docker_host_vlan --host1 r2 --host2 sw1 --id 11 --ptype untagged
config_docker_host --host1 r1 --host2 sw1 --ptype vlan --id 11 --addr 11.11.11.253/24 --gw 11.11.11.1
config_docker_host --host1 r2 --host2 sw1 --ptype vlan --id 11 --addr 11.11.11.254/24 --gw 11.11.11.1
config_docker_host --host1 llb1 --host2 sw1 --ptype vlan --id 11 --addr 11.11.11.1/24

create_docker_host_vlan --host1 llb1 --host2 sw2 --id 10 --ptype untagged
create_docker_host_vlan --host1 r3 --host2 sw2 --id 10 --ptype untagged
create_docker_host_vlan --host1 r4 --host2 sw2 --id 10 --ptype untagged

config_docker_host --host1 llb1 --host2 sw2 --ptype vlan --id 10 --addr 10.10.10.1/24
config_docker_host --host1 r3 --host2 sw2 --ptype vlan --id 10 --addr 10.10.10.253/24 --gw 10.10.10.1
config_docker_host --host1 r4 --host2 sw2 --ptype vlan --id 10 --addr 10.10.10.254/24 --gw 10.10.10.1

config_docker_host --host1 ep1 --host2 r3 --ptype phy --addr 31.31.31.1/24 --gw 31.31.31.254
config_docker_host --host1 ep1 --host2 r4 --ptype phy --addr 32.32.32.1/24
config_docker_host --host1 r3 --host2 ep1 --ptype phy --addr 31.31.31.254/24
config_docker_host --host1 r4 --host2 ep1 --ptype phy --addr 32.32.32.254/24

$hexec user ip route change default via 1.1.1.254
$hexec ep1 ip route change default via 31.31.31.254

# Backup paths in user
$hexec user ip route add 124.124.124.1/32 via 2.2.2.254
$hexec user ip route add 125.125.125.1/32 via 2.2.2.254
$hexec user ip route add 134.134.134.1/32 via 2.2.2.254
$hexec user ip route add 135.135.135.1/32 via 2.2.2.254

$hexec ep1 ip route add 124.124.124.1/32 via 32.32.32.254
$hexec ep1 ip route add 125.125.125.1/32 via 32.32.32.254
$hexec ep1 ip route add 134.134.134.1/32 via 32.32.32.254
$hexec ep1 ip route add 135.135.135.1/32 via 32.32.32.254

$hexec llb1 ip route add 1.1.1.0/24 via 11.11.11.253
$hexec llb1 ip route add 2.2.2.0/24 via 11.11.11.254

$hexec llb1 ip route add 31.31.31.0/24 via 10.10.10.253
$hexec llb1 ip route add 32.32.32.0/24 via 10.10.10.254

sleep 20
##Create LB rule user->ep1
create_lb_rule llb1 123.123.123.1 --secips=124.124.124.1,125.125.125.1 --sctp=2020:9999 --endpoints=31.31.31.1:1 --mode=fullnat

##Create LB rule ep1->user
create_lb_rule llb1 133.133.133.1 --secips=134.134.134.1,135.135.135.1 --sctp=2020:9999 --endpoints=1.1.1.1:1 --mode=fullnat

$dexec llb1 loxicmd create ep 1.1.1.1 --name=1.1.1.1_sctp_9999 --probetype=none
$dexec llb1 loxicmd create ep 31.31.31.1 --name=31.31.31.1_sctp_9999 --probetype=none
6 changes: 6 additions & 0 deletions cicd/sctpmh/input
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@






32 changes: 32 additions & 0 deletions cicd/sctpmh/rmconfig.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

echo "#########################################"
echo "Removing testbed"
echo "#########################################"

source ../common.sh

disconnect_docker_hosts user r1
disconnect_docker_hosts user r2
disconnect_docker_hosts r1 sw1
disconnect_docker_hosts r2 sw1
disconnect_docker_hosts sw1 llb1
disconnect_docker_hosts llb1 sw2
disconnect_docker_hosts sw2 r3
disconnect_docker_hosts sw2 r4
disconnect_docker_hosts r3 ep1
disconnect_docker_hosts r4 ep1

delete_docker_host llb1
delete_docker_host user
delete_docker_host r1
delete_docker_host r2
delete_docker_host r3
delete_docker_host r4
delete_docker_host sw1
delete_docker_host sw2
delete_docker_host ep1

echo "#########################################"
echo "Removed testbed"
echo "#########################################"
14 changes: 14 additions & 0 deletions cicd/sctpmh/validation.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
echo "SCTP Multihoming - Test case #1"
echo -e "*********************************************************************************"
./validation1.sh
echo -e "\n\n\nSCTP Multihoming - Test case #2"
echo -e "*********************************************************************************"
./validation2.sh
echo -e "\n\n\nSCTP Multihoming - Test case #3"
echo -e "*********************************************************************************"
./validation3.sh
echo -e "\n\n\nSCTP Multihoming - Test case #4"
echo -e "*********************************************************************************"
./validation4.sh
echo -e "\n\n\n*********************************************************************************"
Loading

0 comments on commit ef38a03

Please sign in to comment.