Skip to content

Commit

Permalink
Finally working operator
Browse files Browse the repository at this point in the history
  • Loading branch information
VidarHUN committed Feb 17, 2021
1 parent b10f1f6 commit c5afdee
Show file tree
Hide file tree
Showing 11 changed files with 585 additions and 74 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ WORKDIR /app
COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt
COPY . .
EXPOSE 22222
# EXPOSE 22222
ENTRYPOINT [ "/app/entrypoint.sh" ]
# CMD ["python3", "app.py", "--config_file", "config/sample-config.conf"]
53 changes: 37 additions & 16 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import sdp_transform
import socket
import time
import os

MULTI_PARAMETERS_COMMANDS = [
'file', 'delete', 'start_recording', 'stop_recording', 'block_dtmf',
Expand Down Expand Up @@ -42,22 +43,40 @@ def main():
args = arguments()
commands = Commands()
options(args, commands)
if not args.server:
if args.offer:
offer_rtp_port = handle_oa(
args.addr, args.port,
args.offer, args.bind_offer, "offer")
if args.answer:
answer_rtp_port = handle_oa(
args.addr, args.port,
args.answer, args.bind_answer, "answer")
if args.generate_calls:
global g_calls
if args.offer:
offer_rtp_port = handle_oa(
args.addr, args.port,
args.offer, args.bind_offer, "offer")
if args.answer:
answer_rtp_port = handle_oa(
args.addr, args.port,
args.answer, args.bind_answer, "answer")
if args.generate_calls:
global g_calls
if not args.sidecar_type:
g_calls = GenerateCall(
args.addr, args.port, args.sdpaddr, args.audio_file,
args.rtpsend, args.in_cluster, args.without_jsonsocket)
address=args.addr,
port=args.port,
sdp_address=args.sdpaddr,
audio_file=args.audio_file,
rtpsend=args.rtpsend,
in_cluster=args.in_cluster,
without_jsonsocket=args.without_jsonsocket,
sidecar=""
)
g_calls.generate_calls(args.generate_calls)
elif args.sidecar_type == 'l7mp':
g_calls = GenerateCall(
address=args.addr,
port=args.port,
sdp_address=args.sdpaddr,
audio_file=args.audio_file,
rtpsend=args.rtpsend,
in_cluster=args.in_cluster,
without_jsonsocket=args.without_jsonsocket,
sidecar=args.sidecar_type
)
g_calls.generate_calls(args.generate_calls)


if args.offer and args.answer and args.ffmpeg:
time.sleep(1)
Expand All @@ -68,8 +87,10 @@ def main():
def delete():
apis = g_calls.get_apis()
g_calls.delete_calls()
for a in apis:
a.delete_resources()
if os.getenv('RTPE_OPERATOR'):
print('test')
for a in apis:
a.delete_resources()

if __name__ == '__main__':
try:
Expand Down
88 changes: 46 additions & 42 deletions client/call_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ class GenerateCall():
''' With this class you can generate calls.
'''

def __init__(self, address, port, sdp_address, audio_file, in_cluster,
rtpsend, without_jsonsocket):
self.address = address
self.port = port
self.sdp_address = sdp_address
self.audio_file = audio_file
self.in_cluster = in_cluster
def __init__(self, **kwargs):
self.address = kwargs['address']
self.port = kwargs['port']
self.sdp_address = kwargs['sdp_address']
self.audio_file = kwargs['audio_file']
self.in_cluster = kwargs['in_cluster']
self.apis = []
self.calls = []
self.commands = Commands()
self.rtpsend = rtpsend
self.without_jsonsocket = without_jsonsocket
self.rtpsend = kwargs['rtpsend']
self.without_jsonsocket = kwargs['without_jsonsocket']
self.sidecar = kwargs['sidecar']

