Adds Kuryr-sctp-demo application

Adds the sctp-demo server and client application to test_container.

Partially-Implements: blueprint sctp-support
Change-Id: I4b6d3a0e8bff7fdeb23ec8de046ea71dbf690069
This commit is contained in:
Tabitha 2021-01-11 16:57:04 +01:00
parent a646091518
commit 60f778805d
4 changed files with 106 additions and 0 deletions

View File

@ -7,8 +7,12 @@ function build_test_container {
# hence this awful if clause.
if [[ ${CONTAINER_ENGINE} == 'crio' ]]; then
sudo buildah bud -t quay.io/kuryr/demo -f Dockerfile .
sudo buildah bud -t quay.io/kuryr/sctp-demo -f \
kuryr_sctp_demo/Dockerfile .
else
docker build -t quay.io/kuryr/demo . -f Dockerfile
docker build -t quay.io/kuryr/sctp-demo . -f \
kuryr_sctp_demo/Dockerfile
fi
popd
}

View File

@ -0,0 +1,29 @@
FROM quay.io/kuryr/alpine:3.12
RUN apk add --no-cache \
bash \
gcc \
g++ \
libstdc++ \
linux-headers \
lksctp-tools \
lksctp-tools-dev \
openssh-client \
net-tools \
python3 \
py3-pip \
python3-dev
ENV BUSYBOX_VERSION 1.31.1
RUN adduser -S kuryr
USER kuryr
WORKDIR /home/kuryr
COPY kuryr_sctp_demo/sctp_server.py /sctp_server.py
COPY kuryr_sctp_demo/sctp_client.py /home/kuryr/sctp_client.py
RUN pip3 --no-cache-dir install -U pip \
&& python3 -m pip install pysctp
EXPOSE 9090
ENTRYPOINT ["python3", "/sctp_server.py"]

View File

@ -0,0 +1,32 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import socket
import sys
import sctp
sk = sctp.sctpsocket_tcp(socket.AF_INET)
def connect_plus_message(out_ip, out_port):
sk.connect((out_ip, out_port))
print("Sending Message")
sk.sctp_send(msg='HELLO, I AM ALIVE!!!')
msgFromServer = sk.recvfrom(1024)
print(msgFromServer[0].decode('utf-8'))
sk.shutdown(0)
sk.close()
if __name__ == '__main__':
connect_plus_message(sys.argv[1], int(sys.argv[2]))

View File

@ -0,0 +1,41 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import platform
import sctp
import socket
host = '0.0.0.0'
port = 9090
sock = sctp.sctpsocket_tcp(socket.AF_INET)
sock.bind((host, port))
sock.listen(1)
while True:
# wait for a connection
connection, client_address = sock.accept()
try:
while True:
data = connection.recv(1024)
if data:
# send response to client.
response = '%s: HELLO, I AM ALIVE!!!' % platform.node()
sent = connection.send(response.encode('utf-8'))
else:
# no more data -- quit the loop
break
finally:
# Clean up the connection
connection.close()