Chetan Gaonker | 2547097 | 2016-02-26 08:52:15 -0800 | [diff] [blame] | 1 | import unittest |
| 2 | from nose.tools import * |
| 3 | from nose.twistedtools import reactor, deferred |
| 4 | from twisted.internet import defer |
| 5 | from scapy.all import * |
Chetan Gaonker | eb2b24b | 2016-03-01 14:04:45 -0800 | [diff] [blame] | 6 | import time, monotonic |
Chetan Gaonker | 2547097 | 2016-02-26 08:52:15 -0800 | [diff] [blame] | 7 | import os, sys |
Chetan Gaonker | eb2b24b | 2016-03-01 14:04:45 -0800 | [diff] [blame] | 8 | import tempfile |
Chetan Gaonker | eb2b24b | 2016-03-01 14:04:45 -0800 | [diff] [blame] | 9 | import random |
| 10 | import threading |
Chetan Gaonker | e88c95c | 2016-03-02 05:21:47 -0800 | [diff] [blame] | 11 | from IGMP import * |
Chetan Gaonker | eb2b24b | 2016-03-01 14:04:45 -0800 | [diff] [blame] | 12 | from McastTraffic import * |
| 13 | from Stats import Stats |
Chetan Gaonker | 4a25e2b | 2016-03-04 14:45:15 -0800 | [diff] [blame] | 14 | from OnosCtrl import OnosCtrl |
Chetan Gaonker | 4eb1207 | 2016-03-28 15:04:15 -0700 | [diff] [blame] | 15 | from Channels import IgmpChannel |
Chetan Gaonker | eb2b24b | 2016-03-01 14:04:45 -0800 | [diff] [blame] | 16 | log.setLevel('INFO') |
Chetan Gaonker | 2547097 | 2016-02-26 08:52:15 -0800 | [diff] [blame] | 17 | |
| 18 | class IGMPTestState: |
| 19 | |
| 20 | def __init__(self, groups = [], df = None, state = 0): |
| 21 | self.df = df |
| 22 | self.state = state |
| 23 | self.counter = 0 |
| 24 | self.groups = groups |
| 25 | self.group_map = {} ##create a send/recv count map |
| 26 | for g in groups: |
Chetan Gaonker | eb2b24b | 2016-03-01 14:04:45 -0800 | [diff] [blame] | 27 | self.group_map[g] = (Stats(), Stats()) |
| 28 | |
| 29 | def update(self, group, tx = 0, rx = 0, t = 0): |
| 30 | self.counter += 1 |
Chetan Gaonker | 2547097 | 2016-02-26 08:52:15 -0800 | [diff] [blame] | 31 | index = 0 if rx == 0 else 1 |
| 32 | v = tx if rx == 0 else rx |
| 33 | if self.group_map.has_key(group): |
Chetan Gaonker | eb2b24b | 2016-03-01 14:04:45 -0800 | [diff] [blame] | 34 | self.group_map[group][index].update(packets = v, t = t) |
Chetan Gaonker | 2547097 | 2016-02-26 08:52:15 -0800 | [diff] [blame] | 35 | |
| 36 | def update_state(self): |
| 37 | self.state = self.state ^ 1 |
Chetan Gaonker | 2547097 | 2016-02-26 08:52:15 -0800 | [diff] [blame] | 38 | |
| 39 | class igmp_exchange(unittest.TestCase): |
Chetan Gaonker | eb2b24b | 2016-03-01 14:04:45 -0800 | [diff] [blame] | 40 | |
Chetan Gaonker | 8bbc4d5 | 2016-03-29 16:59:45 -0700 | [diff] [blame] | 41 | V_INF1 = 'veth0' |
| 42 | V_INF2 = 'veth1' |
| 43 | MGROUP1 = '239.1.2.3' |
| 44 | MGROUP2 = '239.2.2.3' |
| 45 | MMACGROUP1 = "01:00:5e:01:02:03" |
| 46 | MMACGROUP2 = "01:00:5e:02:02:03" |
Chetan Gaonker | 586fec3 | 2016-04-29 17:33:54 -0700 | [diff] [blame] | 47 | MINVALIDGROUP1 = "255.255.255.255" |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 48 | MINVALIDGROUP2 = "255.255.255.255" |
Chetan Gaonker | 8bbc4d5 | 2016-03-29 16:59:45 -0700 | [diff] [blame] | 49 | IGMP_DST_MAC = "01:00:5e:00:01:01" |
| 50 | IGMP_SRC_MAC = "5a:e1:ac:ec:4d:a1" |
| 51 | IP_SRC = '1.2.3.4' |
| 52 | IP_DST = '224.0.1.1' |
| 53 | igmp_eth = Ether(dst = IGMP_DST_MAC, src = IGMP_SRC_MAC, type = ETH_P_IP) |
| 54 | igmp_ip = IP(dst = IP_DST, src = IP_SRC) |
Chetan Gaonker | eb2b24b | 2016-03-01 14:04:45 -0800 | [diff] [blame] | 55 | IGMP_TEST_TIMEOUT = 5 |
Chetan Gaonker | 1f7c3f8 | 2016-03-08 12:17:37 -0800 | [diff] [blame] | 56 | IGMP_QUERY_TIMEOUT = 30 |
Chetan Gaonker | eb2b24b | 2016-03-01 14:04:45 -0800 | [diff] [blame] | 57 | MCAST_TRAFFIC_TIMEOUT = 10 |
Chetan Gaonker | 4eb1207 | 2016-03-28 15:04:15 -0700 | [diff] [blame] | 58 | PORT_TX_DEFAULT = 2 |
| 59 | PORT_RX_DEFAULT = 1 |
Chetan Gaonker | eb2b24b | 2016-03-01 14:04:45 -0800 | [diff] [blame] | 60 | max_packets = 100 |
Chetan Gaonker | 4a25e2b | 2016-03-04 14:45:15 -0800 | [diff] [blame] | 61 | app = 'org.onosproject.igmp' |
| 62 | |
| 63 | def setUp(self): |
| 64 | ''' Activate the dhcp app''' |
| 65 | self.onos_ctrl = OnosCtrl(self.app) |
| 66 | status, _ = self.onos_ctrl.activate() |
| 67 | assert_equal(status, True) |
Chetan Gaonker | 8bbc4d5 | 2016-03-29 16:59:45 -0700 | [diff] [blame] | 68 | time.sleep(2) |
Chetan Gaonker | 4eb1207 | 2016-03-28 15:04:15 -0700 | [diff] [blame] | 69 | self.igmp_channel = IgmpChannel() |
Chetan Gaonker | 4a25e2b | 2016-03-04 14:45:15 -0800 | [diff] [blame] | 70 | |
| 71 | def teardown(self): |
| 72 | '''Deactivate the dhcp app''' |
| 73 | self.onos_ctrl.deactivate() |
| 74 | |
| 75 | def onos_load_config(self, config): |
Chetan Gaonker | a2b87df | 2016-03-31 15:41:31 -0700 | [diff] [blame] | 76 | status, code = OnosCtrl.config(config) |
Chetan Gaonker | 4a25e2b | 2016-03-04 14:45:15 -0800 | [diff] [blame] | 77 | if status is False: |
| 78 | log.info('JSON request returned status %d' %code) |
| 79 | assert_equal(status, True) |
| 80 | time.sleep(2) |
| 81 | |
Chetan Gaonker | eb2b24b | 2016-03-01 14:04:45 -0800 | [diff] [blame] | 82 | def onos_ssm_table_load(self, groups, src_list): |
| 83 | ssm_dict = {'apps' : { 'org.onosproject.igmp' : { 'ssmTranslate' : [] } } } |
| 84 | ssm_xlate_list = ssm_dict['apps']['org.onosproject.igmp']['ssmTranslate'] |
| 85 | for g in groups: |
| 86 | for s in src_list: |
| 87 | d = {} |
Chetan Gaonker | 8bbc4d5 | 2016-03-29 16:59:45 -0700 | [diff] [blame] | 88 | d['source'] = s or '0.0.0.0' |
Chetan Gaonker | eb2b24b | 2016-03-01 14:04:45 -0800 | [diff] [blame] | 89 | d['group'] = g |
| 90 | ssm_xlate_list.append(d) |
Chetan Gaonker | 4a25e2b | 2016-03-04 14:45:15 -0800 | [diff] [blame] | 91 | self.onos_load_config(ssm_dict) |
Chetan Gaonker | 4eb1207 | 2016-03-28 15:04:15 -0700 | [diff] [blame] | 92 | cord_port_map = {} |
| 93 | for g in groups: |
| 94 | cord_port_map[g] = (self.PORT_TX_DEFAULT, self.PORT_RX_DEFAULT) |
| 95 | self.igmp_channel.cord_port_table_load(cord_port_map) |
Chetan Gaonker | 5a5204e | 2016-03-02 01:35:13 -0800 | [diff] [blame] | 96 | time.sleep(2) |
Chetan Gaonker | eb2b24b | 2016-03-01 14:04:45 -0800 | [diff] [blame] | 97 | |
| 98 | def igmp_verify_join(self, igmpStateList): |
| 99 | sendState, recvState = igmpStateList |
Chetan Gaonker | 2547097 | 2016-02-26 08:52:15 -0800 | [diff] [blame] | 100 | ## check if the send is received for the groups |
Chetan Gaonker | eb2b24b | 2016-03-01 14:04:45 -0800 | [diff] [blame] | 101 | for g in sendState.groups: |
| 102 | tx_stats = sendState.group_map[g][0] |
| 103 | tx = tx_stats.count |
Chetan Gaonker | 2547097 | 2016-02-26 08:52:15 -0800 | [diff] [blame] | 104 | assert_greater(tx, 0) |
Chetan Gaonker | eb2b24b | 2016-03-01 14:04:45 -0800 | [diff] [blame] | 105 | rx_stats = recvState.group_map[g][1] |
| 106 | rx = rx_stats.count |
| 107 | assert_greater(rx, 0) |
| 108 | log.info('Receive stats %s for group %s' %(rx_stats, g)) |
| 109 | |
| 110 | log.info('IGMP test verification success') |
Chetan Gaonker | 2547097 | 2016-02-26 08:52:15 -0800 | [diff] [blame] | 111 | |
Chetan Gaonker | eb2b24b | 2016-03-01 14:04:45 -0800 | [diff] [blame] | 112 | def igmp_verify_leave(self, igmpStateList, leave_groups): |
| 113 | sendState, recvState = igmpStateList[0], igmpStateList[1] |
| 114 | ## check if the send is received for the groups |
| 115 | for g in sendState.groups: |
| 116 | tx_stats = sendState.group_map[g][0] |
| 117 | rx_stats = recvState.group_map[g][1] |
| 118 | tx = tx_stats.count |
| 119 | rx = rx_stats.count |
| 120 | assert_greater(tx, 0) |
| 121 | if g not in leave_groups: |
| 122 | log.info('Received %d packets for group %s' %(rx, g)) |
| 123 | for g in leave_groups: |
| 124 | rx = recvState.group_map[g][1].count |
| 125 | assert_equal(rx, 0) |
| 126 | |
| 127 | log.info('IGMP test verification success') |
Chetan Gaonker | 2547097 | 2016-02-26 08:52:15 -0800 | [diff] [blame] | 128 | |
Chetan Gaonker | eb2b24b | 2016-03-01 14:04:45 -0800 | [diff] [blame] | 129 | def mcast_traffic_timer(self): |
| 130 | self.mcastTraffic.stopReceives() |
| 131 | |
| 132 | def send_mcast_cb(self, send_state): |
| 133 | for g in send_state.groups: |
| 134 | send_state.update(g, tx = 1) |
Chetan Gaonker | 2547097 | 2016-02-26 08:52:15 -0800 | [diff] [blame] | 135 | return 0 |
| 136 | |
Chetan Gaonker | eb2b24b | 2016-03-01 14:04:45 -0800 | [diff] [blame] | 137 | ##Runs in the context of twisted reactor thread |
Chetan Gaonker | 2547097 | 2016-02-26 08:52:15 -0800 | [diff] [blame] | 138 | def igmp_recv(self, igmpState, iface = 'veth0'): |
Chetan Gaonker | eb2b24b | 2016-03-01 14:04:45 -0800 | [diff] [blame] | 139 | p = self.recv_socket.recv() |
| 140 | send_time = float(p.payload.load) |
| 141 | recv_time = monotonic.monotonic() |
| 142 | #log.info( 'Recv in %.6f secs' %(recv_time - send_time)) |
| 143 | igmpState.update(p.dst, rx = 1, t = recv_time - send_time) |
Chetan Gaonker | 2547097 | 2016-02-26 08:52:15 -0800 | [diff] [blame] | 144 | return 0 |
| 145 | |
Chetan Gaonker | 8bbc4d5 | 2016-03-29 16:59:45 -0700 | [diff] [blame] | 146 | def send_igmp_join(self, groups, src_list = ['1.2.3.4'], ip_pkt = None, iface = 'veth0', delay = 2): |
Chetan Gaonker | eb2b24b | 2016-03-01 14:04:45 -0800 | [diff] [blame] | 147 | self.onos_ssm_table_load(groups, src_list) |
Chetan Gaonker | 5a5204e | 2016-03-02 01:35:13 -0800 | [diff] [blame] | 148 | igmp = IGMPv3(type = IGMP_TYPE_V3_MEMBERSHIP_REPORT, max_resp_code=30, |
Chetan Gaonker | 8bbc4d5 | 2016-03-29 16:59:45 -0700 | [diff] [blame] | 149 | gaddr=self.IP_DST) |
Chetan Gaonker | eb2b24b | 2016-03-01 14:04:45 -0800 | [diff] [blame] | 150 | for g in groups: |
Chetan Gaonker | 5a5204e | 2016-03-02 01:35:13 -0800 | [diff] [blame] | 151 | gr = IGMPv3gr(rtype=IGMP_V3_GR_TYPE_EXCLUDE, mcaddr=g) |
| 152 | gr.sources = src_list |
| 153 | igmp.grps.append(gr) |
Chetan Gaonker | 8bbc4d5 | 2016-03-29 16:59:45 -0700 | [diff] [blame] | 154 | if ip_pkt is None: |
| 155 | ip_pkt = self.igmp_eth/self.igmp_ip |
| 156 | pkt = ip_pkt/igmp |
Chetan Gaonker | 5a5204e | 2016-03-02 01:35:13 -0800 | [diff] [blame] | 157 | IGMPv3.fixup(pkt) |
| 158 | sendp(pkt, iface=iface) |
Chetan Gaonker | eb2b24b | 2016-03-01 14:04:45 -0800 | [diff] [blame] | 159 | if delay != 0: |
| 160 | time.sleep(delay) |
| 161 | |
Chetan Gaonker | 8bbc4d5 | 2016-03-29 16:59:45 -0700 | [diff] [blame] | 162 | def send_igmp_leave(self, groups, src_list = ['1.2.3.4'], ip_pkt = None, iface = 'veth0', delay = 2): |
Chetan Gaonker | 5a5204e | 2016-03-02 01:35:13 -0800 | [diff] [blame] | 163 | igmp = IGMPv3(type = IGMP_TYPE_V3_MEMBERSHIP_REPORT, max_resp_code=30, |
Chetan Gaonker | 8bbc4d5 | 2016-03-29 16:59:45 -0700 | [diff] [blame] | 164 | gaddr=self.IP_DST) |
Chetan Gaonker | eb2b24b | 2016-03-01 14:04:45 -0800 | [diff] [blame] | 165 | for g in groups: |
Chetan Gaonker | 5a5204e | 2016-03-02 01:35:13 -0800 | [diff] [blame] | 166 | gr = IGMPv3gr(rtype=IGMP_V3_GR_TYPE_INCLUDE, mcaddr=g) |
| 167 | gr.sources = src_list |
| 168 | igmp.grps.append(gr) |
Chetan Gaonker | 8bbc4d5 | 2016-03-29 16:59:45 -0700 | [diff] [blame] | 169 | if ip_pkt is None: |
| 170 | ip_pkt = self.igmp_eth/self.igmp_ip |
| 171 | pkt = ip_pkt/igmp |
Chetan Gaonker | 5a5204e | 2016-03-02 01:35:13 -0800 | [diff] [blame] | 172 | IGMPv3.fixup(pkt) |
| 173 | sendp(pkt, iface = iface) |
Chetan Gaonker | eb2b24b | 2016-03-01 14:04:45 -0800 | [diff] [blame] | 174 | if delay != 0: |
| 175 | time.sleep(delay) |
Chetan Gaonker | 2547097 | 2016-02-26 08:52:15 -0800 | [diff] [blame] | 176 | |
Chetan Gaonker | eb2b24b | 2016-03-01 14:04:45 -0800 | [diff] [blame] | 177 | @deferred(timeout=MCAST_TRAFFIC_TIMEOUT+10) |
| 178 | def test_igmp_join_verify_traffic(self): |
Chetan Gaonker | 2547097 | 2016-02-26 08:52:15 -0800 | [diff] [blame] | 179 | groups = ['224.0.1.1', '225.0.0.1'] |
Chetan Gaonker | 2547097 | 2016-02-26 08:52:15 -0800 | [diff] [blame] | 180 | df = defer.Deferred() |
| 181 | igmpState = IGMPTestState(groups = groups, df = df) |
Chetan Gaonker | eb2b24b | 2016-03-01 14:04:45 -0800 | [diff] [blame] | 182 | igmpStateRecv = IGMPTestState(groups = groups, df = df) |
| 183 | igmpStateList = (igmpState, igmpStateRecv) |
| 184 | mcastTraffic = McastTraffic(groups, iface= 'veth2', cb = self.send_mcast_cb, arg = igmpState) |
| 185 | self.df = df |
| 186 | self.mcastTraffic = mcastTraffic |
| 187 | self.recv_socket = L3PacketSocket(iface = 'veth0', type = ETH_P_IP) |
| 188 | |
| 189 | def igmp_srp_task(stateList): |
| 190 | igmpSendState, igmpRecvState = stateList |
| 191 | if not mcastTraffic.isRecvStopped(): |
| 192 | result = self.igmp_recv(igmpRecvState) |
| 193 | reactor.callLater(0, igmp_srp_task, stateList) |
| 194 | else: |
| 195 | self.mcastTraffic.stop() |
| 196 | self.recv_socket.close() |
| 197 | self.igmp_verify_join(stateList) |
| 198 | self.df.callback(0) |
| 199 | |
| 200 | self.send_igmp_join(groups) |
| 201 | mcastTraffic.start() |
| 202 | self.test_timer = reactor.callLater(self.MCAST_TRAFFIC_TIMEOUT, self.mcast_traffic_timer) |
| 203 | reactor.callLater(0, igmp_srp_task, igmpStateList) |
Chetan Gaonker | 2547097 | 2016-02-26 08:52:15 -0800 | [diff] [blame] | 204 | return df |
| 205 | |
Chetan Gaonker | eb2b24b | 2016-03-01 14:04:45 -0800 | [diff] [blame] | 206 | @deferred(timeout=MCAST_TRAFFIC_TIMEOUT+10) |
| 207 | def test_igmp_leave_verify_traffic(self): |
| 208 | groups = ['224.0.1.10', '225.0.0.10'] |
| 209 | leave_groups = ['224.0.1.10'] |
| 210 | df = defer.Deferred() |
| 211 | igmpState = IGMPTestState(groups = groups, df = df) |
| 212 | igmpStateRecv = IGMPTestState(groups = groups, df = df) |
| 213 | igmpStateList = (igmpState, igmpStateRecv) |
| 214 | mcastTraffic = McastTraffic(groups, iface= 'veth2', cb = self.send_mcast_cb, |
| 215 | arg = igmpState) |
| 216 | self.df = df |
| 217 | self.mcastTraffic = mcastTraffic |
| 218 | self.recv_socket = L3PacketSocket(iface = 'veth0', type = ETH_P_IP) |
| 219 | |
| 220 | def igmp_srp_task(stateList): |
| 221 | igmpSendState, igmpRecvState = stateList |
| 222 | if not mcastTraffic.isRecvStopped(): |
| 223 | result = self.igmp_recv(igmpRecvState) |
| 224 | reactor.callLater(0, igmp_srp_task, stateList) |
| 225 | else: |
| 226 | self.mcastTraffic.stop() |
| 227 | self.recv_socket.close() |
| 228 | self.igmp_verify_leave(stateList, leave_groups) |
| 229 | self.df.callback(0) |
| 230 | |
| 231 | self.send_igmp_join(groups) |
| 232 | self.send_igmp_leave(leave_groups, delay = 3) |
| 233 | mcastTraffic.start() |
| 234 | self.test_timer = reactor.callLater(self.MCAST_TRAFFIC_TIMEOUT, self.mcast_traffic_timer) |
| 235 | reactor.callLater(0, igmp_srp_task, igmpStateList) |
| 236 | return df |
| 237 | |
| 238 | @deferred(timeout=100) |
| 239 | def test_igmp_leave_join_loop(self): |
| 240 | self.groups = ['226.0.1.1', '227.0.0.1', '228.0.0.1', '229.0.0.1', '230.0.0.1' ] |
| 241 | self.src_list = ['3.4.5.6', '7.8.9.10'] |
| 242 | df = defer.Deferred() |
| 243 | self.df = df |
| 244 | self.iterations = 0 |
| 245 | self.num_groups = len(self.groups) |
| 246 | self.MAX_TEST_ITERATIONS = 10 |
| 247 | |
Chetan Gaonker | eb2b24b | 2016-03-01 14:04:45 -0800 | [diff] [blame] | 248 | def igmp_srp_task(v): |
| 249 | if self.iterations < self.MAX_TEST_ITERATIONS: |
| 250 | if v == 1: |
| 251 | ##join test |
| 252 | self.num_groups = random.randint(0, len(self.groups)) |
| 253 | self.send_igmp_join(self.groups[:self.num_groups], |
| 254 | src_list = self.src_list, |
| 255 | iface = 'veth0', delay = 0) |
| 256 | else: |
| 257 | self.send_igmp_leave(self.groups[:self.num_groups], |
| 258 | src_list = self.src_list, |
| 259 | iface = 'veth0', delay = 0) |
| 260 | self.iterations += 1 |
| 261 | v ^= 1 |
| 262 | reactor.callLater(1.0 + 0.5*self.num_groups, |
| 263 | igmp_srp_task, v) |
| 264 | else: |
| 265 | self.df.callback(0) |
| 266 | |
| 267 | reactor.callLater(0, igmp_srp_task, 1) |
| 268 | return df |
| 269 | |
| 270 | def igmp_join_task(self, intf, groups, state, src_list = ['1.2.3.4']): |
| 271 | self.onos_ssm_table_load(groups, src_list) |
Chetan Gaonker | 5a5204e | 2016-03-02 01:35:13 -0800 | [diff] [blame] | 272 | igmp = IGMPv3(type = IGMP_TYPE_V3_MEMBERSHIP_REPORT, max_resp_code=30, |
Chetan Gaonker | 8bbc4d5 | 2016-03-29 16:59:45 -0700 | [diff] [blame] | 273 | gaddr=self.IP_DST) |
Chetan Gaonker | eb2b24b | 2016-03-01 14:04:45 -0800 | [diff] [blame] | 274 | for g in groups: |
Chetan Gaonker | 5a5204e | 2016-03-02 01:35:13 -0800 | [diff] [blame] | 275 | gr = IGMPv3gr(rtype = IGMP_V3_GR_TYPE_EXCLUDE, mcaddr = g) |
| 276 | gr.sources = src_list |
| 277 | igmp.grps.append(gr) |
| 278 | |
| 279 | for g in groups: |
Chetan Gaonker | eb2b24b | 2016-03-01 14:04:45 -0800 | [diff] [blame] | 280 | state.group_map[g][0].update(1, t = monotonic.monotonic()) |
Chetan Gaonker | 5a5204e | 2016-03-02 01:35:13 -0800 | [diff] [blame] | 281 | |
Chetan Gaonker | 8bbc4d5 | 2016-03-29 16:59:45 -0700 | [diff] [blame] | 282 | pkt = self.igmp_eth/self.igmp_ip/igmp |
Chetan Gaonker | 5a5204e | 2016-03-02 01:35:13 -0800 | [diff] [blame] | 283 | IGMPv3.fixup(pkt) |
| 284 | sendp(pkt, iface=intf) |
Chetan Gaonker | eb2b24b | 2016-03-01 14:04:45 -0800 | [diff] [blame] | 285 | log.debug('Returning from join task') |
| 286 | |
| 287 | def igmp_recv_task(self, intf, groups, join_state): |
| 288 | recv_socket = L3PacketSocket(iface = intf, type = ETH_P_IP) |
| 289 | group_map = {} |
| 290 | for g in groups: |
| 291 | group_map[g] = [0,0] |
| 292 | |
| 293 | while True: |
| 294 | p = recv_socket.recv() |
| 295 | if p.dst in groups and group_map[p.dst][0] == 0: |
| 296 | group_map[p.dst][0] += 1 |
| 297 | group_map[p.dst][1] = monotonic.monotonic() |
| 298 | c = 0 |
| 299 | for g in groups: |
| 300 | c += group_map[g][0] |
| 301 | if c == len(groups): |
| 302 | break |
| 303 | for g in groups: |
| 304 | join_start = join_state.group_map[g][0].start |
| 305 | recv_time = group_map[g][1] * 1000000 |
| 306 | delta = (recv_time - join_start) |
| 307 | log.info('Join for group %s received in %.3f usecs' % |
| 308 | (g, delta)) |
| 309 | |
| 310 | recv_socket.close() |
| 311 | log.debug('Returning from recv task') |
Chetan Gaonker | 8bbc4d5 | 2016-03-29 16:59:45 -0700 | [diff] [blame] | 312 | |
| 313 | def igmp_not_recv_task(self, intf, groups, join_state): |
| 314 | recv_socket = L2Socket(iface = intf, type = ETH_P_IP) |
| 315 | group_map = {} |
| 316 | for g in groups: |
| 317 | group_map[g] = [0,0] |
| 318 | |
| 319 | log.info('Should not receive any multicast data') |
| 320 | status = 1 |
| 321 | def igmp_recv_cb(pkt): |
| 322 | log.info('Multicast packet %s received for left groups %s' %(pkt[IP].dst, groups)) |
| 323 | status = 2 |
| 324 | sniff(prn = igmp_recv_cb, count = 1, lfilter = lambda p: p[IP].dst in groups, |
| 325 | timeout = 3, opened_socket = recv_socket) |
| 326 | recv_socket.close() |
| 327 | return status |
| 328 | |
Chetan Gaonker | eb2b24b | 2016-03-01 14:04:45 -0800 | [diff] [blame] | 329 | def group_latency_check(self, groups): |
| 330 | tasks = [] |
| 331 | self.send_igmp_leave(groups = groups) |
| 332 | join_state = IGMPTestState(groups = groups) |
| 333 | tasks.append(threading.Thread(target=self.igmp_join_task, args = ('veth0', groups, join_state,))) |
| 334 | traffic_state = IGMPTestState(groups = groups) |
| 335 | mcast_traffic = McastTraffic(groups, iface= 'veth2', cb = self.send_mcast_cb, |
| 336 | arg = traffic_state) |
| 337 | mcast_traffic.start() |
| 338 | tasks.append(threading.Thread(target=self.igmp_recv_task, args = ('veth0', groups, join_state))) |
| 339 | for t in tasks: |
| 340 | t.start() |
| 341 | for t in tasks: |
| 342 | t.join() |
| 343 | |
| 344 | mcast_traffic.stop() |
| 345 | self.send_igmp_leave(groups = groups) |
| 346 | return |
| 347 | |
| 348 | def test_igmp_1group_join_latency(self): |
| 349 | groups = ['239.0.1.1'] |
| 350 | self.group_latency_check(groups) |
| 351 | |
| 352 | def test_igmp_2group_join_latency(self): |
| 353 | groups = ['239.0.1.1', '240.0.1.1'] |
| 354 | self.group_latency_check(groups) |
| 355 | |
| 356 | def test_igmp_Ngroup_join_latency(self): |
| 357 | groups = ['239.0.1.1', '240.0.1.1', '241.0.1.1', '242.0.1.1'] |
| 358 | self.group_latency_check(groups) |
| 359 | |
| 360 | |
Chetan Gaonker | 1f7c3f8 | 2016-03-08 12:17:37 -0800 | [diff] [blame] | 361 | def test_igmp_join_rover(self): |
| 362 | '''Keep sending joins across multicast range of addresses''' |
| 363 | '''For now, restricting it to 50/100''' |
| 364 | s = (224 << 24) | 1 |
| 365 | #e = (225 << 24) | (255 << 16) | (255 << 16) | 255 |
Chetan Gaonker | 8bbc4d5 | 2016-03-29 16:59:45 -0700 | [diff] [blame] | 366 | e = (224 << 24) | 10 |
Chetan Gaonker | 1f7c3f8 | 2016-03-08 12:17:37 -0800 | [diff] [blame] | 367 | for i in xrange(s, e+1): |
| 368 | if i&0xff: |
| 369 | ip = '%d.%d.%d.%d'%((i>>24)&0xff, (i>>16)&0xff, (i>>8)&0xff, i&0xff) |
| 370 | self.send_igmp_join([ip], delay = 0) |
| 371 | |
| 372 | @deferred(timeout=IGMP_QUERY_TIMEOUT + 10) |
| 373 | def test_igmp_query(self): |
| 374 | groups = ['224.0.0.1'] ##igmp query group |
| 375 | df = defer.Deferred() |
| 376 | self.df = df |
| 377 | self.recv_socket = L2Socket(iface = 'veth0', type = ETH_P_IP) |
| 378 | |
| 379 | def igmp_query_timeout(): |
Chetan Gaonker | 1f7c3f8 | 2016-03-08 12:17:37 -0800 | [diff] [blame] | 380 | def igmp_query_cb(pkt): |
Chetan Gaonker | bd4390f | 2016-03-09 18:56:52 -0800 | [diff] [blame] | 381 | log.info('Got IGMP query packet from %s for %s' %(pkt[IP].src, pkt[IP].dst)) |
| 382 | assert_equal(pkt[IP].dst, '224.0.0.1') |
| 383 | |
| 384 | sniff(prn = igmp_query_cb, count=1, lfilter = lambda p: p[IP].dst in groups, |
| 385 | opened_socket = self.recv_socket) |
Chetan Gaonker | 1f7c3f8 | 2016-03-08 12:17:37 -0800 | [diff] [blame] | 386 | self.recv_socket.close() |
| 387 | self.df.callback(0) |
| 388 | |
| 389 | self.send_igmp_join(groups) |
| 390 | self.test_timer = reactor.callLater(self.IGMP_QUERY_TIMEOUT, igmp_query_timeout) |
| 391 | return df |
| 392 | |
Chetan Gaonker | 8bbc4d5 | 2016-03-29 16:59:45 -0700 | [diff] [blame] | 393 | def igmp_send_joins_different_groups_srclist(self, groups, sources, intf = V_INF1, delay = 2, ip_src = None): |
| 394 | g1 = groups[0] |
| 395 | g2 = groups[1] |
| 396 | sourcelist1 = sources[0] |
| 397 | sourcelist2 = sources[1] |
| 398 | eth = Ether(dst = self.MMACGROUP1, src = self.IGMP_SRC_MAC, type = ETH_P_IP) |
| 399 | src_ip = ip_src or self.IP_SRC |
| 400 | ip = IP(dst = g1, src = src_ip) |
| 401 | log.info('Sending join message for the group %s' %g1) |
| 402 | self.send_igmp_join((g1,), src_list = sourcelist1, ip_pkt = eth/ip, iface = intf, delay = 2) |
| 403 | eth = Ether(dst = self.MMACGROUP2, src = self.IGMP_SRC_MAC, type = ETH_P_IP) |
| 404 | ip = IP(dst = g2, src = src_ip) |
| 405 | log.info('Sending join message for group %s' %g2) |
| 406 | self.send_igmp_join((g2,), src_list = sourcelist2, ip_pkt = eth/ip, iface = intf, delay = 2) |
| 407 | |
| 408 | def igmp_joins_leave_functionality(self, again_join = False, df = None): |
| 409 | groups1 = (self.MGROUP1,) |
| 410 | groups2 = (self.MGROUP2,) |
| 411 | self.igmp_send_joins_different_groups_srclist(groups1 + groups2, |
| 412 | (['2.2.2.2'], ['2.2.2.2']), intf = self.V_INF1, delay = 2) |
| 413 | dst_mac = '01:00:5e:01:02:03' |
| 414 | src_ip = '2.2.2.2' |
| 415 | if df is None: |
| 416 | df = defer.Deferred() |
| 417 | igmpState1 = IGMPTestState(groups = groups1, df = df) |
| 418 | igmpStateRecv1 = IGMPTestState(groups = groups1, df = df) |
| 419 | igmpStateList1 = (igmpState1, igmpStateRecv1) |
| 420 | |
| 421 | igmpState2 = IGMPTestState(groups = groups2, df = df) |
| 422 | igmpStateRecv2 = IGMPTestState(groups = groups2, df = df) |
| 423 | igmpStateList2 = (igmpState2, igmpStateRecv2) |
| 424 | mcastTraffic1 = McastTraffic(groups1, iface= 'veth2', dst_mac = dst_mac, |
| 425 | src_ip = src_ip, cb = self.send_mcast_cb, |
| 426 | arg = igmpState1) |
| 427 | dst_mac = '01:00:5e:02:02:03' |
| 428 | src_ip = '2.2.2.2' |
| 429 | mcastTraffic2 = McastTraffic(groups2, iface= 'veth2', dst_mac = dst_mac, |
| 430 | src_ip = src_ip, cb = self.send_mcast_cb, |
| 431 | arg = igmpState2) |
| 432 | mcastTraffic1.start() |
| 433 | mcastTraffic2.start() |
| 434 | join_state1 = IGMPTestState(groups = groups1) |
| 435 | join_state2 = IGMPTestState(groups = groups2) |
| 436 | target1 = self.igmp_recv_task(self.V_INF1, groups1, join_state1) |
| 437 | log.info('Interface is receiving multicast groups %s' %groups1) |
| 438 | target2 = self.igmp_recv_task(self.V_INF1, groups2, join_state2) |
| 439 | log.info('Interface is receiving multicast groups %s' %groups2) |
| 440 | log.info('Interface is sending leave message for groups %s now' %groups2) |
| 441 | self.send_igmp_leave(groups = groups2, src_list = ['2.2.2.2'], iface = self.V_INF1, delay = 2) |
| 442 | target3 = self.igmp_recv_task(self.V_INF1, groups1, join_state1) |
| 443 | target4 = self.igmp_not_recv_task(self.V_INF1, groups2, join_state2) |
| 444 | assert target4 == 1, 'EXPECTED FAILURE' |
| 445 | if again_join: |
| 446 | dst_mac = '01:00:5e:02:02:03' |
| 447 | ip_dst = '239.2.2.3' |
| 448 | eth = Ether(dst = dst_mac, src = self.IGMP_SRC_MAC, type = ETH_P_IP) |
| 449 | ip = IP(dst = ip_dst, src = self.IP_SRC) |
| 450 | log.info('Interface sending join message again for the groups %s' %groups2) |
| 451 | self.send_igmp_join(groups2, src_list = [src_ip], ip_pkt = eth/ip, iface = self.V_INF1, delay = 2) |
| 452 | target5 = self.igmp_recv_task(self.V_INF1, groups2, join_state2) |
| 453 | log.info('Interface is receiving multicast groups %s again' %groups2) |
| 454 | target6 = self.igmp_recv_task(self.V_INF1, groups1, join_state1) |
| 455 | log.info('Interface is still receiving from multicast groups %s' %groups1) |
| 456 | else: |
| 457 | log.info('Ended test case') |
| 458 | mcastTraffic1.stop() |
| 459 | mcastTraffic2.stop() |
| 460 | self.onos_ctrl.deactivate() |
| 461 | |
| 462 | @deferred(timeout=MCAST_TRAFFIC_TIMEOUT+20) |
| 463 | def test_igmp_2joins_1leave_functionality(self): |
| 464 | '''This test is subscribing to two channels and sending leave for one channel''' |
| 465 | df = defer.Deferred() |
| 466 | def test_igmp_2joins_1leave(): |
| 467 | self.igmp_joins_leave_functionality(again_join = False, df = df) |
| 468 | df.callback(0) |
| 469 | reactor.callLater(0, test_igmp_2joins_1leave) |
| 470 | return df |
| 471 | |
| 472 | @deferred(timeout=MCAST_TRAFFIC_TIMEOUT+25) |
| 473 | def test_igmp_2joins_1leave_again_joins_functionality(self): |
| 474 | '''This test is subscribing to two channels and sending leave for one channel,again join to the same group''' |
| 475 | df = defer.Deferred() |
| 476 | def test_igmp_2joins_1leave_join_again(): |
| 477 | self.igmp_joins_leave_functionality(again_join = True, df = df) |
| 478 | df.callback(0) |
| 479 | reactor.callLater(0, test_igmp_2joins_1leave_join_again) |
| 480 | return df |
| 481 | |
| 482 | def igmp_not_src_list_functionality(self, df = None): |
| 483 | groups1 = (self.MGROUP1,) |
| 484 | groups2 = (self.MGROUP2,) |
| 485 | self.igmp_send_joins_different_groups_srclist(groups1 + groups2, |
| 486 | (['2.2.2.2', '3.3.3.3', '4.4.4.4'], ['2.2.2.2', '5.5.5.5']), |
| 487 | intf = self.V_INF1, delay = 2) |
| 488 | dst_mac = '01:00:5e:01:02:03' |
| 489 | src_ip = '6.6.6.6' |
| 490 | if df is None: |
| 491 | df = defer.Deferred() |
| 492 | igmpState1 = IGMPTestState(groups = groups1, df = df) |
| 493 | igmpStateRecv1 = IGMPTestState(groups = groups1, df = df) |
| 494 | mcastTraffic1 = McastTraffic(groups1, iface = 'veth2', dst_mac = dst_mac, |
| 495 | src_ip = src_ip, cb = self.send_mcast_cb, arg = igmpState1) |
| 496 | mcastTraffic1.start() |
| 497 | join_state1 = IGMPTestState(groups = groups1) |
| 498 | target1 = self.igmp_not_recv_task(self.V_INF1, groups1, join_state1) |
| 499 | assert target1 == 1, 'EXPECTED FAILURE' |
| 500 | log.info('Interface is not receiving from multicast groups %s' %groups1) |
| 501 | mcastTraffic1.stop() |
| 502 | self.onos_ctrl.deactivate() |
| 503 | |
| 504 | @deferred(timeout=MCAST_TRAFFIC_TIMEOUT+20) |
| 505 | def test_igmp_not_src_list_functionality(self): |
| 506 | '''This test is sending join with source list A,B,C and exclude A,D''' |
| 507 | df = defer.Deferred() |
| 508 | def igmp_not_src_list_functionality(): |
| 509 | self.igmp_not_src_list_functionality(df = df) |
| 510 | df.callback(0) |
| 511 | reactor.callLater(0, igmp_not_src_list_functionality) |
| 512 | return df |
| 513 | |
| 514 | def igmp_change_to_exclude_src_list_functionality(self, df = None): |
| 515 | groups1 = (self.MGROUP1,) |
| 516 | groups2 = (self.MGROUP2,) |
| 517 | self.igmp_send_joins_different_groups_srclist(groups1 + groups2, |
| 518 | (['2.2.2.2', '3.3.3.3', '4.4.4.4'], ['2.2.2.2', '5.5.5.5']), |
| 519 | intf = self.V_INF1, delay = 2) |
| 520 | dst_mac = '01:00:5e:01:02:03' |
| 521 | src_ip = '2.2.2.2' |
| 522 | if df is None: |
| 523 | df = defer.Deferred() |
| 524 | igmpState1 = IGMPTestState(groups = groups1, df = df) |
| 525 | igmpStateRecv1 = IGMPTestState(groups = groups1, df = df) |
| 526 | mcastTraffic1 = McastTraffic(groups1, iface= 'veth2', dst_mac = dst_mac, |
| 527 | src_ip = src_ip, cb = self.send_mcast_cb, arg = igmpState1) |
| 528 | mcastTraffic1.start() |
| 529 | join_state1 = IGMPTestState(groups = groups1) |
| 530 | target1 = self.igmp_recv_task(self.V_INF1, groups1, join_state1) |
| 531 | self.send_igmp_leave(groups = groups1, src_list = ['2.2.2.2'], iface = self.V_INF1, delay =2) |
| 532 | target2 = self.igmp_not_recv_task(self.V_INF1, groups1, join_state1) |
| 533 | assert target2 == 1, 'EXPECTED FAILURE' |
| 534 | log.info('Interface is not receiving from multicast groups %s after sending CHANGE_TO_EXCLUDE' %groups1) |
| 535 | mcastTraffic1.stop() |
| 536 | self.onos_ctrl.deactivate() |
| 537 | |
| 538 | @deferred(timeout=MCAST_TRAFFIC_TIMEOUT+10) |
| 539 | def test_igmp_change_to_exclude_src_list_functionality(self): |
| 540 | '''This test is sending join with source list A,B,C and exclude A,D''' |
| 541 | df = defer.Deferred() |
| 542 | def igmp_change_to_exclude_src_list_functionality(): |
| 543 | self.igmp_change_to_exclude_src_list_functionality(df = df) |
| 544 | df.callback(0) |
| 545 | reactor.callLater(0, igmp_change_to_exclude_src_list_functionality) |
| 546 | return df |
| 547 | |
| 548 | def igmp_change_to_include_src_list_functionality(self, df = None): |
| 549 | groups1 = (self.MGROUP1,) |
| 550 | groups2 = (self.MGROUP2,) |
| 551 | self.send_igmp_leave(groups = groups1, src_list = ['2.2.2.2', '3.3.3.3', '4.4.4.4'], |
| 552 | iface = self.V_INF1, delay = 2) |
| 553 | self.igmp_send_joins_different_groups_srclist(groups1 + groups2, |
| 554 | (['2.2.2.2', '3.3.3.3', '4.4.4.4'], ['6.6.6.6', '5.5.5.5']), |
| 555 | intf = self.V_INF1, delay = 2) |
| 556 | dst_mac = '01:00:5e:01:02:03' |
| 557 | src_ip = '2.2.2.2' |
| 558 | if df is None: |
| 559 | df = defer.Deferred() |
| 560 | igmpState1 = IGMPTestState(groups = groups1, df = df) |
| 561 | igmpStateRecv1 = IGMPTestState(groups = groups1, df = df) |
| 562 | mcastTraffic1 = McastTraffic(groups1, iface= 'veth2', dst_mac = dst_mac, |
| 563 | src_ip = src_ip, cb = self.send_mcast_cb, arg = igmpState1) |
| 564 | mcastTraffic1.start() |
| 565 | join_state1 = IGMPTestState(groups = groups1) |
| 566 | target1= self.igmp_not_recv_task(self.V_INF1, groups1, join_state1) |
| 567 | assert target1 == 1, 'EXPECTED FAILURE' |
| 568 | log.info('Interface is not receiving from multicast groups %s' %groups1) |
| 569 | self.igmp_send_joins_different_groups_srclist(groups1 + groups2, |
| 570 | (['2.2.2.2', '3.3.3.3', '4.4.4.4'], ['6.6.6.6', '5.5.5.5']), |
| 571 | intf = self.V_INF1, delay = 2) |
| 572 | target2 = self.igmp_recv_task(self.V_INF1, groups1, join_state1) |
| 573 | log.info('Interface is receiving from multicast groups %s after send Change to include message' %groups1) |
| 574 | mcastTraffic1.stop() |
| 575 | self.onos_ctrl.deactivate() |
| 576 | |
| 577 | @deferred(timeout=MCAST_TRAFFIC_TIMEOUT+10) |
| 578 | def test_igmp_change_to_include_src_list_functionality(self): |
| 579 | '''This test is sending join with source list A,B,C and exclude D,E''' |
| 580 | df = defer.Deferred() |
| 581 | def igmp_change_to_include_src_list_functionality(): |
| 582 | self.igmp_change_to_include_src_list_functionality(df = df) |
| 583 | df.callback(0) |
| 584 | reactor.callLater(0, igmp_change_to_include_src_list_functionality) |
| 585 | return df |
| 586 | |
| 587 | def igmp_new_src_list_functionality(self, df = None): |
| 588 | groups1 = (self.MGROUP1,) |
| 589 | groups2 = (self.MGROUP2,) |
| 590 | self.igmp_send_joins_different_groups_srclist(groups1+groups2, |
| 591 | (['2.2.2.2', '3.3.3.3', '4.4.4.4'], ['2.2.2.2', '5.5.5.5']), |
| 592 | intf = self.V_INF1, delay = 2) |
| 593 | dst_mac = '01:00:5e:01:02:03' |
| 594 | src_ip = '6.6.6.6' |
| 595 | if df is None: |
| 596 | df = defer.Deferred() |
| 597 | igmpState1 = IGMPTestState(groups = groups1, df = df) |
| 598 | igmpStateRecv1 = IGMPTestState(groups = groups1, df = df) |
| 599 | mcastTraffic1 = McastTraffic(groups1, iface= 'veth2', dst_mac = dst_mac, |
| 600 | src_ip = src_ip, cb = self.send_mcast_cb, arg = igmpState1) |
| 601 | mcastTraffic1.start() |
| 602 | join_state1 = IGMPTestState(groups = groups1) |
| 603 | target1 = self.igmp_not_recv_task(self.V_INF1, groups1, join_state1) |
| 604 | assert target1 == 1, 'EXPECTED FAILURE' |
| 605 | log.info('Interface is not receiving from multicast groups %s' %groups1) |
| 606 | self.igmp_send_joins_different_groups_srclist(groups1 + groups2, |
| 607 | (['6.6.6.6', '3.3.3.3', '4.4.4.4'], ['2.2.2.2', '5.5.5.5']), |
| 608 | intf = self.V_INF1, delay = 2) |
| 609 | target2 = self.igmp_recv_task(self.V_INF1, groups1, join_state1) |
| 610 | log.info('Interface is receiving from multicast groups %s after sending join with new source list' %groups1) |
| 611 | mcastTraffic1.stop() |
| 612 | self.onos_ctrl.deactivate() |
| 613 | |
| 614 | @deferred(timeout=MCAST_TRAFFIC_TIMEOUT+10) |
| 615 | def test_igmp_new_src_list_functionality(self): |
| 616 | '''This test is sending join with source list A,B,C and exclude A,D''' |
| 617 | df = defer.Deferred() |
| 618 | def igmp_new_src_list_functionality(): |
| 619 | self.igmp_new_src_list_functionality(df = df) |
| 620 | df.callback(0) |
| 621 | reactor.callLater(0, igmp_new_src_list_functionality) |
| 622 | return df |
| 623 | |
| 624 | def igmp_block_old_src_list_functionality(self, df = None): |
| 625 | groups1 = (self.MGROUP1,) |
| 626 | groups2 = (self.MGROUP2,) |
| 627 | groups = groups1 + groups2 |
| 628 | self.igmp_send_joins_different_groups_srclist(groups, |
| 629 | (['2.2.2.2', '3.3.3.3', '4.4.4.4'], ['2.2.2.2', '5.5.5.5']), |
| 630 | intf = self.V_INF1, delay = 2) |
| 631 | dst_mac = '01:00:5e:02:02:03' |
| 632 | src_ip = '5.5.5.5' |
| 633 | if df is None: |
| 634 | df = defer.Deferred() |
| 635 | igmpState1 = IGMPTestState(groups = groups2, df = df) |
| 636 | igmpStateRecv1 = IGMPTestState(groups = groups2, df = df) |
| 637 | mcastTraffic1 = McastTraffic(groups2, iface= 'veth2', dst_mac = dst_mac, |
| 638 | src_ip = src_ip, cb = self.send_mcast_cb, arg = igmpState1) |
| 639 | mcastTraffic1.start() |
| 640 | join_state1 = IGMPTestState(groups = groups2) |
| 641 | target1 = self.igmp_recv_task(self.V_INF1, groups2, join_state1) |
| 642 | log.info('Interface is receiving from multicast groups %s' %groups2) |
| 643 | self.igmp_send_joins_different_groups_srclist(groups, |
| 644 | (['6.6.6.6', '3.3.3.3', '4.4.4.4'], ['2.2.2.2', '7.7.7.7']), |
| 645 | intf = self.V_INF1, delay = 2) |
| 646 | target2 = self.igmp_not_recv_task(self.V_INF1, groups2, join_state1) |
| 647 | assert target2 == 1, 'EXPECTED FAILURE' |
| 648 | log.info('Interface is not receiving from multicast groups %s after sending join with block old source list' %groups2) |
| 649 | mcastTraffic1.stop() |
| 650 | self.onos_ctrl.deactivate() |
| 651 | |
| 652 | @deferred(timeout=MCAST_TRAFFIC_TIMEOUT+20) |
| 653 | def test_igmp_block_old_src_list_functionality(self): |
| 654 | '''This test is sending join with source list A,B,C and exclude A,D''' |
| 655 | df = defer.Deferred() |
| 656 | def igmp_block_old_src_list_functionality(): |
| 657 | self.igmp_block_old_src_list_functionality(df = df) |
| 658 | df.callback(0) |
| 659 | reactor.callLater(0, igmp_block_old_src_list_functionality) |
| 660 | return df |
| 661 | |
| 662 | def igmp_include_empty_src_list_functionality(self, df = None): |
| 663 | print'This test is sending join with source list A,B,C and exclude D,F,G' |
| 664 | groups1 = (self.MGROUP1,) |
| 665 | groups2 = (self.MGROUP2,) |
| 666 | groups = groups1 + groups2 |
| 667 | self.igmp_send_joins_different_groups_srclist(groups, |
| 668 | (['2.2.2.2', '3.3.3.3', '4.4.4.4'], ['']), |
| 669 | intf = self.V_INF1, delay = 2) |
| 670 | dst_mac = '01:00:5e:02:02:03' |
| 671 | src_ip = '5.5.5.5' |
| 672 | if df is None: |
| 673 | df = defer.Deferred() |
| 674 | igmpState1 = IGMPTestState(groups = groups2, df = df) |
| 675 | igmpStateRecv1 = IGMPTestState(groups = groups2, df = df) |
| 676 | mcastTraffic1 = McastTraffic(groups2, iface= 'veth2', dst_mac = dst_mac, |
| 677 | src_ip = src_ip, cb = self.send_mcast_cb, arg = igmpState1) |
| 678 | mcastTraffic1.start() |
| 679 | join_state1 = IGMPTestState(groups = groups2) |
| 680 | target1 = self.igmp_not_recv_task(self.V_INF1, groups2, join_state1) |
| 681 | assert target1==1, 'EXPECTED FAILURE' |
| 682 | log.info('Interface is not receiving from multicast groups %s when we sent join with source list is empty' %groups2) |
| 683 | mcastTraffic1.stop() |
| 684 | self.onos_ctrl.deactivate() |
| 685 | |
| 686 | @deferred(timeout=MCAST_TRAFFIC_TIMEOUT+20) |
| 687 | def ztest_igmp_include_empty_src_list_functionality(self): |
| 688 | '''This test is sending join with source list A,B,C and exclude D,F,G''' |
| 689 | '''Disabling this test as scapy IGMP doesn't work with empty source lists''' |
| 690 | df = defer.Deferred() |
| 691 | def igmp_include_empty_src_list_functionality(): |
| 692 | self.igmp_include_empty_src_list_functionality(df = df) |
| 693 | df.callback(0) |
| 694 | reactor.callLater(0, igmp_include_empty_src_list_functionality) |
| 695 | return df |
| 696 | |
| 697 | def igmp_exclude_empty_src_list_functionality(self, df = None): |
| 698 | groups1 = (self.MGROUP1,) |
| 699 | groups2 = (self.MGROUP2,) |
| 700 | groups = groups1 + groups2 |
| 701 | self.send_igmp_leave(groups = groups2, src_list = [''], iface = self.V_INF1, delay = 2) |
| 702 | dst_mac = '01:00:5e:02:02:03' |
| 703 | src_ip = '5.5.5.5' |
| 704 | if df is None: |
| 705 | df = defer.Deferred() |
| 706 | igmpState1 = IGMPTestState(groups = groups2, df = df) |
| 707 | igmpStateRecv1 = IGMPTestState(groups = groups2, df = df) |
| 708 | mcastTraffic1 = McastTraffic(groups2, iface= 'veth2', dst_mac = dst_mac, |
| 709 | src_ip = src_ip, cb = self.send_mcast_cb, arg = igmpState1) |
| 710 | mcastTraffic1.start() |
| 711 | join_state1 = IGMPTestState(groups = groups2) |
| 712 | target1 = self.igmp_recv_task(self.V_INF1, groups2, join_state1) |
| 713 | log.info('Interface is receiving multicast groups %s' %groups2) |
| 714 | mcastTraffic1.stop() |
| 715 | self.onos_ctrl.deactivate() |
| 716 | |
| 717 | @deferred(timeout=MCAST_TRAFFIC_TIMEOUT+20) |
| 718 | def ztest_igmp_exclude_empty_src_list_functionality(self): |
| 719 | '''This test is sending join with source list A,B,C and exclude D,F,G''' |
| 720 | '''Disabling this test case since scapy IGMP doesn't work with empty src list''' |
| 721 | df = defer.Deferred() |
| 722 | def igmp_exclude_empty_src_list_functionality(): |
| 723 | self.igmp_exclude_empty_src_list_functionality() |
| 724 | df.callback(0) |
| 725 | reactor.callLater(0, igmp_exclude_empty_src_list_functionality) |
| 726 | return df |
| 727 | |
| 728 | def igmp_join_sourceip_0_0_0_0_functionality(self, df = None): |
| 729 | groups1 = (self.MGROUP1,) |
| 730 | groups2 = (self.MGROUP2,) |
| 731 | groups = groups1 + groups2 |
| 732 | ip_src = '0.0.0.0' |
| 733 | self.igmp_send_joins_different_groups_srclist(groups, |
| 734 | (['2.2.2.2', '3.3.3.3', '4.4.4.4'], ['5.5.5.5']), |
| 735 | intf = self.V_INF1, delay = 2, ip_src = ip_src) |
| 736 | ip_src = self.IP_SRC |
| 737 | dst_mac = '01:00:5e:02:02:03' |
| 738 | src_ip = '5.5.5.5' |
| 739 | if df is None: |
| 740 | df = defer.Deferred() |
| 741 | igmpState1 = IGMPTestState(groups = groups2, df = df) |
| 742 | igmpStateRecv1 = IGMPTestState(groups = groups2, df = df) |
| 743 | mcastTraffic1 = McastTraffic(groups2, iface= 'veth2', dst_mac = dst_mac, |
| 744 | src_ip = src_ip, cb = self.send_mcast_cb, arg = igmpState1) |
| 745 | mcastTraffic1.start() |
| 746 | join_state1 = IGMPTestState(groups = groups2) |
| 747 | target1 = self.igmp_recv_task(self.V_INF1, groups2, join_state1) |
| 748 | log.info('Interface is receiving from multicast groups %s when we sent join with source IP is 0.0.0.0' %groups2) |
| 749 | mcastTraffic1.stop() |
| 750 | self.onos_ctrl.deactivate() |
| 751 | |
| 752 | @deferred(timeout=MCAST_TRAFFIC_TIMEOUT+20) |
| 753 | def test_igmp_join_sourceip_0_0_0_0_functionality(self): |
| 754 | '''This test is sending join with source list A,B,C and exclude D,F,G with source IP as 0.0.0.0''' |
| 755 | df = defer.Deferred() |
| 756 | def igmp_join_sourceip_0_0_0_0_functionality(): |
| 757 | self.igmp_join_sourceip_0_0_0_0_functionality(df = df) |
| 758 | df.callback(0) |
| 759 | reactor.callLater(0, igmp_join_sourceip_0_0_0_0_functionality) |
| 760 | return df |
| 761 | |
Chetan Gaonker | 586fec3 | 2016-04-29 17:33:54 -0700 | [diff] [blame] | 762 | def igmp_invalid_join_packet_functionality(self, df = None): |
| 763 | groups1 = (self.MGROUP1,) |
| 764 | groups2 = (self.MINVALIDGROUP1,) |
| 765 | groups = groups1 + groups2 |
| 766 | ip_src = '1.1.1.1' |
| 767 | self.igmp_send_joins_different_groups_srclist(groups, |
| 768 | (['2.2.2.2', '3.3.3.3', '4.4.4.4'], ['5.5.5.5']), |
| 769 | intf = self.V_INF1, delay = 2, ip_src = ip_src) |
| 770 | ip_src = self.IP_SRC |
| 771 | dst_mac = '01:00:5e:02:02:03' |
| 772 | src_ip = '5.5.5.5' |
| 773 | if df is None: |
| 774 | df = defer.Deferred() |
| 775 | igmpState1 = IGMPTestState(groups = groups2, df = df) |
| 776 | igmpStateRecv1 = IGMPTestState(groups = groups2, df = df) |
| 777 | mcastTraffic1 = McastTraffic(groups2, iface= 'veth2', dst_mac = dst_mac, |
| 778 | src_ip = src_ip, cb = self.send_mcast_cb, arg = igmpState1) |
| 779 | mcastTraffic1.start() |
| 780 | join_state1 = IGMPTestState(groups = groups2) |
| 781 | target1 = self.igmp_not_recv_task(self.V_INF1, groups2, join_state1) |
| 782 | assert target1==1, 'EXPECTED FAILURE' |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 783 | log.info('Interface is not receiving data from multicast groups %s when we sent invalid join packet ' %groups2) |
Chetan Gaonker | 586fec3 | 2016-04-29 17:33:54 -0700 | [diff] [blame] | 784 | mcastTraffic1.stop() |
| 785 | self.onos_ctrl.deactivate() |
| 786 | |
| 787 | @deferred(timeout=MCAST_TRAFFIC_TIMEOUT+20) |
| 788 | def test_igmp_invalid_join_packet_functionality(self): |
| 789 | '''This test is sending invalid join with source list A,B,C and exclude D,F,G with multicast group as 255.255.255.255''' |
| 790 | df = defer.Deferred() |
| 791 | def igmp_invalid_join_packet_functionality(): |
| 792 | self.igmp_invalid_join_packet_functionality(df = df) |
| 793 | df.callback(0) |
| 794 | reactor.callLater(0, igmp_invalid_join_packet_functionality) |
| 795 | return df |
| 796 | |
| 797 | def igmp_join_data_receiving_during_subscriber_link_down_up_functionality(self, df = None): |
| 798 | groups1 = (self.MGROUP1,) |
| 799 | groups2 = (self.MGROUP2,) |
| 800 | groups = groups1 + groups2 |
| 801 | ip_src = '1.1.1.1' |
| 802 | self.igmp_send_joins_different_groups_srclist(groups, |
| 803 | (['2.2.2.2', '3.3.3.3', '4.4.4.4'], ['5.5.5.5']), |
| 804 | intf = self.V_INF1, delay = 2, ip_src = ip_src) |
| 805 | ip_src = self.IP_SRC |
| 806 | dst_mac = '01:00:5e:02:02:03' |
| 807 | src_ip = '5.5.5.5' |
| 808 | if df is None: |
| 809 | df = defer.Deferred() |
| 810 | igmpState1 = IGMPTestState(groups = groups2, df = df) |
| 811 | igmpStateRecv1 = IGMPTestState(groups = groups2, df = df) |
| 812 | mcastTraffic1 = McastTraffic(groups2, iface= 'veth2', dst_mac = dst_mac, |
| 813 | src_ip = src_ip, cb = self.send_mcast_cb, arg = igmpState1) |
| 814 | mcastTraffic1.start() |
| 815 | join_state1 = IGMPTestState(groups = groups2) |
| 816 | target1 = self.igmp_recv_task(self.V_INF1, groups2, join_state1) |
| 817 | log.info('Interface is receiving data from multicast groups, before bringing it down self.V_INF1=%s ' %self.V_INF1) |
| 818 | os.system('ifconfig '+self.V_INF1+' down') |
| 819 | log.info(' the self.V_INF1 %s is down now ' %self.V_INF1) |
| 820 | os.system('ifconfig '+self.V_INF1) |
| 821 | time.sleep(10) |
| 822 | #target1 = self.igmp_not_recv_task(self.V_INF1, groups2, join_state1) |
| 823 | #assert target1==1, 'EXPECTED FAILURE' |
| 824 | #log.info('Interface is not receiving from multicast groups %s when we shutdown the subscriber interface ' %groups2) |
| 825 | os.system('ifconfig '+self.V_INF1+' up') |
| 826 | os.system('ifconfig '+self.V_INF1) |
| 827 | log.info(' the self.V_INF1 %s is up now ' %self.V_INF1) |
| 828 | #target1 = self.igmp_not_recv_task(self.V_INF1, groups2, join_state1) |
| 829 | #assert target1==0, 'EXPECTED FAILURE' |
| 830 | #log.info('Interface is not receiving from multicast groups %s when we shutdown the subscriber interface ' %groups2) |
| 831 | target1 = self.igmp_recv_task(self.V_INF1, groups2, join_state1) |
| 832 | log.info('Interface is receiving data from multicast groups %s when we bring up interface ' %groups2) |
| 833 | mcastTraffic1.stop() |
| 834 | self.onos_ctrl.deactivate() |
| 835 | |
| 836 | |
| 837 | @deferred(timeout=MCAST_TRAFFIC_TIMEOUT+20) |
| 838 | def test_igmp_join_data_receiving_during_subscriber_link_down_up_functionality(self): |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 839 | '''This test is sending join with source list A,B,C and exclude D,F,G with valid multicast group during receiving data, shutdown the data receiving port ''' |
Chetan Gaonker | 586fec3 | 2016-04-29 17:33:54 -0700 | [diff] [blame] | 840 | df = defer.Deferred() |
| 841 | def igmp_join_data_receiving_during_subscriber_link_down_up_functionality(): |
| 842 | self.igmp_join_data_receiving_during_subscriber_link_down_up_functionality(df = df) |
| 843 | df.callback(0) |
| 844 | reactor.callLater(0, igmp_join_data_receiving_during_subscriber_link_down_up_functionality) |
| 845 | return df |
| 846 | |
| 847 | |
| 848 | def igmp_invalidClassDIP_join_packet_functionality(self, df = None): |
| 849 | groups1 = (self.MGROUP1,) |
| 850 | groups2 = (self.MINVALIDGROUP2,) |
| 851 | groups = groups1 + groups2 |
| 852 | ip_src = '1.1.1.1' |
| 853 | self.igmp_send_joins_different_groups_srclist(groups, |
| 854 | (['2.2.2.2', '3.3.3.3', '4.4.4.4'], ['5.5.5.5']), |
| 855 | intf = self.V_INF1, delay = 2, ip_src = ip_src) |
| 856 | ip_src = self.IP_SRC |
| 857 | dst_mac = '01:00:5e:02:02:03' |
| 858 | src_ip = '5.5.5.5' |
| 859 | if df is None: |
| 860 | df = defer.Deferred() |
| 861 | igmpState1 = IGMPTestState(groups = groups2, df = df) |
| 862 | igmpStateRecv1 = IGMPTestState(groups = groups2, df = df) |
| 863 | mcastTraffic1 = McastTraffic(groups2, iface= 'veth2', dst_mac = dst_mac, |
| 864 | src_ip = src_ip, cb = self.send_mcast_cb, arg = igmpState1) |
| 865 | mcastTraffic1.start() |
| 866 | join_state1 = IGMPTestState(groups = groups2) |
| 867 | target1 = self.igmp_not_recv_task(self.V_INF1, groups2, join_state1) |
| 868 | assert target1==1, 'EXPECTED FAILURE' |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 869 | log.info('Interface is not receiving data from multicast groups %s when we send invalid join packet ' %groups2) |
Chetan Gaonker | 586fec3 | 2016-04-29 17:33:54 -0700 | [diff] [blame] | 870 | mcastTraffic1.stop() |
| 871 | self.onos_ctrl.deactivate() |
| 872 | |
| 873 | @deferred(timeout=MCAST_TRAFFIC_TIMEOUT+20) |
| 874 | def test_igmp_invalidClassDIP_join_packet_functionality(self): |
| 875 | '''This test is sending invalid join with source list A,B,C and exclude D,F,G with multicast group as 239.255.255.255''' |
| 876 | df = defer.Deferred() |
| 877 | def igmp_invalidClassDIP_join_packet_functionality(): |
| 878 | self.igmp_invalidClassDIP_join_packet_functionality(df = df) |
| 879 | df.callback(0) |
| 880 | reactor.callLater(0, igmp_invalidClassDIP_join_packet_functionality) |
| 881 | return df |
| 882 | |
| 883 | def igmp_invalidClassDIP_as_srclistIP_join_packet_functionality(self, df = None): |
| 884 | groups1 = (self.MGROUP1,) |
| 885 | groups2 = (self.MGROUP2,) |
| 886 | groups = groups1 + groups2 |
| 887 | ip_src = '1.1.1.1' |
| 888 | self.igmp_send_joins_different_groups_srclist(groups, |
| 889 | (['2.2.2.2', '3.3.3.3', '4.4.4.4'], ['239.5.5.5']), |
| 890 | intf = self.V_INF1, delay = 2, ip_src = ip_src) |
| 891 | ip_src = self.IP_SRC |
| 892 | dst_mac = '01:00:5e:02:02:03' |
| 893 | src_ip = '5.5.5.5' |
| 894 | if df is None: |
| 895 | df = defer.Deferred() |
| 896 | igmpState1 = IGMPTestState(groups = groups2, df = df) |
| 897 | igmpStateRecv1 = IGMPTestState(groups = groups2, df = df) |
| 898 | mcastTraffic1 = McastTraffic(groups2, iface= 'veth2', dst_mac = dst_mac, |
| 899 | src_ip = src_ip, cb = self.send_mcast_cb, arg = igmpState1) |
| 900 | mcastTraffic1.start() |
| 901 | join_state1 = IGMPTestState(groups = groups2) |
| 902 | target1 = self.igmp_not_recv_task(self.V_INF1, groups2, join_state1) |
| 903 | assert target1==1, 'EXPECTED FAILURE' |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 904 | log.info('Interface is not receiving data from multicast groups %s when we send invalid join packet ' %groups2) |
Chetan Gaonker | 586fec3 | 2016-04-29 17:33:54 -0700 | [diff] [blame] | 905 | mcastTraffic1.stop() |
| 906 | self.onos_ctrl.deactivate() |
| 907 | |
| 908 | @deferred(timeout=MCAST_TRAFFIC_TIMEOUT+20) |
| 909 | def test_igmp_invalidClassDIP_as_srclistIP_join_packet_functionality(self): |
| 910 | '''This test is sending invalid join with source list A,B,C and exclude D,F,G with source list as 239.5.5.5''' |
| 911 | df = defer.Deferred() |
| 912 | def igmp_invalidClassDIP_as_srclistIP_join_packet_functionality(): |
| 913 | self.igmp_invalidClassDIP_as_srclistIP_join_packet_functionality(df = df) |
| 914 | df.callback(0) |
| 915 | reactor.callLater(0, igmp_invalidClassDIP_as_srclistIP_join_packet_functionality) |
| 916 | return df |
Chetan Gaonker | f72ca40 | 2016-05-02 16:29:32 -0700 | [diff] [blame] | 917 | |
| 918 | def send_igmp_join_listeningQuery(self, groups, src_list = ['1.2.3.4'], ip_pkt = None, iface = 'veth0', delay = 2): |
| 919 | self.onos_ssm_table_load(groups, src_list) |
| 920 | igmp = IGMPv3(type = IGMP_TYPE_V3_MEMBERSHIP_REPORT, |
| 921 | max_resp_code=30, |
| 922 | gaddr=self.IP_DST) |
| 923 | for g in groups: |
| 924 | gr = IGMPv3gr(rtype=IGMP_V3_GR_TYPE_EXCLUDE, mcaddr=g) |
| 925 | gr.sources = src_list |
| 926 | igmp.grps.append(gr) |
| 927 | if ip_pkt is None: |
| 928 | ip_pkt = self.igmp_eth/self.igmp_ip |
| 929 | pkt = ip_pkt/igmp |
| 930 | IGMPv3.fixup(pkt) |
| 931 | resp = srp1(pkt, iface=iface) |
| 932 | resp[0].summary() |
| 933 | if delay != 0: |
| 934 | time.sleep(delay) |