Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cicd: fixed sctp client for various scenarios #421

Merged
merged 23 commits into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/k3s-flannel-incluster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
run: |
cd cicd/k3s-flannel-incluster
./config.sh
sleep 90
./validation.sh
cd -

Expand Down
Binary file added cicd/common/sctp_socat_client
Binary file not shown.
72 changes: 72 additions & 0 deletions cicd/common/sctp_socat_client.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netinet/sctp.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>

#define RECVBUFSIZE 4096
#define PPID 1234

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;
struct sctp_status status = {0};
struct sctp_sndrcvinfo sndrcvinfo = {0};
struct sctp_event_subscribe events = {0};
struct sctp_initmsg initmsg = {0};
char msg[1024] = {0};
char buff[1024] = {0};
socklen_t opt_len;
socklen_t slen = (socklen_t) sizeof(struct sockaddr_in);


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;

//bind to local address
error = bind(sockfd, (struct sockaddr *)&laddr, sizeof(struct sockaddr_in));
if (error != 0) {
printf("\n\n\t\t***r: error binding addr:"
" %s. ***\n", strerror(errno));
exit(1);
}

saddr = argv[3];
sport = atoi(argv[4]);
bzero( (void *)&servaddr, sizeof(servaddr) );
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(sport);
servaddr.sin_addr.s_addr = inet_addr( saddr );

connect( sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr));

while(1)
{
in = sctp_recvmsg(sockfd, (void*)buff, RECVBUFSIZE,
(struct sockaddr *)&servaddr,
&slen, &sndrcvinfo, &flags);
if (in > 0 && in < RECVBUFSIZE - 1)
{
buff[in] = 0;
printf("%s",buff);
break;
}
}

close(sockfd);
return 0;
}
8 changes: 4 additions & 4 deletions cicd/k3s-flannel-incluster/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ Vagrant.configure("2") do |config|
master.vm.network :private_network, ip: "192.168.90.10", :netmask => "255.255.255.0"
master.vm.provision :shell, :path => "master1.sh"
master.vm.provider :virtualbox do |vbox|
vbox.customize ["modifyvm", :id, "--memory", 8192]
vbox.customize ["modifyvm", :id, "--cpus", 4]
vbox.customize ["modifyvm", :id, "--memory", 4096]
vbox.customize ["modifyvm", :id, "--cpus", 2]
vbox.customize ["modifyvm", :id, "--nicpromisc1", "allow-all"]
vbox.customize ["modifyvm", :id, "--nicpromisc2", "allow-all"]
end
Expand All @@ -42,8 +42,8 @@ Vagrant.configure("2") do |config|
master.vm.network :private_network, ip: "192.168.90.11", :netmask => "255.255.255.0"
master.vm.provision :shell, :path => "master2.sh"
master.vm.provider :virtualbox do |vbox|
vbox.customize ["modifyvm", :id, "--memory", 8192]
vbox.customize ["modifyvm", :id, "--cpus", 4]
vbox.customize ["modifyvm", :id, "--memory", 4096]
vbox.customize ["modifyvm", :id, "--cpus", 2]
vbox.customize ["modifyvm", :id, "--nicpromisc1", "allow-all"]
vbox.customize ["modifyvm", :id, "--nicpromisc2", "allow-all"]
end
Expand Down
6 changes: 3 additions & 3 deletions cicd/k3s-flannel-incluster/host.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
wget https://github.com/loxilb-io/loxilb/raw/main/cicd/common/sctp_client
wget https://github.com/loxilb-io/loxilb/raw/main/cicd/common/sctp_socat_client
wget https://github.com/loxilb-io/loxilb/raw/main/cicd/common/udp_client
chmod 777 sctp_client
chmod 777 sctp_socat_client
chmod 777 udp_client
echo "123.123.123.1 k8s-svc" >> /etc/hosts

sudo apt install -y bird2 socat
sudo apt install -y bird2 socat lksctp-tools

sleep 5

