blob: 3d68ff78aaae4bde6ccaf7016376f6d674d009f0 [file] [log] [blame]
Dimitrios Mavrommatis0774a592017-12-21 14:57:52 -08001#!/usr/bin/python
2#coding: utf8
3#Copyright © 2016 - 2017 Copyright (c) Sprint, Inc. and others. All rights
4#reserved.
5#
6#This program and the accompanying materials are made available under the
7#terms of the Eclipse Public License v1.0 which accompanies this distribution,
8#and is available at http://www.eclipse.org/legal/epl-v10.html
9#
10############################################################################
11# File : rules_test.py
12#
13# Comments :
14# Establish the channel with DP (Script(PUB) -> Forwarder -> DP(SUB)),
15# And listen and push the message over socket.
16############################################################################
17
18import signal
19import sys
20import zmq
21import struct
22import socket as socketlib
23import datetime
24import time
25
26from adc_rules import *
27from pcc_rules import *
28from mtr_rules import *
29from sdf_rules import *
30
31conflict = False
32topicId = None
33
34# TBD: Needs to handle exception
35# TBD: Needs to handle keyboard intrrupts
36
37#ZMQ ports
slowrdd7e81b2018-01-05 05:58:41 -050038rec_port = "5566"
Dimitrios Mavrommatis0774a592017-12-21 14:57:52 -080039send_port = "5555"
40# Socket to talk to server
41context = zmq.Context()
42socket = context.socket(zmq.SUB)
43pub_socket = context.socket(zmq.PUB)
44# As of not test script runs from FPC-SDN only
45socket.connect ("tcp://192.168.105.14:%s" % rec_port)
46pub_socket.connect("tcp://192.168.105.14:%s" % send_port)
47topicfilter = ""
48controller_topic= 252
49socket.setsockopt(zmq.SUBSCRIBE, topicfilter)
50print "Listening to port ", rec_port
51print "Publisher on port ", send_port
52print "Ready to receive messages. Press Ctrl+C when ready to exit."
53
54for update_nbr in range(900000):
55 # TBD: Needs to handle exception
56 string = socket.recv()
57 ts = time.time()
58 st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
59
60 topic, msgnum, ID = struct.unpack('!BBB', string[:3])
61 print"\n topic,msg,ID:%s,%s,%s" % (topic, msgnum, ID)
62
63 #Listen to topic
64 if topic == 1 and msgnum == 10:#Assign_Id
65 top, msg, topId = struct.unpack('!BBB', string[:3])
66 print "\n topId :", topId
67 topicId = topId
68
69 #Listen to ack
70 if topic == 2 and msgnum == 12:
71 top, msg, topId_t = struct.unpack('!BBB', string[:3])
72
73 if topicId == topId_t:
74 # TBD: Needs to handle exception
75
76 parse_adc_values(pub_socket, topicId)
77 time.sleep(1)
78 parse_mtr_values(pub_socket, topicId)
79 time.sleep(1)
80 parse_pcc_values(pub_socket, topicId)
81 time.sleep(1)
82 parse_sdf_values(pub_socket, topicId)
83 time.sleep(1)
84 socket.close()
85 pub_socket.close()
86 sys.exit(0)
87