Loading src/tests/ryu-openflow/mininet/custom_pentagon_topology.py +53 −8 Original line number Diff line number Diff line Loading @@ -13,7 +13,7 @@ # limitations under the License. import json, re, socketserver, threading, time import json, logging, re, socketserver, threading, time from http.server import BaseHTTPRequestHandler, HTTPServer from urllib.parse import parse_qs, urlparse from mininet.topo import Topo Loading @@ -22,6 +22,9 @@ from mininet.node import RemoteController #from mininet.cli import CLI from mininet.link import TCLink logging.basicConfig(level=logging.INFO) LOGGER = logging.getLogger(__name__) class PentagonTopo(Topo): def build(self): sw1 = self.addSwitch('s1') Loading Loading @@ -53,8 +56,8 @@ def parse_ping_output(output: str): return 0, 0, 0.0 transmitted = int(match.group(1)) received = int(match.group(2)) ratio = (received / transmitted) if transmitted else 0.0 return transmitted, received, ratio success_ratio = (received / transmitted) if transmitted else 0.0 return transmitted, received, success_ratio def build_ping_handler(net: Mininet): Loading @@ -81,32 +84,74 @@ def build_ping_handler(net: Mininet): return params = parse_qs(parsed.query) LOGGER.warning('params={:s}'.format(str(params))) source = params.get('source', [None])[0] target = params.get('target', [None])[0] count_val = params.get('count', ['3'])[0] LOGGER.warning('source={:s}'.format(str(source))) LOGGER.warning('target={:s}'.format(str(target))) LOGGER.warning('count_val={:s}'.format(str(count_val))) if not source or not target: self._send_json(400, {'error': 'source and target query parameters are required'}) self._send_json(400, { 'error': 'source and target query parameters are required', 'params': str(params), 'source': str(source), 'target': str(target), 'count_val': str(count_val), }) return count = None try: count = int(count_val) if count <= 0: raise ValueError() except ValueError: self._send_json(400, {'error': 'count must be a positive integer'}) self._send_json(400, { 'error': 'count must be a positive integer', 'params': str(params), 'source': str(source), 'target': str(target), 'count_val': str(count_val), 'count': str(count), }) return LOGGER.warning('count={:s}'.format(str(count))) src_host = None dst_host = None try: src_host = net.get(source) dst_host = net.get(target) except KeyError as exc: self._send_json(404, {'error': f'Unknown host: {exc}'}) self._send_json(404, { 'error': f'Unknown host: {exc}', 'params': str(params), 'source': str(source), 'target': str(target), 'count_val': str(count_val), 'count': str(count), 'src_host': str(src_host), 'dst_host': str(dst_host), }) return LOGGER.warning('src_host={:s}'.format(str(src_host))) LOGGER.warning('dst_host={:s}'.format(str(dst_host))) destination_ip = dst_host.IP() LOGGER.warning('destination_ip={:s}'.format(str(destination_ip))) output = src_host.cmd(f'ping -c {count} {destination_ip}') transmitted, received, ratio = parse_ping_output(output) LOGGER.warning('output={:s}'.format(str(output))) transmitted, received, success_ratio = parse_ping_output(output) LOGGER.warning('transmitted={:s}'.format(str(transmitted))) LOGGER.warning('received={:s}'.format(str(received))) LOGGER.warning('success_ratio={:s}'.format(str(success_ratio))) self._send_json(200, { 'source': source, Loading @@ -115,7 +160,7 @@ def build_ping_handler(net: Mininet): 'count': count, 'packets_transmitted': transmitted, 'packets_received': received, 'success_ratio': ratio, 'success_ratio': success_ratio, 'raw_output': output }) Loading Loading
src/tests/ryu-openflow/mininet/custom_pentagon_topology.py +53 −8 Original line number Diff line number Diff line Loading @@ -13,7 +13,7 @@ # limitations under the License. import json, re, socketserver, threading, time import json, logging, re, socketserver, threading, time from http.server import BaseHTTPRequestHandler, HTTPServer from urllib.parse import parse_qs, urlparse from mininet.topo import Topo Loading @@ -22,6 +22,9 @@ from mininet.node import RemoteController #from mininet.cli import CLI from mininet.link import TCLink logging.basicConfig(level=logging.INFO) LOGGER = logging.getLogger(__name__) class PentagonTopo(Topo): def build(self): sw1 = self.addSwitch('s1') Loading Loading @@ -53,8 +56,8 @@ def parse_ping_output(output: str): return 0, 0, 0.0 transmitted = int(match.group(1)) received = int(match.group(2)) ratio = (received / transmitted) if transmitted else 0.0 return transmitted, received, ratio success_ratio = (received / transmitted) if transmitted else 0.0 return transmitted, received, success_ratio def build_ping_handler(net: Mininet): Loading @@ -81,32 +84,74 @@ def build_ping_handler(net: Mininet): return params = parse_qs(parsed.query) LOGGER.warning('params={:s}'.format(str(params))) source = params.get('source', [None])[0] target = params.get('target', [None])[0] count_val = params.get('count', ['3'])[0] LOGGER.warning('source={:s}'.format(str(source))) LOGGER.warning('target={:s}'.format(str(target))) LOGGER.warning('count_val={:s}'.format(str(count_val))) if not source or not target: self._send_json(400, {'error': 'source and target query parameters are required'}) self._send_json(400, { 'error': 'source and target query parameters are required', 'params': str(params), 'source': str(source), 'target': str(target), 'count_val': str(count_val), }) return count = None try: count = int(count_val) if count <= 0: raise ValueError() except ValueError: self._send_json(400, {'error': 'count must be a positive integer'}) self._send_json(400, { 'error': 'count must be a positive integer', 'params': str(params), 'source': str(source), 'target': str(target), 'count_val': str(count_val), 'count': str(count), }) return LOGGER.warning('count={:s}'.format(str(count))) src_host = None dst_host = None try: src_host = net.get(source) dst_host = net.get(target) except KeyError as exc: self._send_json(404, {'error': f'Unknown host: {exc}'}) self._send_json(404, { 'error': f'Unknown host: {exc}', 'params': str(params), 'source': str(source), 'target': str(target), 'count_val': str(count_val), 'count': str(count), 'src_host': str(src_host), 'dst_host': str(dst_host), }) return LOGGER.warning('src_host={:s}'.format(str(src_host))) LOGGER.warning('dst_host={:s}'.format(str(dst_host))) destination_ip = dst_host.IP() LOGGER.warning('destination_ip={:s}'.format(str(destination_ip))) output = src_host.cmd(f'ping -c {count} {destination_ip}') transmitted, received, ratio = parse_ping_output(output) LOGGER.warning('output={:s}'.format(str(output))) transmitted, received, success_ratio = parse_ping_output(output) LOGGER.warning('transmitted={:s}'.format(str(transmitted))) LOGGER.warning('received={:s}'.format(str(received))) LOGGER.warning('success_ratio={:s}'.format(str(success_ratio))) self._send_json(200, { 'source': source, Loading @@ -115,7 +160,7 @@ def build_ping_handler(net: Mininet): 'count': count, 'packets_transmitted': transmitted, 'packets_received': received, 'success_ratio': ratio, 'success_ratio': success_ratio, 'raw_output': output }) Loading