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

gh-242 : CPU usage fixes #255

Merged
merged 12 commits into from
Apr 18, 2023
4 changes: 4 additions & 0 deletions api/restapi/handler/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ func ConfigPostLoadbalancer(params operations.PostConfigLoadbalancerParams) midd
})
}

if lbRules.Serv.Mode == cmn.LBModeDSR && lbRules.Serv.Sel != cmn.LbSelHash {
return &ResultResponse{Result: "Error: Only Hash Selection criteria allowed for DSR mode"}
}

tk.LogIt(tk.LogDebug, "[API] lbRules : %v\n", lbRules)
_, err := ApiHooks.NetLbRuleAdd(&lbRules)
if err != nil {
Expand Down
19 changes: 10 additions & 9 deletions cicd/cluster2/validation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function tcp_validate() {
then
echo "All TCP Servers are not UP" >&2
echo CLUSTER-2 [FAILED] >&2
sudo pkill node
sudo pkill -9 node 2>&1 > /dev/null
exit 1
fi
fi
Expand Down Expand Up @@ -91,9 +91,9 @@ function tcp_validate() {
}

function sctp_validate() {
$hexec ep1 ../common/sctp_server server1 &
$hexec ep2 ../common/sctp_server server2 &
$hexec ep3 ../common/sctp_server server3 &
$hexec ep1 ../common/sctp_server ${ep[0]} 8080 server1 >/dev/null 2>&1 &
$hexec ep2 ../common/sctp_server ${ep[1]} 8080 server2 >/dev/null 2>&1 &
$hexec ep3 ../common/sctp_server ${ep[2]} 8080 server3 >/dev/null 2>&1 &

sleep 20

Expand All @@ -107,7 +107,7 @@ function sctp_validate() {
else
$hexec r2 ip route list match 20.20.20.1 >&2
echo "BGP Service Route [NOK]" >&2
sudo pkill sctp_server
sudo pkill -9 sctp_server >/dev/null 2&1
return 1
fi

Expand All @@ -117,7 +117,7 @@ function sctp_validate() {
waitCount=0
while [ $j -le 2 ]
do
res=$($hexec user timeout 10 ../common/sctp_client ${ep[j]} 8080)
res=$($hexec user timeout 10 ../common/sctp_client 1.1.1.1 0 ${ep[j]} 8080)
if [[ $res == "${servArr[j]}" ]]
then
echo "$res UP" >&2
Expand All @@ -129,6 +129,7 @@ function sctp_validate() {
then
echo "All SCTP Servers are not UP" >&2
echo CLUSTER-2 [FAILED] >&2
sudo pkill -9 sctp_server >/dev/null 2&1
exit 1
fi

Expand All @@ -140,7 +141,7 @@ function sctp_validate() {
do
for j in {0..2}
do
res=$($hexec user timeout 10 ../common/sctp_client 20.20.20.1 2020)
res=$($hexec user timeout 10 ../common/sctp_client 1.1.1.1 0 20.20.20.1 2020)
echo -e $res >&2
ids=`echo "${res//[!0-9]/}"`
if [[ $res == *"server"* ]]; then
Expand All @@ -165,7 +166,7 @@ function sctp_validate() {
sleep 1
done
done
sudo pkill sctp_server
sudo pkill -9 sctp_server >/dev/null 2>&1
echo $code
}

Expand Down Expand Up @@ -319,5 +320,5 @@ then
else
echo CLUSTER-2 SCTP [FAILED]
fi

sudo pkill -9 sctp_server >/dev/null 2>&1
exit $code
14 changes: 7 additions & 7 deletions cicd/cluster3/validation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ function tcp_validate() {
}

function sctp_validate() {
$hexec ep1 ../common/sctp_server server1 &
$hexec ep2 ../common/sctp_server server2 &
$hexec ep3 ../common/sctp_server server3 &
$hexec ep1 ../common/sctp_server ${ep[0]} 8080 server1 >/dev/null 2>&1 &
$hexec ep2 ../common/sctp_server ${ep[1]} 8080 server2 >/dev/null 2>&1 &
$hexec ep3 ../common/sctp_server ${ep[2]} 8080 server3 >/dev/null 2>&1 &

sleep 20

Expand All @@ -106,7 +106,7 @@ function sctp_validate() {
else
$hexec r2 ip route list match 20.20.20.1 >&2
echo "BGP Service Route [NOK]" >&2
sudo pkill sctp_server
sudo pkill sctp_server >/dev/null 2>&1
return 1
fi

Expand All @@ -116,7 +116,7 @@ function sctp_validate() {
waitCount=0
while [ $j -le 2 ]
do
res=$($hexec user timeout 10 ../common/sctp_client ${ep[j]} 8080)
res=$($hexec user timeout 10 ../common/sctp_client 1.1.1.1 0 ${ep[j]} 8080)
if [[ $res == "${servArr[j]}" ]]
then
echo "$res UP" >&2
Expand All @@ -139,7 +139,7 @@ function sctp_validate() {
do
for j in {0..2}
do
res=$($hexec user timeout 10 ../common/sctp_client 20.20.20.1 2020)
res=$($hexec user timeout 10 ../common/sctp_client 1.1.1.1 0 20.20.20.1 2020)
echo -e $res >&2
ids=`echo "${res//[!0-9]/}"`
if [[ $res == *"server"* ]]; then
Expand All @@ -164,7 +164,7 @@ function sctp_validate() {
sleep 1
done
done
sudo pkill sctp_server
sudo pkill sctp_server >/dev/null 2>&1
echo $code
}

Expand Down
Binary file modified cicd/common/sctp_client
Binary file not shown.
142 changes: 65 additions & 77 deletions cicd/common/sctp_client.c
Original file line number Diff line number Diff line change
@@ -1,96 +1,84 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netinet/sctp.h>
#include <arpa/inet.h>
#define MAX_BUFFER 1024
#define MY_PORT_NUM 8080 /* This can be changed to suit the need and should be same in server and client */
#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[])
int main(int argc, char* argv[])
{
int connSock, in, i, ret, flags;
struct sockaddr_in servaddr;
struct sctp_status status;
struct sctp_sndrcvinfo sndrcvinfo;
char buffer[MAX_BUFFER + 1];
int datalen = 0;
fd_set read_fd_set;

/*Get the input from user*/
//printf("Enter data to send: ");
//fgets(buffer, MAX_BUFFER, stdin);
/* Clear the newline or carriage return from the end*/
//buffer[strcspn(buffer, "\r\n")] = 0;
/* Sample input */
strncpy (buffer, "Hello Server", 12);
buffer[12] = '\0';
datalen = strlen(buffer);
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);


connSock = socket (AF_INET, SOCK_STREAM, IPPROTO_SCTP);
sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP);
lport = atoi(argv[2]);

if (connSock == -1)
{
printf("Socket creation failed\n");
perror("socket()");
exit(1);
}
laddr.sin_family = AF_INET;
laddr.sin_addr.s_addr = inet_addr(argv[1]);
laddr.sin_port = lport?htons(lport):0;

bzero ((void *) &servaddr, sizeof (servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons (atoi(argv[2]));
servaddr.sin_addr.s_addr = inet_addr (argv[1]);
//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);
}

ret = connect (connSock, (struct sockaddr *) &servaddr, sizeof (servaddr));
//set the association options
initmsg.sinit_num_ostreams = 1;
setsockopt( sockfd, IPPROTO_SCTP, SCTP_INITMSG, &initmsg,sizeof(initmsg));

if (ret == -1)
{
printf("Connection failed\n");
perror("connect()");
close(connSock);
exit(1);
}
FD_ZERO(&read_fd_set);
ret = sctp_sendmsg (connSock, (void *) buffer, (size_t) datalen,
NULL, 0, 0, 0, 0, 0, 0);
if(ret == -1 )
{
printf("Error in sctp_sendmsg\n");
perror("sctp_sendmsg()");
}
else {
// printf("Successfully sent %d bytes data to server\n", ret);
FD_SET(connSock, &read_fd_set);
int ret_val = select(FD_SETSIZE, &read_fd_set, NULL, NULL, NULL);
if (ret_val >= 0) {
if (FD_ISSET(connSock, &read_fd_set)) {
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 );

in = sctp_recvmsg (connSock, buffer, sizeof (buffer),
(struct sockaddr *) NULL, 0, &sndrcvinfo, &flags);

if( in == -1)
{
printf("Error in sctp_recvmsg\n");
perror("sctp_recvmsg()");
close(connSock);
return -1;
}
else {
//Add '\0' in case of text data
buffer[in] = '\0';
connect( sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr));

// printf (" Length of Data received: %d\n", in);
printf ("%s", (char *) buffer);
}
}
}
}
opt_len = (socklen_t) sizeof(struct sctp_status);
getsockopt(sockfd, IPPROTO_SCTP, SCTP_STATUS, &status, &opt_len);

while(1)
{
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);

close (connSock);
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;
}
}

return 0;
close(sockfd);
return 0;
}
Binary file modified cicd/common/sctp_server
Binary file not shown.