Expand Down
2 changes: 1 addition & 1 deletion cicd/k3s-flannel-incluster/master1.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
sudo su
export MASTER_IP=$(ip a |grep global | grep -v '10.0.2.15' | grep -v '192.168.90' | grep '192.168.80' | awk '{print $2}' | cut -f1 -d '/')
curl -fL https://get.k3s.io | sh -s - server --node-ip=192.168.80.10 --disable servicelb --disable traefik --cluster-init external-hostname=192.168.80.10 --node-external-ip=192.168.80.10 --disable-cloud-controller
#curl -sfL https://github.com/loxilb-io/loxilb-ebpf/raw/main/kprobe/install.sh | sh -
curl -sfL https://github.com/loxilb-io/loxilb-ebpf/raw/main/kprobe/install.sh | sh -
sleep 60
echo $MASTER_IP > /vagrant/master-ip
cp /var/lib/rancher/k3s/server/node-token /vagrant/node-token
Expand Down
2 changes: 1 addition & 1 deletion cicd/k3s-flannel-incluster/master2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ export NODE_TOKEN=$(cat /vagrant/node-token)

#curl -fL https://get.k3s.io | K3S_TOKEN=${NODE_TOKEN} sh -s - server --server https://192.168.80.10:6443 --disable traefik --disable servicelb --node-ip=192.168.80.11 external-hostname=192.168.80.11 --node-external-ip=192.168.80.11 --disable-cloud-controller -t ${NODE_TOKEN}
curl -fL https://get.k3s.io | K3S_TOKEN=${NODE_TOKEN} sh -s - server --server https://192.168.80.10:6443 --disable traefik --disable servicelb --node-ip=192.168.80.11 external-hostname=192.168.80.11 --node-external-ip=192.168.80.11 -t ${NODE_TOKEN}
#curl -sfL https://github.com/loxilb-io/loxilb-ebpf/raw/main/kprobe/install.sh | sh -
curl -sfL https://github.com/loxilb-io/loxilb-ebpf/raw/main/kprobe/install.sh | sh -

/vagrant/wait_ready.sh
6 changes: 4 additions & 2 deletions cicd/k3s-flannel-incluster/validation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ else
exit 1
fi

out=$(vagrant ssh host -c "socat -T10 - sctp:$extIP:55004,bind=192.168.90.9")
#vagrant ssh host -c "socat -v -T10 - sctp:$extIP:55004,bind=192.168.90.9 1> /vagrant/log1.txt 2>&1"
out=$(vagrant ssh host -c "timeout 10 ./sctp_socat_client 192.168.90.9 0 $extIP 55004")
if [[ ${out} == *"server1"* ]]; then
echo "k3s-flannel-cluster (kube-loxilb) sctp [OK]"
else
Expand All @@ -50,7 +51,8 @@ else
exit 1
fi

out=$(vagrant ssh host -c "socat -T10 - sctp:$extIP:57004,bind=192.168.90.9")
#vagrant ssh host -c "socat -v -T10 - sctp:$extIP:57004,bind=192.168.90.9 1> /vagrant/log2.txt 2>&1"
out=$(vagrant ssh host -c "timeout 10 ./sctp_socat_client 192.168.90.9 0 $extIP 57004")
if [[ ${out} == *"server1"* ]]; then
echo "k3s-flannel-cluster (kube-loxilb) default-sctp [OK]"
else
Expand Down
2 changes: 1 addition & 1 deletion cicd/k8s-calico-ubuntu22/validation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ else
code=1
fi

out=$(timeout 10 ../common/sctp_client 192.168.90.1 34951 $extIP ${sctp_port[i]})
out=$(timeout 10 ../common/sctp_socat_client 192.168.90.1 34951 $extIP ${sctp_port[i]})
if [[ ${out} == *"server1"* ]]; then
echo -e "K8s-calico-Ubuntu22 SCTP\t(${mode[i]})\t[OK]"
else
Expand Down
2 changes: 1 addition & 1 deletion cicd/k8s-calico/validation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ else
code=1
fi

out=$(timeout 5 ../common/sctp_client 192.168.90.1 34951 $extIP ${sctp_port[i]})
out=$(timeout 5 ../common/sctp_socat_client 192.168.90.1 34951 $extIP ${sctp_port[i]})
if [[ ${out} == *"server1"* ]]; then
echo -e "K8s-calico SCTP\t(${mode[i]})\t[OK]"
else
Expand Down
Loading