def send_offer(self, start_port):
sdp_offer = self.commands.offer(
Expand Down Expand Up @@ -95,6 +95,7 @@ def generate_calls(self, cnt):
start_port += 2
self.send_answer(start_port)

print(str(start_port - 2) + "-" + str(start_port))
query = send(
self.address, self.port,
self.commands.query(str(start_port - 2) + "-" + str(start_port)),
Expand Down Expand Up @@ -130,40 +131,44 @@ def generate_calls(self, cnt):
callee_source_ports.append(str(start_port))
caller_destinations.append(self.address + '/' + str(offer_rtp_port))
callee_destinations.append(self.address + '/' + str(answer_rtp_port))

# Offer
self.apis.append(
KubernetesAPIClient(
self.in_cluster,
call_id=str(start_port - 2) + "-" + str(start_port),
tag="from-tag" + str(start_port - 2),
# local_ip='127.0.0.1',
local_ip=self.sdp_address,
local_rtp_port=start_port - 2,
local_rtcp_port=start_port - 1,
remote_rtp_port=offer_rtp_port,
remote_rtcp_port=offer_rtcp_port,
without_jsonsocket=self.without_jsonsocket
)
)

# Answer
self.apis.append(
KubernetesAPIClient(
self.in_cluster,
call_id=str(start_port - 2) + "-" + str(start_port),
tag="to-tag" + str(start_port - 2),
# local_ip='127.0.0.1',
local_ip=self.sdp_address,
local_rtp_port=start_port,
local_rtcp_port=start_port + 1,
remote_rtp_port=answer_rtp_port,
remote_rtcp_port=answer_rtcp_port,
without_jsonsocket=self.without_jsonsocket
if not self.sidecar:
# Offer
print('test before offer')
self.apis.append(
KubernetesAPIClient(
self.in_cluster,
call_id=str(start_port - 2) + "-" + str(start_port),
tag="from-tag" + str(start_port - 2),
# local_ip='127.0.0.1',
local_ip=self.sdp_address,
local_rtp_port=start_port - 2,
local_rtcp_port=start_port - 1,
remote_rtp_port=offer_rtp_port,
remote_rtcp_port=offer_rtcp_port,
without_jsonsocket=self.without_jsonsocket
)
)

# Answer
print('test before answer')
self.apis.append(
KubernetesAPIClient(
self.in_cluster,
call_id=str(start_port - 2) + "-" + str(start_port),
tag="to-tag" + str(start_port - 2),
# local_ip='127.0.0.1',
local_ip=self.sdp_address,
local_rtp_port=start_port,
local_rtcp_port=start_port + 1,
remote_rtp_port=answer_rtp_port,
remote_rtcp_port=answer_rtcp_port,
without_jsonsocket=self.without_jsonsocket
)
)
)

time.sleep(1)
print('test before stream')
if not self.rtpsend:
ffmpeg(self.audio_file, cnt, offers, answers)
else:
Expand All @@ -182,9 +187,8 @@ def delete_calls(self):
rtpengine based on their call_id and from-tag.
'''
for call in self.calls:
deleted_call = send(
send(
self.address, self.port,
self.commands.delete(call['call_id'], call['from-tag']),
self.sdp_address, 3000
)
pprint(deleted_call)
)
9 changes: 6 additions & 3 deletions client/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import logging
import sdp_transform
import json
import os
from pprint import pprint

bc = bencodepy.Bencode(
Expand Down Expand Up @@ -69,9 +70,11 @@ def send(address, port, file, bind_address, bind_port):

response = sock.recv(4096)
data = response.decode()
data = data.split(" ", 1)
result = bc.decode(data[1])
logging.debug("Received message: %s", str(result))
if os.getenv('RTPE_OPERATOR'):
data = data.split(" ", 1)
result = bc.decode(data[1])
else:
result = bc.decode(data)

sock.close()
logging.debug("Socket closed.")
Expand Down
8 changes: 4 additions & 4 deletions config/sample-config.conf
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
port=22222
port=2000
addr=192.168.49.2

# sidecar_port=22222
# sidecar_tpye=envoy
sidecar_type=l7mp

# offer=path to offer json
# answer=path to answer json
Expand All @@ -12,7 +12,7 @@ addr=192.168.49.2
# file=path to file json
audio_file=/home/richard/Desktop/Ericsson/test-rtpengine/python/recording1h.wav
# rtpsend=/home/richard/Desktop/Ericsson/audio.rtp
generate_calls=1
generate_calls=100
without_jsonsocket=yes

sdpaddr=192.168.49.1
Expand All @@ -29,7 +29,7 @@ sdpaddr=192.168.49.1
# statistics=yes

# You can specify these with inline json or from a json file.
# delete={"call-id": "1-2", "from-tag": "tag", "to-tag": "tag2", "via-branch": "branch"}
# delete={"call-id": "3002-3004", "from-tag": "from-tag3002"}
# start_recording=
# stop_recording=
# block_dtmf=
Expand Down
2 changes: 1 addition & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export PYTHONPATH="${PYTHONPATH}:/app"
if [[ -z "${RTPE_OPERATOR}" ]]; then
python3 app.py --config_file config/sample-config.conf
else
python3 rtpe_operator/op.py
python3 -u rtpe_operator/op.py
fi

exec "$@"
Loading

0 comments on commit c5afdee

Please sign in to comment.