Skip to content

Commit

Permalink
Add SCTP example
Browse files Browse the repository at this point in the history
  • Loading branch information
mertyildiran committed Jun 9, 2024
1 parent 734b731 commit 2ed3935
Show file tree
Hide file tree
Showing 15 changed files with 251 additions and 0 deletions.
9 changes: 9 additions & 0 deletions additions/sctp-client/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM python:3.8-slim-buster

WORKDIR /app
COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt
RUN apt-get update
RUN apt-get -y install curl procps
COPY example.py .
COPY run.sh .
3 changes: 3 additions & 0 deletions additions/sctp-client/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

docker build . -t mertyildiran/mizutest-sctp-client:latest && docker push mertyildiran/mizutest-sctp-client:latest
32 changes: 32 additions & 0 deletions additions/sctp-client/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import socket
import sctp
import time

print("Start SCTP client")

sock = sctp.sctpsocket_tcp(socket.AF_INET)

cnt = 0
connected = False
while True:
if not connected:
try:
sock.connect(("mizutest-sctp-server", 50051))
except:
print("couldn't connect")
time.sleep(3)
continue

connected = True

msg = 'hello world %s' % cnt
sock.sctp_send(msg=msg)
print("Sent %s" % msg)
cnt += 1

time.sleep(3)

sock.shutdown(0)


sock.close()
1 change: 1 addition & 0 deletions additions/sctp-client/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pysctp==0.7.2
3 changes: 3 additions & 0 deletions additions/sctp-client/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

python3 example.py
9 changes: 9 additions & 0 deletions additions/sctp-server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM python:3.8-slim-buster

WORKDIR /app
COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt
RUN apt-get update
RUN apt-get -y install curl procps
COPY example.py .
COPY run.sh .
3 changes: 3 additions & 0 deletions additions/sctp-server/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

docker build . -t mertyildiran/mizutest-sctp-server:latest && docker push mertyildiran/mizutest-sctp-server:latest
35 changes: 35 additions & 0 deletions additions/sctp-server/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import socket
import sctp

print("Start SCTP server")

host = '0.0.0.0'
port = 50051

sock = sctp.sctpsocket_tcp(socket.AF_INET)
sock.bind((host, port))
sock.listen(1)

while True:
# wait for a connection
print ('waiting for a connection')
connection, client_address = sock.accept()

try:
# show who connected to us
print ('connection from', client_address)
print (connection)
# receive the data in small chunks and print it
while True:
data = connection.recv(999)
if data:
# output received data
print ("Data: %s" % data.decode())
connection.sendall(str.encode("We recieved " + str(len(data)) + " bytes from you"))
else:
# no more data -- quit the loop
print ("no more data.")
break
finally:
# Clean up the connection
connection.close()
1 change: 1 addition & 0 deletions additions/sctp-server/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pysctp==0.7.2
3 changes: 3 additions & 0 deletions additions/sctp-server/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

python3 example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mizutest-sctp-server
labels:
name: mizutest-sctp-server
namespace: sock-shop
spec:
replicas: 1
selector:
matchLabels:
name: mizutest-sctp-server
template:
metadata:
labels:
name: mizutest-sctp-server
spec:
containers:
- name: mizutest-sctp-server
image: mertyildiran/mizutest-sctp-server:latest
env:
- name: PYTHONUNBUFFERED
value: "1"
- name: PYTHONIOENCODING
value: "UTF-8"
imagePullPolicy: Always
command: ["sh", "-c", "./run.sh"]
resources:
limits:
cpu: 75m
memory: 100Mi
requests:
cpu: 10m
memory: 10Mi
ports:
- containerPort: 50051
hostPort: 50051
protocol: SCTP
securityContext:
runAsNonRoot: true
runAsUser: 10001
capabilities:
drop:
- all
add:
- NET_BIND_SERVICE
readOnlyRootFilesystem: true
nodeSelector:
beta.kubernetes.io/os: linux
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
apiVersion: v1
kind: Service
metadata:
name: mizutest-sctp-server
annotations:
prometheus.io/scrape: 'true'
labels:
name: mizutest-sctp-server
namespace: sock-shop
spec:
clusterIP: None # Headless
ports:
# the port that this service should serve on
- port: 50051
targetPort: 50051
protocol: SCTP
selector:
name: mizutest-sctp-server
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mizutest-sctp-client
labels:
name: mizutest-sctp-client
namespace: sock-shop
spec:
replicas: 1
selector:
matchLabels:
name: mizutest-sctp-client
template:
metadata:
labels:
name: mizutest-sctp-client
spec:
containers:
- name: mizutest-sctp-client
image: mertyildiran/mizutest-sctp-client:latest
env:
- name: PYTHONUNBUFFERED
value: "1"
- name: PYTHONIOENCODING
value: "UTF-8"
imagePullPolicy: Always
command: ["sh", "-c", "./run.sh"]
resources:
limits:
cpu: 75m
memory: 100Mi
requests:
cpu: 10m
memory: 10Mi
ports:
- containerPort: 50051
securityContext:
runAsNonRoot: true
runAsUser: 10001
capabilities:
drop:
- all
add:
- NET_BIND_SERVICE
readOnlyRootFilesystem: true
nodeSelector:
beta.kubernetes.io/os: linux
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
apiVersion: v1
kind: Service
metadata:
name: mizutest-sctp-client
annotations:
prometheus.io/scrape: 'true'
labels:
name: mizutest-sctp-client
namespace: sock-shop
spec:
ports:
# the port that this service should serve on
- port: 50051
targetPort: 50051
selector:
name: mizutest-sctp-client
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: kubeshark-hub-network-policy
namespace: sock-shop
spec:
podSelector:
matchLabels:
name: mizutest-sctp-server
policyTypes:
- Ingress
- Egress
ingress:
- ports:
- protocol: SCTP
port: 50051
egress:
- {}

0 comments on commit 2ed3935

Please sign in to comment.