* [spp] [PATCH 2/5] controller: change socket buffer length
2018-10-01 3:14 [spp] [PATCH 0/5] Change primary status command to be detailed ogawa.yasufumi
2018-10-01 3:14 ` [spp] [PATCH 1/5] shared: change socket buffer length ogawa.yasufumi
@ 2018-10-01 3:14 ` ogawa.yasufumi
2018-10-01 3:14 ` [spp] [PATCH 3/5] primary: change status command detailed ogawa.yasufumi
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: ogawa.yasufumi @ 2018-10-01 3:14 UTC (permalink / raw)
To: spp, ferruh.yigit; +Cc: Yasufumi Ogawa
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
Size of message via socket might exceed 1000 if network configuration is
complexed. This patch is for defining `spp_common.SOCK_BUF_SIZE` and its
size to 2048.
Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
src/controller/conn_thread.py | 10 ++++------
src/controller/spp.py | 2 +-
src/controller/spp_common.py | 3 +++
3 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/src/controller/conn_thread.py b/src/controller/conn_thread.py
index e524e84..8bddfc0 100644
--- a/src/controller/conn_thread.py
+++ b/src/controller/conn_thread.py
@@ -52,8 +52,7 @@ class ConnectionThread(threading.Thread):
# Receiving from secondary
try:
- # 1024 stands for bytes of data to be received
- data = self.conn.recv(1024)
+ data = self.conn.recv(spp_common.SOCK_BUF_SIZE)
if data:
msg = "%s" % data.decode('utf-8')
spp_common.SEC2MAIN[self.client_id].put(msg)
@@ -99,7 +98,7 @@ class AcceptThread(threading.Thread):
except KeyError:
return -1
- data = conn.recv(1024)
+ data = conn.recv(spp_common.SOCK_BUF_SIZE)
if data is None:
return -1
@@ -140,7 +139,7 @@ class AcceptThread(threading.Thread):
msg = "_set_client_id %u" % free_client_id
conn.send(msg.encode('utf-8'))
- data = conn.recv(1024)
+ data = conn.recv(spp_common.SOCK_BUF_SIZE)
return free_client_id
@@ -236,8 +235,7 @@ class PrimaryThread(threading.Thread):
# Receiving from primary
try:
- # 1024 stands for bytes of data to be received
- data = conn.recv(1024)
+ data = conn.recv(spp_common.SOCK_BUF_SIZE)
if data:
spp_common.PRIMARY2MAIN.put(
"recv:%s:{%s}" % (str(addr), data.decode('utf-8')))
diff --git a/src/controller/spp.py b/src/controller/spp.py
index 57604de..80b1fab 100644
--- a/src/controller/spp.py
+++ b/src/controller/spp.py
@@ -24,7 +24,7 @@ class CmdRequestHandler(socketserver.BaseRequestHandler):
CMD = None # contains a instance of Shell class
def handle(self):
- self.data = self.request.recv(1024).strip()
+ self.data = self.request.recv(spp_common.SOCK_BUF_SIZE).strip()
cur_thread = threading.currentThread()
print(cur_thread.getName())
print(self.client_address[0])
diff --git a/src/controller/spp_common.py b/src/controller/spp_common.py
index 80fab76..0cac2d9 100644
--- a/src/controller/spp_common.py
+++ b/src/controller/spp_common.py
@@ -30,6 +30,9 @@ PRIMARY2MAIN = Queue()
# Maximum num of sock queues for secondaries
MAX_SECONDARY = 16
+# Should be as same as MSG_SIZE in src/shared/common.h
+SOCK_BUF_SIZE = 2048
+
PRIMARY = ''
SECONDARY_COUNT = 0
--
2.7.4
^ permalink raw reply [flat|nested] 6+ messages in thread
* [spp] [PATCH 3/5] primary: change status command detailed
2018-10-01 3:14 [spp] [PATCH 0/5] Change primary status command to be detailed ogawa.yasufumi
2018-10-01 3:14 ` [spp] [PATCH 1/5] shared: change socket buffer length ogawa.yasufumi
2018-10-01 3:14 ` [spp] [PATCH 2/5] controller: " ogawa.yasufumi
@ 2018-10-01 3:14 ` ogawa.yasufumi
2018-10-01 3:14 ` [spp] [PATCH 4/5] controller: change msg format in ConnectionThread ogawa.yasufumi
2018-10-01 3:14 ` [spp] [PATCH 5/5] controller: simply print primary status ogawa.yasufumi
4 siblings, 0 replies; 6+ messages in thread
From: ogawa.yasufumi @ 2018-10-01 3:14 UTC (permalink / raw)
To: spp, ferruh.yigit; +Cc: Yasufumi Ogawa
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
Status command of primary simply returns 'running' or 'idling'. This
update is to change to stats of each fo ports as json instead of running
status. Here is an example.
{
"phy_ports": [
{
"eth": "56:48:4f:12:34:00",
"id": 0,
"rx": 78932932,
"tx": 78932931,
"tx_drop": 1,
}
...
],
"ring_ports": [
{
"id": 0,
"rx": 89283,
"rx_drop": 0,
"tx": 89283,
"tx_drop": 0
},
...
]
}
Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
src/primary/main.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 77 insertions(+), 4 deletions(-)
diff --git a/src/primary/main.c b/src/primary/main.c
index 7ad8f54..7d5e0a2 100644
--- a/src/primary/main.c
+++ b/src/primary/main.c
@@ -152,6 +152,81 @@ do_send(int *connected, int *sock, char *str)
return 0;
}
+/**
+ * Retrieve all of statu of ports as JSON format managed by primary.
+ *
+ * Here is an exmaple.
+ *
+ * {
+ * "ring_ports": [
+ * {
+ * "id": 0,
+ * "rx": 0,
+ * "rx_drop": 0,
+ * "tx": 0,
+ * "tx_drop": 0
+ * },
+ * ...
+ * ],
+ * "phy_ports": [
+ * {
+ * "eth": "56:48:4f:53:54:00",
+ * "id": 0,
+ * "rx": 0,
+ * "tx": 0,
+ * "tx_drop": 0
+ * },
+ * ...
+ * ]
+ * }
+ */
+static int
+get_status_json(char *str)
+{
+ int i;
+ char phy_ports[512];
+ char ring_ports[1024];
+ memset(phy_ports, '\0', 512);
+ memset(ring_ports, '\0', 1024);
+
+ for (i = 0; i < ports->num_ports; i++) {
+ sprintf(phy_ports, "%s{\"id\": %u, \"eth\": \"%s\", "
+ "\"rx\": %"PRIu64", \"tx\": %"PRIu64", "
+ "\"tx_drop\": %"PRIu64"}",
+ phy_ports,
+ ports->id[i],
+ get_printable_mac_addr(ports->id[i]),
+ ports->port_stats[i].rx,
+ ports->port_stats[i].tx,
+ ports->client_stats[i].tx_drop);
+
+ if (i < ports->num_ports - 1)
+ sprintf(phy_ports, "%s,", phy_ports);
+ }
+
+ for (i = 0; i < num_clients; i++) {
+ sprintf(ring_ports, "%s{\"id\": %u, \"rx\": %"PRIu64", "
+ "\"rx_drop\": %"PRIu64", "
+ "\"tx\": %"PRIu64", \"tx_drop\": %"PRIu64"}",
+ ring_ports,
+ i,
+ ports->client_stats[i].rx,
+ ports->client_stats[i].rx_drop,
+ ports->client_stats[i].tx,
+ ports->client_stats[i].tx_drop);
+
+ if (i < num_clients - 1)
+ sprintf(ring_ports, "%s,", ring_ports);
+ }
+
+ RTE_LOG(DEBUG, APP, "{\"phy_ports\": [%s], \"ring_ports\": [%s]}",
+ phy_ports, ring_ports);
+ sprintf(str, "{\"phy_ports\": [%s], \"ring_ports\": [%s]}",
+ phy_ports, ring_ports);
+
+ return 0;
+}
+
static int
parse_command(char *str)
{
@@ -171,10 +246,7 @@ parse_command(char *str)
RTE_LOG(DEBUG, APP, "status\n");
memset(str, '\0', MSG_SIZE);
- if (cmd == START)
- sprintf(str, "Server Running\n");
- else
- sprintf(str, "Server Idling\n");
+ ret = get_status_json(str);
} else if (!strcmp(token_list[0], "exit")) {
RTE_LOG(DEBUG, APP, "exit\n");
@@ -183,6 +255,7 @@ parse_command(char *str)
ret = -1;
} else if (!strcmp(token_list[0], "clear")) {
+ sprintf(str, "{\"status\": \"cleared\"}");
clear_stats();
}
--
2.7.4
^ permalink raw reply [flat|nested] 6+ messages in thread
* [spp] [PATCH 5/5] controller: simply print primary status
2018-10-01 3:14 [spp] [PATCH 0/5] Change primary status command to be detailed ogawa.yasufumi
` (3 preceding siblings ...)
2018-10-01 3:14 ` [spp] [PATCH 4/5] controller: change msg format in ConnectionThread ogawa.yasufumi
@ 2018-10-01 3:14 ` ogawa.yasufumi
4 siblings, 0 replies; 6+ messages in thread
From: ogawa.yasufumi @ 2018-10-01 3:14 UTC (permalink / raw)
To: spp, ferruh.yigit; +Cc: Yasufumi Ogawa
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
Change printing primary status of law JSON format to be more intuitive.
Here is an example.
Physical Ports:
ID rx tx tx_drop mac_addr
0 78932932 78932931 1 56:48:4f:53:54:00
Ring Ports:
ID rx tx rx_drop rx_drop
0 89283 89283 0 0
...
Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
src/controller/shell.py | 61 ++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 60 insertions(+), 1 deletion(-)
diff --git a/src/controller/shell.py b/src/controller/shell.py
index 3497073..fb30d5d 100644
--- a/src/controller/shell.py
+++ b/src/controller/shell.py
@@ -95,6 +95,62 @@ class Shell(cmd.Cmd, object):
for i in spp_common.SECONDARY_LIST:
print("Connected secondary id: %d" % i)
+ def print_pri_status(self, json_obj):
+ """Parse SPP primary's status and print.
+
+ Primary returns the status as JSON format, but it is just a little
+ long.
+
+ {
+ "phy_ports": [
+ {
+ "eth": "56:48:4f:12:34:00",
+ "id": 0,
+ "rx": 78932932,
+ "tx": 78932931,
+ "tx_drop": 1,
+ }
+ ...
+ ],
+ "ring_ports": [
+ {
+ "id": 0,
+ "rx": 89283,
+ "rx_drop": 0,
+ "tx": 89283,
+ "tx_drop": 0
+ },
+ ...
+ ]
+ }
+
+ It is formatted to be simple and more understandable.
+
+ Physical Ports:
+ ID rx tx tx_drop mac_addr
+ 0 78932932 78932931 1 56:48:4f:53:54:00
+ Ring Ports:
+ ID rx tx rx_drop rx_drop
+ 0 89283 89283 0 0
+ ...
+ """
+
+ if json_obj.has_key('phy_ports'):
+ print('Physical Ports:')
+ print(' ID rx tx tx_drop mac_addr')
+ for pports in json_obj['phy_ports']:
+ print(' %2d %10d %10d %10d %s' % (
+ pports['id'], pports['rx'], pports['tx'],
+ pports['tx_drop'], pports['eth']))
+
+ if json_obj.has_key('ring_ports'):
+ print('Ring Ports:')
+ print(' ID rx tx rx_drop rx_drop')
+ for rports in json_obj['ring_ports']:
+ print(' %2d %10d %10d %10d %10d' % (
+ rports['id'], rports['rx'], rports['tx'],
+ rports['rx_drop'], rports['tx_drop']))
+
def print_sec_status(self, msg):
"""Parse and print message from SPP secondary
@@ -144,7 +200,8 @@ class Shell(cmd.Cmd, object):
if spp_common.PRIMARY:
spp_common.MAIN2PRIMARY.put(command.encode('utf-8'))
recv = spp_common.PRIMARY2MAIN.get(True)
- print(recv)
+ json_obj = json.loads(recv)
+ self.print_pri_status(json_obj)
return self.CMD_OK, recv
else:
recv = "primary not started"
@@ -508,7 +565,9 @@ class Shell(cmd.Cmd, object):
if cmds[0] == 'sec':
self.close_all_secondary()
elif cmds[0] == 'all':
+ print('Closing secondary ...')
self.close_all_secondary()
+ print('Closing primary ...')
self.command_primary('exit')
elif cmds[0] == '':
print('Thank you for using Soft Patch Panel')
--
2.7.4
^ permalink raw reply [flat|nested] 6+ messages in thread