diff --git a/devstack/plugin.sh b/devstack/plugin.sh index e3de3f1b..340d3892 100644 --- a/devstack/plugin.sh +++ b/devstack/plugin.sh @@ -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 } diff --git a/test_container/kuryr_sctp_demo/Dockerfile b/test_container/kuryr_sctp_demo/Dockerfile new file mode 100644 index 00000000..25b395cc --- /dev/null +++ b/test_container/kuryr_sctp_demo/Dockerfile @@ -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"] diff --git a/test_container/kuryr_sctp_demo/sctp_client.py b/test_container/kuryr_sctp_demo/sctp_client.py new file mode 100644 index 00000000..b81f2aa0 --- /dev/null +++ b/test_container/kuryr_sctp_demo/sctp_client.py @@ -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])) diff --git a/test_container/kuryr_sctp_demo/sctp_server.py b/test_container/kuryr_sctp_demo/sctp_server.py new file mode 100644 index 00000000..79d6e6a2 --- /dev/null +++ b/test_container/kuryr_sctp_demo/sctp_server.py @@ -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()