A R Karthick | 338268f | 2016-06-21 17:12:13 -0700 | [diff] [blame] | 1 | # |
Chetan Gaonker | cfcce78 | 2016-05-10 10:10:42 -0700 | [diff] [blame] | 2 | # Copyright 2016-present Ciena Corporation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
A R Karthick | 338268f | 2016-06-21 17:12:13 -0700 | [diff] [blame] | 7 | # |
Chetan Gaonker | cfcce78 | 2016-05-10 10:10:42 -0700 | [diff] [blame] | 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
A R Karthick | 338268f | 2016-06-21 17:12:13 -0700 | [diff] [blame] | 9 | # |
Chetan Gaonker | cfcce78 | 2016-05-10 10:10:42 -0700 | [diff] [blame] | 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | # |
Chetan Gaonker | b424ff8 | 2016-03-08 12:11:12 -0800 | [diff] [blame] | 16 | import threading |
| 17 | import sys |
| 18 | import os |
| 19 | import time |
| 20 | import monotonic |
| 21 | import random |
A.R Karthick | 2e99c47 | 2017-03-22 19:13:51 -0700 | [diff] [blame] | 22 | import logging |
| 23 | logging.getLogger('scapy.runtime').setLevel(logging.ERROR) |
Chetan Gaonker | b424ff8 | 2016-03-08 12:11:12 -0800 | [diff] [blame] | 24 | from scapy.all import * |
| 25 | from McastTraffic import * |
| 26 | from IGMP import * |
| 27 | from OnosCtrl import OnosCtrl |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 28 | from CordTestUtils import log_test |
Chetan Gaonker | b424ff8 | 2016-03-08 12:11:12 -0800 | [diff] [blame] | 29 | from nose.tools import * |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 30 | log_test.setLevel('DEBUG') |
Chetan Gaonker | b424ff8 | 2016-03-08 12:11:12 -0800 | [diff] [blame] | 31 | |
| 32 | conf.verb = 0 |
| 33 | |
| 34 | class IgmpChannel: |
| 35 | |
| 36 | IGMP_DST_MAC = "01:00:5e:00:01:01" |
| 37 | IGMP_SRC_MAC = "5a:e1:ac:ec:4d:a1" |
| 38 | IP_SRC = '1.2.3.4' |
| 39 | IP_DST = '224.0.1.1' |
| 40 | igmp_eth = Ether(dst = IGMP_DST_MAC, src = IGMP_SRC_MAC, type = ETH_P_IP) |
| 41 | igmp_ip = IP(dst = IP_DST, src = IP_SRC) |
A R Karthick | 338268f | 2016-06-21 17:12:13 -0700 | [diff] [blame] | 42 | ssm_list = [] |
Chetan Gaonker | b424ff8 | 2016-03-08 12:11:12 -0800 | [diff] [blame] | 43 | |
Thangavelu K S | 8e41308 | 2017-07-13 20:02:14 +0000 | [diff] [blame] | 44 | def __init__(self, iface = 'veth0', ssm_list = [], src_list = None, delay = 2,controller=None): |
| 45 | |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 46 | self.controller=controller |
Chetan Gaonker | b424ff8 | 2016-03-08 12:11:12 -0800 | [diff] [blame] | 47 | self.iface = iface |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 48 | self.ssm_list += ssm_list |
Thangavelu K S | 8e41308 | 2017-07-13 20:02:14 +0000 | [diff] [blame] | 49 | if src_list is None: |
| 50 | self.src_list = ['1.2.3.4'] |
| 51 | else: |
| 52 | self.src_list = src_list |
Chetan Gaonker | b424ff8 | 2016-03-08 12:11:12 -0800 | [diff] [blame] | 53 | self.delay = delay |
A.R Karthick | 401a1ed | 2017-05-18 11:08:27 -0700 | [diff] [blame] | 54 | self.onos_ctrl = OnosCtrl('org.opencord.igmp',controller=self.controller) |
Chetan Gaonker | b424ff8 | 2016-03-08 12:11:12 -0800 | [diff] [blame] | 55 | self.onos_ctrl.activate() |
A R Karthick | 338268f | 2016-06-21 17:12:13 -0700 | [diff] [blame] | 56 | |
Thangavelu K S | 8e41308 | 2017-07-13 20:02:14 +0000 | [diff] [blame] | 57 | def igmp_load_ssm_config(self, ssm_list = [], src_list = None): |
A R Karthick | 2f4e0ba | 2017-07-17 10:55:36 -0700 | [diff] [blame] | 58 | if src_list is None: |
| 59 | src_list = self.src_list |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 60 | if not ssm_list: |
| 61 | ssm_list = self.ssm_list |
Thangavelu K S | 8e41308 | 2017-07-13 20:02:14 +0000 | [diff] [blame] | 62 | self.ssm_table_load(ssm_list, src_list = src_list) |
Chetan Gaonker | b424ff8 | 2016-03-08 12:11:12 -0800 | [diff] [blame] | 63 | |
Thangavelu K S | 8e41308 | 2017-07-13 20:02:14 +0000 | [diff] [blame] | 64 | def igmp_join(self, groups, src_list = None, record_type = None): |
A R Karthick | 2f4e0ba | 2017-07-17 10:55:36 -0700 | [diff] [blame] | 65 | if src_list is None: |
| 66 | src_list = self.src_list |
Thangavelu K S | 8e41308 | 2017-07-13 20:02:14 +0000 | [diff] [blame] | 67 | if record_type is None: |
| 68 | record_type = IGMP_V3_GR_TYPE_INCLUDE |
Chetan Gaonker | b424ff8 | 2016-03-08 12:11:12 -0800 | [diff] [blame] | 69 | igmp = IGMPv3(type = IGMP_TYPE_V3_MEMBERSHIP_REPORT, max_resp_code=30, |
| 70 | gaddr='224.0.1.1') |
| 71 | for g in groups: |
Thangavelu K S | 8e41308 | 2017-07-13 20:02:14 +0000 | [diff] [blame] | 72 | gr = IGMPv3gr(rtype=record_type, mcaddr=g) |
| 73 | gr.sources = src_list |
Chetan Gaonker | b424ff8 | 2016-03-08 12:11:12 -0800 | [diff] [blame] | 74 | igmp.grps.append(gr) |
| 75 | |
| 76 | pkt = self.igmp_eth/self.igmp_ip/igmp |
| 77 | IGMPv3.fixup(pkt) |
| 78 | sendp(pkt, iface=self.iface) |
| 79 | if self.delay != 0: |
| 80 | time.sleep(self.delay) |
| 81 | |
Thangavelu K S | 8e41308 | 2017-07-13 20:02:14 +0000 | [diff] [blame] | 82 | def igmp_leave(self, groups, src_list = None): |
A R Karthick | 2f4e0ba | 2017-07-17 10:55:36 -0700 | [diff] [blame] | 83 | if src_list is None: |
| 84 | src_list = self.src_list |
Chetan Gaonker | b424ff8 | 2016-03-08 12:11:12 -0800 | [diff] [blame] | 85 | igmp = IGMPv3(type = IGMP_TYPE_V3_MEMBERSHIP_REPORT, max_resp_code=30, |
| 86 | gaddr='224.0.1.1') |
| 87 | for g in groups: |
Chetan Gaonker | 38737f8 | 2016-05-11 17:44:17 -0700 | [diff] [blame] | 88 | gr = IGMPv3gr(rtype=IGMP_V3_GR_TYPE_EXCLUDE, mcaddr=g) |
Thangavelu K S | 8e41308 | 2017-07-13 20:02:14 +0000 | [diff] [blame] | 89 | gr.sources = src_list |
Chetan Gaonker | b424ff8 | 2016-03-08 12:11:12 -0800 | [diff] [blame] | 90 | igmp.grps.append(gr) |
| 91 | |
| 92 | pkt = self.igmp_eth/self.igmp_ip/igmp |
| 93 | IGMPv3.fixup(pkt) |
| 94 | sendp(pkt, iface = self.iface) |
| 95 | if self.delay != 0: |
| 96 | time.sleep(self.delay) |
| 97 | |
| 98 | def onos_load_config(self, config): |
ChetanGaonker | 689b386 | 2016-10-17 16:25:01 -0700 | [diff] [blame] | 99 | status, code = OnosCtrl.config(config,controller=self.controller) |
Chetan Gaonker | b424ff8 | 2016-03-08 12:11:12 -0800 | [diff] [blame] | 100 | if status is False: |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 101 | log_test.info('JSON config request returned status %d' %code) |
Chetan Gaonker | b424ff8 | 2016-03-08 12:11:12 -0800 | [diff] [blame] | 102 | time.sleep(2) |
| 103 | |
Thangavelu K S | 8e41308 | 2017-07-13 20:02:14 +0000 | [diff] [blame] | 104 | def ssm_table_load(self, groups, src_list = None): |
A R Karthick | 2f4e0ba | 2017-07-17 10:55:36 -0700 | [diff] [blame] | 105 | return |
| 106 | if src_list is None: |
| 107 | src_list = self.src_list |
A.R Karthick | 401a1ed | 2017-05-18 11:08:27 -0700 | [diff] [blame] | 108 | ssm_dict = {'apps' : { 'org.opencord.igmp' : { 'ssmTranslate' : [] } } } |
| 109 | ssm_xlate_list = ssm_dict['apps']['org.opencord.igmp']['ssmTranslate'] |
Chetan Gaonker | b424ff8 | 2016-03-08 12:11:12 -0800 | [diff] [blame] | 110 | for g in groups: |
Thangavelu K S | 8e41308 | 2017-07-13 20:02:14 +0000 | [diff] [blame] | 111 | for s in src_list: |
Chetan Gaonker | b424ff8 | 2016-03-08 12:11:12 -0800 | [diff] [blame] | 112 | d = {} |
| 113 | d['source'] = s |
| 114 | d['group'] = g |
| 115 | ssm_xlate_list.append(d) |
| 116 | self.onos_load_config(ssm_dict) |
| 117 | |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 118 | def cord_port_table_load(self, cord_port_map): |
A R Karthick | 2f4e0ba | 2017-07-17 10:55:36 -0700 | [diff] [blame] | 119 | return |
Chetan Gaonker | a58ab6e | 2016-03-23 15:04:20 -0700 | [diff] [blame] | 120 | cord_group_dict = {'apps' : { 'org.ciena.cordigmp' : { 'cordIgmpTranslate' : [] } } } |
| 121 | cord_group_xlate_list = cord_group_dict['apps']['org.ciena.cordigmp']['cordIgmpTranslate'] |
| 122 | for group, ports in cord_port_map.items(): |
| 123 | d = {} |
| 124 | d['group'] = group |
| 125 | d['inputPort'] = ports[0] |
| 126 | d['outputPort'] = ports[1] |
| 127 | cord_group_xlate_list.append(d) |
| 128 | self.onos_load_config(cord_group_dict) |
| 129 | |
Chetan Gaonker | b424ff8 | 2016-03-08 12:11:12 -0800 | [diff] [blame] | 130 | class Channels(IgmpChannel): |
| 131 | Stopped = 0 |
| 132 | Started = 1 |
| 133 | Idle = 0 |
| 134 | Joined = 1 |
Thangavelu K S | 8e41308 | 2017-07-13 20:02:14 +0000 | [diff] [blame] | 135 | def __init__(self, num, channel_start = 0, iface = 'veth0', iface_mcast = 'veth2', mcast_cb = None, src_list = None): |
Chetan Gaonker | b424ff8 | 2016-03-08 12:11:12 -0800 | [diff] [blame] | 136 | self.num = num |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 137 | self.channel_start = channel_start |
| 138 | self.channels = self.generate(self.num, self.channel_start) |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 139 | self.group_channel_map = {} |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 140 | #assert_equal(len(self.channels), self.num) |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 141 | for i in range(self.num): |
| 142 | self.group_channel_map[self.channels[i]] = i |
Chetan Gaonker | b424ff8 | 2016-03-08 12:11:12 -0800 | [diff] [blame] | 143 | self.state = self.Stopped |
| 144 | self.streams = None |
| 145 | self.channel_states = {} |
| 146 | self.last_chan = None |
Chetan Gaonker | b424ff8 | 2016-03-08 12:11:12 -0800 | [diff] [blame] | 147 | self.iface_mcast = iface_mcast |
| 148 | self.mcast_cb = mcast_cb |
Thangavelu K S | 8e41308 | 2017-07-13 20:02:14 +0000 | [diff] [blame] | 149 | self.src_list = src_list |
Chetan Gaonker | b424ff8 | 2016-03-08 12:11:12 -0800 | [diff] [blame] | 150 | for c in range(self.num): |
| 151 | self.channel_states[c] = [self.Idle] |
Thangavelu K S | 8e41308 | 2017-07-13 20:02:14 +0000 | [diff] [blame] | 152 | IgmpChannel.__init__(self, ssm_list = self.channels, iface=iface, src_list = src_list) |
A R Karthick | 338268f | 2016-06-21 17:12:13 -0700 | [diff] [blame] | 153 | |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 154 | def generate(self, num, channel_start = 0): |
Chetan Gaonker | 38737f8 | 2016-05-11 17:44:17 -0700 | [diff] [blame] | 155 | start = (225 << 24) | ( ( (channel_start >> 16) & 0xff) << 16 ) | \ |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 156 | ( ( (channel_start >> 8) & 0xff ) << 8 ) | (channel_start) & 0xff |
| 157 | start += channel_start/256 + 1 |
| 158 | end = start + num |
Chetan Gaonker | b424ff8 | 2016-03-08 12:11:12 -0800 | [diff] [blame] | 159 | group_addrs = [] |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 160 | count = 0 |
| 161 | while count != num: |
| 162 | for i in range(start, end): |
| 163 | if i&255: |
| 164 | g = '%s.%s.%s.%s' %((i>>24) &0xff, (i>>16)&0xff, (i>>8)&0xff, i&0xff) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 165 | log_test.debug('Adding group %s' %g) |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 166 | group_addrs.append(g) |
| 167 | count += 1 |
| 168 | start = end |
| 169 | end = start + 1 |
Chetan Gaonker | b424ff8 | 2016-03-08 12:11:12 -0800 | [diff] [blame] | 170 | return group_addrs |
| 171 | |
| 172 | def start(self): |
| 173 | if self.state == self.Stopped: |
| 174 | if self.streams: |
| 175 | self.streams.stop() |
| 176 | self.streams = McastTraffic(self.channels, iface=self.iface_mcast, cb = self.mcast_cb) |
| 177 | self.streams.start() |
| 178 | self.state = self.Started |
| 179 | |
Thangavelu K S | 8e41308 | 2017-07-13 20:02:14 +0000 | [diff] [blame] | 180 | def join(self, chan = None, src_list = None, record_type = None): |
| 181 | #def join(self, chan = None): |
Chetan Gaonker | b424ff8 | 2016-03-08 12:11:12 -0800 | [diff] [blame] | 182 | if chan is None: |
| 183 | chan = random.randint(0, self.num) |
| 184 | else: |
| 185 | if chan >= self.num: |
| 186 | chan = 0 |
| 187 | |
| 188 | if self.get_state(chan) == self.Joined: |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 189 | return chan, 0 |
Chetan Gaonker | b424ff8 | 2016-03-08 12:11:12 -0800 | [diff] [blame] | 190 | groups = [self.channels[chan]] |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 191 | join_start = monotonic.monotonic() |
Thangavelu K S | 8e41308 | 2017-07-13 20:02:14 +0000 | [diff] [blame] | 192 | self.igmp_join(groups, src_list = src_list, record_type = record_type) |
Chetan Gaonker | b424ff8 | 2016-03-08 12:11:12 -0800 | [diff] [blame] | 193 | self.set_state(chan, self.Joined) |
| 194 | self.last_chan = chan |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 195 | return chan, join_start |
Chetan Gaonker | b424ff8 | 2016-03-08 12:11:12 -0800 | [diff] [blame] | 196 | |
Thangavelu K S | 8e41308 | 2017-07-13 20:02:14 +0000 | [diff] [blame] | 197 | def leave(self, chan, force = False, src_list = None): |
Chetan Gaonker | b424ff8 | 2016-03-08 12:11:12 -0800 | [diff] [blame] | 198 | if chan is None: |
| 199 | chan = self.last_chan |
| 200 | if chan is None or chan >= self.num: |
| 201 | return False |
A R Karthick | 78d1f49 | 2017-05-19 14:24:17 -0700 | [diff] [blame] | 202 | if force is False and self.get_state(chan) != self.Joined: |
Chetan Gaonker | b424ff8 | 2016-03-08 12:11:12 -0800 | [diff] [blame] | 203 | return False |
| 204 | groups = [self.channels[chan]] |
Thangavelu K S | 8e41308 | 2017-07-13 20:02:14 +0000 | [diff] [blame] | 205 | self.igmp_leave(groups, src_list = src_list) |
Chetan Gaonker | b424ff8 | 2016-03-08 12:11:12 -0800 | [diff] [blame] | 206 | self.set_state(chan, self.Idle) |
| 207 | if chan == self.last_chan: |
| 208 | self.last_chan = None |
| 209 | return True |
A R Karthick | 338268f | 2016-06-21 17:12:13 -0700 | [diff] [blame] | 210 | |
A.R Karthick | 9d91455 | 2017-05-18 11:22:57 -0700 | [diff] [blame] | 211 | def join_next(self, chan = None, leave_flag = True): |
Chetan Gaonker | b424ff8 | 2016-03-08 12:11:12 -0800 | [diff] [blame] | 212 | if chan is None: |
| 213 | chan = self.last_chan |
| 214 | if chan is None: |
| 215 | return None |
| 216 | leave = chan |
Thangavelu K S | 8e41308 | 2017-07-13 20:02:14 +0000 | [diff] [blame] | 217 | join = chan+1 |
Chetan Gaonker | b424ff8 | 2016-03-08 12:11:12 -0800 | [diff] [blame] | 218 | else: |
| 219 | leave = chan - 1 |
| 220 | join = chan |
A R Karthick | 338268f | 2016-06-21 17:12:13 -0700 | [diff] [blame] | 221 | |
Chetan Gaonker | b424ff8 | 2016-03-08 12:11:12 -0800 | [diff] [blame] | 222 | if join >= self.num: |
| 223 | join = 0 |
| 224 | |
| 225 | if leave >= 0 and leave != join: |
A.R Karthick | 9d91455 | 2017-05-18 11:22:57 -0700 | [diff] [blame] | 226 | if leave_flag is True: |
| 227 | self.leave(leave) |
Chetan Gaonker | b424ff8 | 2016-03-08 12:11:12 -0800 | [diff] [blame] | 228 | |
| 229 | return self.join(join) |
| 230 | |
| 231 | def jump(self): |
| 232 | chan = self.last_chan |
| 233 | if chan is not None: |
| 234 | self.leave(chan) |
| 235 | s_next = chan |
| 236 | else: |
| 237 | s_next = 0 |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 238 | if self.num - s_next < 2: |
| 239 | s_next = 0 |
Chetan Gaonker | b424ff8 | 2016-03-08 12:11:12 -0800 | [diff] [blame] | 240 | chan = random.randint(s_next, self.num) |
| 241 | return self.join(chan) |
| 242 | |
| 243 | def gaddr(self, chan): |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 244 | '''Return the group address for a channel''' |
Chetan Gaonker | b424ff8 | 2016-03-08 12:11:12 -0800 | [diff] [blame] | 245 | if chan >= self.num: |
| 246 | return None |
| 247 | return self.channels[chan] |
| 248 | |
Chetan Gaonker | cbe7964 | 2016-03-09 17:45:58 -0800 | [diff] [blame] | 249 | def caddr(self, group): |
| 250 | '''Return a channel given a group addr''' |
| 251 | if self.group_channel_map.has_key(group): |
| 252 | return self.group_channel_map[group] |
| 253 | return None |
| 254 | |
Thangavelu K S | 8e41308 | 2017-07-13 20:02:14 +0000 | [diff] [blame] | 255 | def recv_cb(self, pkt, src_list = None): |
Chetan Gaonker | b424ff8 | 2016-03-08 12:11:12 -0800 | [diff] [blame] | 256 | '''Default channel receive callback''' |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 257 | log_test.debug('Received packet from source %s, destination %s' %(pkt[IP].src, pkt[IP].dst)) |
Thangavelu K S | 8e41308 | 2017-07-13 20:02:14 +0000 | [diff] [blame] | 258 | if src_list is None: |
| 259 | send_time = float(pkt[IP].payload.load) |
| 260 | recv_time = monotonic.monotonic() |
| 261 | log_test.debug('Packet received in %.3f usecs' %(recv_time - send_time)) |
| 262 | elif(pkt[IP].src == src_list[0]): |
| 263 | log_test.debug('Received packet from specified source %s, destination %s' %(pkt[IP].src, pkt[IP].dst)) |
| 264 | elif(pkt[IP].src != src_list[0]): |
| 265 | log_test.debug('Received packet not from specified source %s, destination %s' %(pkt[IP].src, pkt[IP].dst)) |
| 266 | time.sleep(60) |
Chetan Gaonker | b424ff8 | 2016-03-08 12:11:12 -0800 | [diff] [blame] | 267 | |
Thangavelu K S | 8e41308 | 2017-07-13 20:02:14 +0000 | [diff] [blame] | 268 | def recv(self, chan, cb = None, count = 1, timeout = 5, src_list = None): |
Chetan Gaonker | b424ff8 | 2016-03-08 12:11:12 -0800 | [diff] [blame] | 269 | if chan is None: |
| 270 | return None |
| 271 | if type(chan) == type([]) or type(chan) == type(()): |
| 272 | channel_list=filter(lambda c: c < self.num, chan) |
| 273 | groups = map(lambda c: self.gaddr(c), channel_list) |
| 274 | else: |
| 275 | groups = (self.gaddr(chan),) |
| 276 | if cb is None: |
Thangavelu K S | 8e41308 | 2017-07-13 20:02:14 +0000 | [diff] [blame] | 277 | cb = self.recv_cb(src_list = src_list) |
A R Karthick | 338268f | 2016-06-21 17:12:13 -0700 | [diff] [blame] | 278 | return sniff(prn = cb, count=count, timeout = timeout, |
A.R Karthick | 3f26021 | 2017-05-17 14:37:46 -0700 | [diff] [blame] | 279 | lfilter = lambda p: IP in p and p[IP].dst in groups, iface = bytes(self.iface[:15])) |
Chetan Gaonker | b424ff8 | 2016-03-08 12:11:12 -0800 | [diff] [blame] | 280 | |
| 281 | def stop(self): |
| 282 | if self.streams: |
| 283 | self.streams.stop() |
| 284 | self.state = self.Stopped |
| 285 | |
| 286 | def get_state(self, chan): |
| 287 | return self.channel_states[chan][0] |
| 288 | |
| 289 | def set_state(self, chan, state): |
| 290 | self.channel_states[chan][0] = state |
| 291 | |
| 292 | if __name__ == '__main__': |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 293 | num = 5 |
| 294 | start = 0 |
| 295 | ssm_list = [] |
A R Karthick | 2f4e0ba | 2017-07-17 10:55:36 -0700 | [diff] [blame] | 296 | src_list = [ '1.2.3.4' ] |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 297 | for i in xrange(2): |
Thangavelu K S | 8e41308 | 2017-07-13 20:02:14 +0000 | [diff] [blame] | 298 | channels = Channels(num, start, src_list = src_list) |
Chetan Gaonker | cd86bdd | 2016-03-17 00:08:12 -0700 | [diff] [blame] | 299 | ssm_list += channels.channels |
| 300 | start += num |
Thangavelu K S | 8e41308 | 2017-07-13 20:02:14 +0000 | [diff] [blame] | 301 | igmpChannel = IgmpChannel(src_list = src_list) |
| 302 | igmpChannel.igmp_load_ssm_config(ssm_list, src_list) |
Chetan Gaonker | b424ff8 | 2016-03-08 12:11:12 -0800 | [diff] [blame] | 303 | channels.start() |
| 304 | for i in range(num): |
| 305 | channels.join(i) |
| 306 | for i in range(num): |
| 307 | channels.recv(i) |
| 308 | for i in range(num): |
| 309 | channels.leave(i) |
| 310 | channels.stop() |