Reporting test details for all tests
[samplevnf.git] / VNFs / DPPD-PROX / helper-scripts / demo-scripts / prox.py
1 #!/bin/env python2.7
2
3 ##
4 ## Copyright (c) 2010-2017 Intel Corporation
5 ##
6 ## Licensed under the Apache License, Version 2.0 (the "License");
7 ## you may not use this file except in compliance with the License.
8 ## You may obtain a copy of the License at
9 ##
10 ##     http://www.apache.org/licenses/LICENSE-2.0
11 ##
12 ## Unless required by applicable law or agreed to in writing, software
13 ## distributed under the License is distributed on an "AS IS" BASIS,
14 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 ## See the License for the specific language governing permissions and
16 ## limitations under the License.
17 ##
18
19 import socket
20
21 class prox:
22     def __init__(self, ip):
23         self._ip = ip;
24         self._dat = ""
25         sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
26         try:
27             sock.connect((self._ip, 8474))
28         except:
29             raise Exception("Failed to connect to PROX on " + self._ip + ":8474")
30         self._sock = sock;
31
32     def send(self, msg):
33         self._sock.sendall(msg + "\n");
34         return self
35     def recv(self):
36         ret_str = "";
37         done = 0;
38         while done == 0:
39             if (len(self._dat) == 0):
40                 self._dat = self._sock.recv(256);
41
42             while(len(self._dat)):
43                 if (self._dat[0] == '\n'):
44                     done = 1
45                     self._dat = self._dat[1:]
46                     break;
47                 else:
48                     ret_str += self._dat[0];
49                     self._dat = self._dat[1:]
50         return ret_str;
51
52     def wait_cmd_finished(self):
53         self.send("stats hz").recv();