Commit ca26ca39 authored by Pedro Oliveira's avatar Pedro Oliveira

Clone repository when running start script; use cloned repository instead of...

Clone repository when running start script; use cloned repository instead of copying from Desktop folder of host PC
parent 8c035030
rm -rf MulticastRouting/
cp -rf /hosthome/Desktop/pim/ MulticastRouting/
cd MulticastRouting
cd pim_dm
python3 Run.py -stop
python3 Run.py -start
......
rm -rf MulticastRouting/
cp -rf /hosthome/Desktop/pim/ MulticastRouting/
cd MulticastRouting
cd pim_dm
python3 Run.py -stop
python3 Run.py -start
......
rm -rf MulticastRouting/
cp -rf /hosthome/Desktop/pim/ MulticastRouting/
cd MulticastRouting
cd pim_dm
python3 Run.py -stop
python3 Run.py -start
......
rm -rf MulticastRouting/
cp -rf /hosthome/Desktop/pim/ MulticastRouting/
cd MulticastRouting
cd pim_dm
python3 Run.py -stop
......
......@@ -3,8 +3,7 @@ import logging
import logging.handlers
import socketserver
import struct
import sys
import threading
from TestHello import CustomFilter, Test1, Test2, Test3
from queue import Queue
q = Queue()
......@@ -21,12 +20,20 @@ def worker():
class TestHandler(logging.StreamHandler):
currentTest = Test1()
currentTest.print_test()
nextTests = [Test2(), Test3()]
main = None
def emit(self, record):
super().emit(record)
class CustomFilter(logging.Filter):
def filter(self, record):
return record.name in ("pim.Interface.Neighbor", 'pim.Interface') and record.routername in ["R1", "R2"]
if TestHandler.currentTest and TestHandler.currentTest.test(record):
if len(TestHandler.nextTests) > 0:
TestHandler.currentTest = TestHandler.nextTests.pop(0)
TestHandler.currentTest.print_test()
else:
TestHandler.currentTest = None
TestHandler.main.abort = True
class LogRecordStreamHandler(socketserver.StreamRequestHandler):
......@@ -72,7 +79,6 @@ class LogRecordSocketReceiver(socketserver.ThreadingTCPServer):
socketserver.ThreadingTCPServer.__init__(self, (host, port), handler)
self.abort = 0
self.timeout = 1
self.logname = None
def serve_until_stopped(self):
import select
......@@ -87,12 +93,14 @@ class LogRecordSocketReceiver(socketserver.ThreadingTCPServer):
def main():
import sys
handler = TestHandler(sys.stdout)
formatter = logging.Formatter('%(name)-35s %(levelname)-8s %(asctime)-25s %(vif)-2s %(interfacename)-5s %(routername)-2s %(message)s')
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()
......
import logging
from abc import ABCMeta, abstractmethod
class CustomFilter(logging.Filter):
def filter(self, record):
return record.name in ("pim.Interface.Neighbor", "pim.KernelInterface") and \
record.routername in ["R1", "R2", "R3", "R4"]
class AddTest(object):
__metaclass__ = ABCMeta
def __init__(self, testName, expectedState, success):
self.testName = testName
self.expectedState = expectedState
self.success = success
def test(self, record):
if not record.msg.startswith('Monitoring new neighbor') or record.routername not in self.expectedState:
return False
if record.neighbor_ip in self.expectedState.get(record.routername).get(record.interfacename):
self.success[record.routername][record.interfacename][self.expectedState.get(record.routername).get(record.interfacename).index(record.neighbor_ip)] = True
for interface_test in self.success.values():
for list_success in interface_test.values():
if False in list_success:
return False
print('\x1b[1;32;40m' + self.testName + ' Success' + '\x1b[0m')
return True
@abstractmethod
def print_test(self):
pass
class RemoveTest(object):
__metaclass__ = ABCMeta
def __init__(self, testName, expectedState, success):
self.testName = testName
self.expectedState = expectedState
self.success = success
def test(self, record):
if not (record.msg.startswith('Detected neighbor removal') or record.msg.startswith('Neighbor Liveness Timer expired')) or record.routername not in self.expectedState:
return False
if record.neighbor_ip in self.expectedState.get(record.routername).get(record.interfacename):
self.success[record.routername][record.interfacename][self.expectedState.get(record.routername).get(record.interfacename).index(record.neighbor_ip)] = True
for interface_test in self.success.values():
for list_success in interface_test.values():
if False in list_success:
return False
print('\x1b[1;32;40m' + self.testName + ' Success' + '\x1b[0m')
return True
@abstractmethod
def print_test(self):
pass
class Test1(AddTest):
def __init__(self):
expectedState = {"R1": {"eth0": ["10.0.0.2", "10.0.0.3", "10.0.0.4"]},
"R2": {"eth0": ["10.0.0.1", "10.0.0.3", "10.0.0.4"]},
"R3": {"eth0": ["10.0.0.1", "10.0.0.2", "10.0.0.4"]},
"R4": {"eth0": ["10.0.0.2", "10.0.0.3", "10.0.0.1"]},
}
success = {"R1": {"eth0": [False, False, False]},
"R2": {"eth0": [False, False, False]},
"R3": {"eth0": [False, False, False]},
"R4": {"eth0": [False, False, False]},
}
super().__init__("Test1", expectedState, success)
def print_test(self):
print("Test1: Enable all routers")
print("All routers should establish neighborhood relationships")
class Test2(RemoveTest):
def __init__(self):
expectedState = {"R1": {"eth0": ["10.0.0.3"]},
"R2": {"eth0": ["10.0.0.3"]},
"R4": {"eth0": ["10.0.0.3"]},
}
success = {"R1": {"eth0": [False]},
"R2": {"eth0": [False]},
"R4": {"eth0": [False]},
}
super().__init__("Test2", expectedState, success)
def print_test(self):
print("Test2: Disable Router3 interface (-ri eth0) and check if others router react to R3 HelloHoldTime=0")
class Test3(RemoveTest):
def __init__(self):
expectedState = {"R1": {"eth0": ["10.0.0.4"]},
"R2": {"eth0": ["10.0.0.4"]},
}
success = {"R1": {"eth0": [False]},
"R2": {"eth0": [False]},
}
super().__init__("Test3", expectedState, success)
def print_test(self):
print("Test3: KILL router4 (-stop) to not send Hello with HelloHoldTime set to 0 and check if others remove that router after timeout")
class Test4(AddTest):
def __init__(self):
expectedState = {"R1": {"eth0": ["10.0.0.4"]},
"R2": {"eth0": ["10.0.0.4"]},
"R4": {"eth0": ["10.0.0.2", "10.0.0.1"]},
}
success = {"R1": {"eth0": [False]},
"R2": {"eth0": [False]},
"R4": {"eth0": [False, False]},
}
super().__init__("Test4", expectedState, success)
def print_test(self):
print("Test4: Reenable router4")
rm -rf test/
cp -rf /hosthome/PycharmProjects/RPC/ test/
cd test
pip-3.2 install --index-url=https://pypi.python.org/simple/ -r requirements.txt
python3 Client.py
python3 ServerLogHello.py
......@@ -10,6 +10,11 @@ if [ ! -d "netkit-ng" ]; then
tar -xjSf netkit-ng-kernel-i386-K3.2-0.1.3.tar.bz2
fi
if [ ! -d "emulation/shared/root/pim_dm" ]; then
# if project does not exist, clone it
git clone https://github.com/pedrofran12/pim_dm.git emulation/shared/root/pim_dm
fi
export NETKIT_HOME=$(pwd)/netkit-ng
export MANPATH=:$NETKIT_HOME/man
export PATH=$NETKIT_HOME/bin:$PATH
......@@ -22,10 +27,7 @@ if echo $OUTPUT | grep -q "failed"; then
exit
fi
cd ../emulation/
lstart -p
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