Merge branch 'master' of https://github.com/OPENNETWORKINGLAB/ONLabTest
diff --git a/TestON/drivers/common/cli/emulator/mininetclidriver.py b/TestON/drivers/common/cli/emulator/mininetclidriver.py
index 47cb129..a003f1b 100644
--- a/TestON/drivers/common/cli/emulator/mininetclidriver.py
+++ b/TestON/drivers/common/cli/emulator/mininetclidriver.py
@@ -908,6 +908,27 @@
return results
+ def links_status(self):
+ """
+ Returns list of links and their status
+ """
+ if self.handle :
+ cmd = "py 'Links: %s' % [item for sublist in [[(y[0].name, y[1].name, y[0].isUp() and y[1].isUp()) for y in x[0].connectionsTo(x[1])] for x in __import__('itertools').permutations(net.nameToNode.values(), 2) if x[0] != x[1] and x[0].connectionsTo(x[1])] for item in sublist]"
+ try:
+ response = self.execute(cmd=cmd,prompt="mininet>",timeout=10)
+ if not response:
+ return None
+ for line in response.split('\n'):
+ if line.startswith('Links:'):
+ return eval(line[len("Links :"):])
+ except pexpect.EOF:
+ main.log.error(self.name + ": EOF exception found")
+ main.log.error(self.name + ": " + self.handle.before)
+ main.cleanup()
+ main.exit()
+ return response
+ else:
+ main.log.error("Connection failed to the node")
diff --git a/TestON/drivers/common/cli/onosclidriver.py b/TestON/drivers/common/cli/onosclidriver.py
index 40c07db..52b39a1 100644
--- a/TestON/drivers/common/cli/onosclidriver.py
+++ b/TestON/drivers/common/cli/onosclidriver.py
@@ -1581,3 +1581,84 @@
main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
main.cleanup()
main.exit()
+
+
+ def block_peer(self, ip_address):
+ '''
+ Block traffic to the destination IP address.
+ '''
+ try:
+ for chain in ['INPUT', 'OUTPUT']:
+ check_block_cmd = "sudo iptables -L %s -n | grep \"DROP.*%s\"" % (chain, ip_address)
+ add_block_cmd = "sudo iptables -I %s 1 -s %s -j DROP" % (chain, ip_address)
+ response1 = self.execute(cmd=check_block_cmd,prompt="\$",timeout=10)
+ if ip_address in response1:
+ main.log.error("Already blocked: %s" % response1)
+ return main.TRUE
+ response2 = self.execute(cmd=add_block_cmd,prompt="\$",timeout=10)
+ main.log.info("add_block_cmd: %s" % response2)
+ return main.TRUE
+ except pexpect.EOF:
+ main.log.error(self.name + ": EOF exception found")
+ main.log.error(self.name + ": " + self.handle.before)
+ main.cleanup()
+ main.exit()
+ except:
+ main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
+ main.log.error( traceback.print_exc() )
+ main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
+ main.cleanup()
+ main.exit()
+
+ def unblock_peer(self, ip_address):
+ '''
+ Unblock traffic to the destination IP address.
+ '''
+ try:
+ for chain in ['INPUT', 'OUTPUT']:
+ # To make sure all rules are deleted in case there were multiple
+ # installed in the iptables
+ max_iterations = 10
+ for i in range(max_iterations):
+ check_block_cmd = "sudo iptables -L %s -n | grep \"DROP.*%s\"" % (chain, ip_address)
+ remove_block_cmd = "sudo iptables -D %s -s %s -j DROP" % (chain, ip_address)
+ response1 = self.execute(cmd=check_block_cmd,prompt="\$",timeout=10)
+ if ip_address not in response1:
+ main.log.warn("Already unblocked: %s" % response1)
+ return main.TRUE
+ response2 = self.execute(cmd=remove_block_cmd,prompt="\$",timeout=10)
+ main.log.info("remove_block_cmd: %s" % response2)
+ return main.TRUE
+ except pexpect.EOF:
+ main.log.error(self.name + ": EOF exception found")
+ main.log.error(self.name + ": " + self.handle.before)
+ main.cleanup()
+ main.exit()
+ except:
+ main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
+ main.log.error( traceback.print_exc() )
+ main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
+ main.cleanup()
+ main.exit()
+
+
+ def unblock_all(self):
+ '''
+ Remove all controller block rules
+ '''
+ try:
+ unblock_cmd = "sudo iptables --flush"
+ response = self.execute(cmd=unblock_cmd,prompt="\$", timeout=10)
+ return main.TRUE
+ except pexpect.EOF:
+ main.log.error(self.name + ": EOF exception found")
+ main.log.error(self.name + ": " + self.handle.before)
+ main.cleanup()
+ main.exit()
+ except:
+ main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
+ main.log.error( traceback.print_exc() )
+ main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
+ main.cleanup()
+ main.exit()
+ return main.ERROR