| #!/usr/bin/python |
| # Copyright 2012 Google Inc. All Rights Reserved. |
| |
| """This class implements some basic networking test cases. |
| |
| This class extends the TestCase Class. |
| This file implements some test cases to verify Bruno basic networking |
| features. In the following test cases, only those that are defined in |
| 'config.cfg' file will be executed. |
| |
| Feature test cases include the following: |
| testID: 11874111 7.2.12 IPv6 Duplicate Address Detection |
| testID: 11724363 7.2.16 Ethernet/Moca Traffic Overloading |
| testID: 11843145 7.2.17 VLAN Pass Through |
| testID: 11723379 7.2.18 VLAN Tagging over Home Owner WiFi |
| testID: 11722378 7.2.19 VLAN Tagging over Guest WiFi |
| testID: 11721378 7.2.2 Verify BRUNO (connected to BRUNO-IS) can obtain |
| IPv4 address via RG's DHCP service |
| testID: 11792173 7.2.20 VLAN Tag Removal |
| testID: 11721382 7.2.21 IPv6 Verify subnet with /56, /64 length |
| testID: 11843141 7.2.5 Verify client can get correct IPv4 address if |
| the RG changes DHCP address pool |
| testID: 11721379 7.2.7 Verify time offset information obtained via |
| DHCP option2 |
| """ |
| |
| __author__ = 'Lehan Meng (lmeng@google.com)' |
| |
| |
| import re |
| import time |
| |
| import device |
| import ip |
| import ssh |
| import testCase |
| |
| |
| class BasicNetworkingTest(testCase.TestCase): |
| """Class for test cases of Bruno networking features. |
| |
| Configuration Parameters: |
| testID: 11874111/11724363/11843145/11723379 |
| /11722378/11721378/11792173/11721382/ |
| /11843141/11721379 |
| addr = Bruno's IP address |
| user = root |
| pwd = google |
| bruno_prompt = gfibertv# |
| file = cmdOutput.txt |
| title = Basic_Networking |
| """ |
| |
| def Init(self): |
| """Initialize the networking feature tests.""" |
| # Get all device information. |
| info = self.log.CreateResultInfo( |
| '---', 'Networking test verification started...') |
| self.log.SendLine(self.test_info, info) |
| self.bruno = device.Bruno(user=self.params['user'], |
| addr=self.params['addr'], |
| bruno_prompt=self.params['bruno_prompt'], |
| addr_ipv6=self.params['addr_ipv6']) |
| self.bruno.SetLogging(self.log) |
| if not self.p_ssh: |
| self.p_ssh = ssh.SSH(user=self.params['user'], |
| addr=self.params['addr'], |
| bruno_prompt=self.params['bruno_prompt'], |
| addr_ipv6=self.params['addr_ipv6']) |
| self.bruno.dev_ssh = self.p_ssh |
| self.p_ssh.SetLogging(self.log) |
| return |
| |
| def SshTunnel(self): |
| """Create ssh tunnel for the test.""" |
| self.p_ssh.SshRetry(5, 15) |
| return |
| |
| def VerifyDuplicatedAddress(self, ip_addr): |
| """Verify device can detect duplicated ipv6 address existing in network. |
| |
| Set a duplicated ip address on the device. |
| Verify that the device can detect duplicated ip address |
| |
| Args: |
| ip_addr: the duplicated address |
| Returns: |
| True: if duplicated detected |
| False: if duplicated address is not detected |
| """ |
| time_stamp = self.bruno.GetTimeStamp() |
| self.bruno.dev_ssh.SendCmd('ip -6 addr add ' + ip_addr + '/64 dev br0') |
| time.sleep(1) |
| self.bruno.dev_ssh.SendCmd('dmesg | grep detected') |
| log_list = self.bruno.dev_ssh.GetCmdOutput() |
| |
| pattern_line = ('\[\s*\d*\.\d{3}\]\s*\w*\d:\s* IPv6 duplicate address\s*(' |
| + ip_addr + ')\s*[/\d+]*\s*detected!') |
| self.bruno.dev_ssh.SendCmd('ip -6 addr del ' + ip_addr + '/64 dev br0') |
| |
| if self.bruno.FindLineInLog(log_list, time_stamp, pattern_line): |
| info = self.log.CreateResultInfo('Pass', 'Duplicated IPv6 address ' |
| 'detected: ' + ip_addr) |
| self.log.SendLine(self.test_info, info) |
| else: |
| info = self.log.CreateResultInfo('Failed', |
| 'Duplicated IPv6 address not detected: ' |
| + ip_addr + '. Verification Failed!') |
| self.log.SendLine(self.test_info, info) |
| #[132344.324] br0: IPv6 duplicate address fe80:... detected! |
| |
| def GetIPv4Address(self): |
| """Test Bruno IP address. testID: 11874104.""" |
| # Use ifconfig to check interface IP address |
| self.p_ssh.SendCmd(r'ifconfig br0') |
| line = self.p_ssh.GetCmdOutput(3)[1] |
| |
| # Get Bruno IP address |
| address = ip.IPADDR(line).IsLikeIpv4Address() |
| if address is not None: |
| ip.IPADDR(address).IsValidIpv4Address() |
| info = self.log.CreateProgressInfo('---', |
| 'Verify IP: Bruno has IP address ' |
| + address) |
| self.log.SendLine(self.test_info, info) |
| return address |
| else: |
| info = self.log.CreateErrorInfo('critical', |
| 'Error! Bruno does not have IP address!' |
| ' Exit!') |
| self.log.SendLine(self.test_info, info) |
| return False |
| |
| def GetNetMask(self): |
| """Get Netmask from device.""" |
| self.p_ssh.SendCmd(r'ifconfig br0') |
| line = self.p_ssh.GetCmdOutput(3)[1] |
| |
| netmask = re.search(r'mask [0-9]+(?:\.[0-9]+){3}', line).group() |
| address = ip.IPADDR(netmask).IsLikeIpv4Address() |
| if address is not None: |
| ip.IPADDR(address).IsValidIpv4Address() |
| info = self.log.CreateProgressInfo('---', |
| 'Verify IP: Bruno has netmask: ' |
| + address) |
| self.log.SendLine(self.test_info, info) |
| return address |
| else: |
| info = self.log.CreateErrorInfo('critical', |
| 'Error! Bruno does not have netmask!' |
| ' Exit!') |
| self.log.SendLine(self.test_info, info) |
| return False |
| |
| def VerifyIPv6(self): |
| """Test Bruno IPv6 address. testID: 11722376.""" |
| # Use ip addr to check interface IPv6 address |
| self.p_ssh.SendCmd(r'ip addr show dev br0') |
| |
| for line in reversed(self.p_ssh.p_ssh.before.splitlines()[-10:]): |
| ipv6_addr = re.search('inet6.*dynamic', line) |
| # Get Bruno IPv6 address |
| if ipv6_addr is not None: |
| info = self.log.CreateProgressInfo('---', |
| 'Verify IPv6: ' |
| 'Bruno has IPv6 address: ' |
| + ipv6_addr.group()) |
| self.log.SendLine(self.test_info, info) |
| break |
| else: |
| info = self.log.CreateErrorInfo('intermediate', |
| 'Wanring! ' |
| 'Bruno did not have IPv6 address') |
| self.log.SendLine(self.test_info, info) |
| return |
| |
| def VerifyDHCPOverBrunoIS(self): |
| """Verify Bruno (connected to Bruno-IS) can get IPv4 address from RG. |
| |
| test ID: 11721378 |
| This test requires thinBruno is connected to FatBruno, then to RG. |
| """ |
| ip_addr = self.GetIPv4Address() |
| if ip_addr: |
| info = self.log.CreateResultInfo('Pass', 'Bruno can get IP address from ' |
| 'RG while connecting to Bruno-IS. ' |
| 'IP address: '+ ip_addr) |
| self.log.SendLine(self.test_info, info) |
| else: |
| info = self.log.CreateResultInfo('Failed', |
| 'Bruno cannot get IP address from ' |
| 'RG. Verification Failed!') |
| self.log.SendLine(self.test_info, info) |
| |
| def Run(self): |
| """Run the test case.""" |
| ####### Add your code here -- BEGIN ####### |
| print 'Test Started...' |
| |
| self.Init() |
| time.sleep(2) # time delay between commands issued to Device |
| self.SshTunnel() |
| |
| self.VerifyIPv6() |
| |
| if self.test_info['testID'] == '11874111': |
| ip_addr = self.params['addr_ipv6_dup'] |
| self.VerifyDuplicatedAddress(ip_addr) |
| elif self.test_info['testID'] == '11721378': |
| self.VerifyDHCPOverBrunoIS() |
| |
| # TODO(lmeng): Test cases: '11724363', '11843145', '11723379', '11722378', |
| # '11792173', '11721382', '11843141', '11721379' |
| |
| print 'Test Completed...' |
| ####### Add your code here -- END ####### |
| |
| def Destructor(self): |
| """This is the destructor function to call for the user extened class.""" |
| self.p_ssh.close() |
| |
| if __name__ == '__main__': |
| # Test cases defined in this file: |
| test_defined = ['11874111', '11724363', '11843145', '11723379', '11722378', |
| '11721378', '11792173', '11721382', '11843141', '11721379'] |
| # To execute test cases that defined in config file: |
| test_to_execute = testCase.TestCase.FindTestCaseToExecute('config.cfg') |
| for test_id in test_to_execute: |
| if test_id in test_defined: |
| test = BasicNetworkingTest(testID=test_id) |