Commit 6a618729 authored by Pedro Oliveira's avatar Pedro Oliveira

Test Join/Prune/Graft

parent 39f0760e
......@@ -3,9 +3,7 @@ import logging
import logging.handlers
import socketserver
import struct
from TestAssert import CustomFilter, Test1, Test2, Test3
import sys
import threading
from TestJoinPrune import CustomFilter, Test1, Test2, Test3, Test4, Test5
from queue import Queue
q = Queue()
......@@ -24,7 +22,7 @@ def worker():
class TestHandler(logging.StreamHandler):
currentTest = Test1()
currentTest.print_test()
nextTests = [Test2(), Test3()]
nextTests = [Test2(), Test3(), Test4(), Test5()]
main = None
def emit(self, record):
......@@ -37,6 +35,7 @@ class TestHandler(logging.StreamHandler):
TestHandler.currentTest = None
TestHandler.main.abort = True
class LogRecordStreamHandler(socketserver.StreamRequestHandler):
"""Handler for a streaming logging request.
......@@ -76,11 +75,10 @@ class LogRecordSocketReceiver(socketserver.ThreadingTCPServer):
def __init__(self, host='localhost',
port=logging.handlers.DEFAULT_TCP_LOGGING_PORT,
handler=LogRecordStreamHandler):
handler.main = self
TestHandler.main = self
socketserver.ThreadingTCPServer.__init__(self, (host, port), handler)
self.abort = 0
self.timeout = 1
self.logname = None
def serve_until_stopped(self):
import select
......@@ -95,12 +93,14 @@ class LogRecordSocketReceiver(socketserver.ThreadingTCPServer):
def main():
import sys
handler = TestHandler(sys.stdout)
formatter = logging.Formatter('%(name)-50s %(levelname)-8s %(tree)-35s %(vif)-2s %(interfacename)-5s %(routername)-2s %(message)s')
handler.setFormatter(formatter)
logging.getLogger('my_logger').addHandler(handler)
logging.getLogger('my_logger').addFilter(CustomFilter())
import threading
t = threading.Thread(target=worker)
t.start()
......
......@@ -3,8 +3,8 @@ from abc import ABCMeta
class CustomFilter(logging.Filter):
def filter(self, record):
return record.name in ("pim.KernelEntry.DownstreamInterface.Assert", "pim.KernelEntry.UpstreamInterface.Assert", "pim.KernelInterface") and \
record.routername in ["R1", "R2", "R3", "R4", "R5", "R6"]
return record.name in ("pim.KernelEntry.DownstreamInterface.JoinPrune", "pim.KernelEntry.UpstreamInterface.JoinPrune", "pim.KernelInterface") and \
record.routername in ["R1", "R2","R3","R4","R5","R6"]
class Test():
......@@ -23,6 +23,8 @@ class Test():
for interface_test in self.success.values():
if False in interface_test.values():
#print(self.expectedState)
#print(self.success)
return False
print('\x1b[1;32;40m' + self.testName + ' Success' + '\x1b[0m')
return True
......@@ -33,16 +35,20 @@ class Test():
class Test1(Test):
def __init__(self):
expectedState = {"R2": {"eth1": "L"},
"R3": {"eth1": "L"},
"R4": {"eth1": "W"},
"R5": {"eth0": "L"},
"R6": {"eth0": "L"},
expectedState = {"R1": {"eth0": "F", "eth1": "P", "eth2": "P", "eth3": "NI"}, # Only downstream interface connected to AssertWinner \
# in NI state and upstream interface connected to source\
# in Forward state
"R2": {"eth0": "P"}, # Assert Loser upstream interface in pruned state
"R3": {"eth0": "P"}, # Assert Loser upstream interface in pruned state
"R4": {"eth0": "F", "eth1": "NI"}, # Assert Winner upstream interface in forward state
"R5": {"eth0": "F"}, # Downstream router interested (client0)
"R6": {"eth0": "F"}, # Downstream router interested (client0)
}
success = {"R2": {"eth1": False},
"R3": {"eth1": False},
"R4": {"eth1": False},
success = {"R1": {"eth0": False, "eth1": False, "eth2": False, "eth3": False},
"R2": {"eth0": False},
"R3": {"eth0": False},
"R4": {"eth0": False, "eth1": False},
"R5": {"eth0": False},
"R6": {"eth0": False},
}
......@@ -50,44 +56,80 @@ class Test1(Test):
super().__init__("Test1", expectedState, success)
def print_test(self):
print("Test1: No info about (10.1.1.100,224.12.12.12)")
print("Expected: R4 WINNER")
print("Test1: Formation of (S,G) Broadcast Tree")
print("Having Client0 and Client1 interested")
class Test2(Test):
def __init__(self):
expectedState = {"R2": {"eth1": "L"},
"R3": {"eth1": "W"},
"R5": {"eth0": "L"},
"R6": {"eth0": "L"},
expectedState = {"R4": {"eth1": "PP"}, # Assert Winner upstream interface in PP because of Prune msg
"R6": {"eth0": "P"}, # Downstream router not interested
}
success = {"R2": {"eth1": False},
"R3": {"eth1": False},
"R5": {"eth0": False},
success = {"R4": {"eth1": False},
"R6": {"eth0": False},
}
super().__init__("Test2", expectedState, success)
def print_test(self):
print("Test2: Kill assert winner")
print("Expected: R3 WINNER")
print("Test2: Client1 not interested in receiving traffic destined to group G")
print("R6 sends a Prune and R5 overrides the prune")
class Test3(Test):
def __init__(self):
expectedState = {"R2": {"eth1": "NI"},
"R3": {"eth1": "NI"},
expectedState = {"R4": {"eth1": "NI"}, # Assert Winner upstream interface in PP because of Join msg
}
success = {"R2": {"eth1": False},
"R3": {"eth1": False},
success = {"R4": {"eth1": False},
}
super().__init__("Test3", expectedState, success)
def print_test(self):
print("Test3: CouldAssert of AssertWinner(R3) -> False")
print("Expected: everyone NI")
print("Test3: R5 overrides prune via Join")
print("R4 should transition to Forward state")
class Test4(Test):
def __init__(self):
expectedState = {"R1": {"eth3": "P"}, # Only interface eth3 changes to Pruned state... eth1 is directly connected so it should stay in a Forward state
#"R2": {"eth0": "P"}, #R2 already in a Pruned state
#"R3": {"eth0": "P"}, #R3 already in a Pruned state
"R4": {"eth0": "P", "eth1": "P"}, # Assert Winner upstream interface in forward state
"R5": {"eth0": "P"}, # Downstream router interested (client0)
#"R6": {"eth0": "P"}, # R6 already in a Pruned state
}
success = {"R1": {"eth3": False},
"R4": {"eth0": False, "eth1": False},
"R5": {"eth0": False},
}
super().__init__("Test4", expectedState, success)
def print_test(self):
print("Test4: No client interested")
print("Prune tree")
class Test5(Test):
def __init__(self):
expectedState = {"R1": {"eth3": "NI"}, # R4 grafted this interface
"R4": {"eth0": "F", "eth1": "NI"}, # R5 grafted this interface
"R5": {"eth0": "F"}, # client0 interested
}
success = {"R1": {"eth3": False},
"R4": {"eth0": False, "eth1": False},
"R5": {"eth0": False},
}
super().__init__("Test5", expectedState, success)
def print_test(self):
print("Test5: client0 interested in receiving traffic")
print("Graft tree")
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment