Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 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 |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 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 | */ |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 16 | package org.onosproject.vpls; |
| 17 | |
| 18 | import com.google.common.collect.HashMultimap; |
| 19 | import com.google.common.collect.ImmutableSet; |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 20 | import com.google.common.collect.SetMultimap; |
| 21 | import com.google.common.collect.Sets; |
| 22 | import org.junit.After; |
| 23 | import org.junit.Before; |
| 24 | import org.junit.Test; |
| 25 | import org.onlab.packet.Ethernet; |
| 26 | import org.onlab.packet.IpAddress; |
| 27 | import org.onlab.packet.MacAddress; |
| 28 | import org.onlab.packet.VlanId; |
| 29 | import org.onosproject.core.ApplicationId; |
Ray Milkey | facf286 | 2017-08-03 11:58:29 -0700 | [diff] [blame] | 30 | import org.onosproject.net.intf.Interface; |
Ray Milkey | b65d784 | 2017-08-03 16:28:24 -0700 | [diff] [blame] | 31 | import org.onosproject.net.neighbour.NeighbourHandlerRegistration; |
| 32 | import org.onosproject.net.neighbour.NeighbourMessageContext; |
| 33 | import org.onosproject.net.neighbour.NeighbourMessageHandler; |
| 34 | import org.onosproject.net.neighbour.NeighbourMessageType; |
| 35 | import org.onosproject.net.neighbour.NeighbourProtocol; |
| 36 | import org.onosproject.net.neighbour.NeighbourResolutionService; |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 37 | import org.onosproject.net.ConnectPoint; |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 38 | import org.onosproject.net.Host; |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 39 | import org.onosproject.net.host.HostService; |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 40 | import org.onosproject.vpls.api.VplsData; |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 41 | |
| 42 | import java.util.Collection; |
| 43 | import java.util.Map; |
| 44 | import java.util.Set; |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 45 | |
| 46 | import static junit.framework.TestCase.assertEquals; |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 47 | import static junit.framework.TestCase.assertTrue; |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 48 | |
| 49 | /** |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 50 | * Tests the the {@link VplsNeighbourHandler}. |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 51 | */ |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 52 | public class VplsNeighbourHandlerTest extends VplsTest { |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 53 | |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 54 | private static final String IFACES_NOT_EXPECTED = |
| 55 | "The interfaces reached by the packet are not equal to the " + |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 56 | "interfaces expected."; |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 57 | private VplsNeighbourHandler vplsNeighbourHandler; |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 58 | private HostService hostService; |
| 59 | |
| 60 | /** |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 61 | * Sets up 4 VPLS. |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 62 | * VPLS 1 contains 3 hosts: v100h1, v200h1 and v300h1 |
| 63 | * VPLS 2 contains 2 hosts: v100h2, v200h2 |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 64 | * VPLS 3 contains 2 hosts: vNoneh1, vNoneh2 |
| 65 | * VPLS 4 contains 2 hosts: v400h1, vNoneh3 |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 66 | */ |
| 67 | @Before |
| 68 | public void setUp() { |
| 69 | vplsNeighbourHandler = new VplsNeighbourHandler(); |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 70 | hostService = new TestHostService(); |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 71 | vplsNeighbourHandler.vplsStore = new TestVplsStore(); |
| 72 | vplsNeighbourHandler.interfaceService = new TestInterfaceService(); |
| 73 | vplsNeighbourHandler.neighbourService = new TestNeighbourService(); |
| 74 | vplsNeighbourHandler.coreService = new TestCoreService(); |
| 75 | vplsNeighbourHandler.configService = new TestConfigService(); |
| 76 | |
| 77 | // Init VPLS store |
| 78 | VplsData vplsData = VplsData.of(VPLS1); |
| 79 | vplsData.addInterfaces(ImmutableSet.of(V100H1, V200H1, V300H1)); |
| 80 | vplsNeighbourHandler.vplsStore.addVpls(vplsData); |
| 81 | |
| 82 | vplsData = VplsData.of(VPLS2); |
| 83 | vplsData.addInterfaces(ImmutableSet.of(V100H2, V200H2)); |
| 84 | vplsNeighbourHandler.vplsStore.addVpls(vplsData); |
| 85 | |
| 86 | vplsData = VplsData.of(VPLS3); |
| 87 | vplsData.addInterfaces(ImmutableSet.of(VNONEH1, VNONEH2)); |
| 88 | vplsNeighbourHandler.vplsStore.addVpls(vplsData); |
| 89 | |
| 90 | vplsData = VplsData.of(VPLS4); |
| 91 | vplsData.addInterfaces(ImmutableSet.of(V400H1, VNONEH3)); |
| 92 | vplsNeighbourHandler.vplsStore.addVpls(vplsData); |
| 93 | |
| 94 | vplsNeighbourHandler.activate(); |
| 95 | |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | @After |
| 99 | public void tearDown() { |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 100 | vplsNeighbourHandler.deactivate(); |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Registers neighbour handler to all available interfaces. |
| 105 | */ |
| 106 | @Test |
| 107 | public void testConfigNeighbourHandler() { |
| 108 | vplsNeighbourHandler.configNeighbourHandler(); |
| 109 | assertEquals(9, vplsNeighbourHandler.neighbourService.getHandlerRegistrations().size()); |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | /** |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 113 | * Sends request messages to all hosts in VPLS 1. |
| 114 | * Request messages should be received from other hosts in VPLS 1. |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 115 | */ |
| 116 | @Test |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 117 | public void vpls1RequestMessage() { |
| 118 | // Request messages from v100h1 (VPLS 1) should be received by v200h1 and v300h1 |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 119 | TestMessageContext requestMessage = |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 120 | makeBroadcastRequestContext(V100HOST1); |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 121 | Set<Interface> expectInterfaces = ImmutableSet.of(V200H1, V300H1); |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 122 | ((TestNeighbourService) vplsNeighbourHandler.neighbourService).sendNeighourMessage(requestMessage); |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 123 | assertEquals(IFACES_NOT_EXPECTED, expectInterfaces, requestMessage.forwardResults); |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 124 | |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 125 | // Request messages from v200h1 (VPLS 1) should be received by v100h1 and v300h1 |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 126 | requestMessage = makeBroadcastRequestContext(V200HOST1); |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 127 | expectInterfaces = ImmutableSet.of(V100H1, V300H1); |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 128 | ((TestNeighbourService) vplsNeighbourHandler.neighbourService).sendNeighourMessage(requestMessage); |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 129 | assertEquals(IFACES_NOT_EXPECTED, expectInterfaces, requestMessage.forwardResults); |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 130 | |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 131 | // Request from v300h1 (VPLS 1) should be received by v100h1 and v200h1 |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 132 | requestMessage = makeBroadcastRequestContext(V300HOST1); |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 133 | expectInterfaces = ImmutableSet.of(V100H1, V200H1); |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 134 | ((TestNeighbourService) vplsNeighbourHandler.neighbourService).sendNeighourMessage(requestMessage); |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 135 | assertEquals(IFACES_NOT_EXPECTED, expectInterfaces, requestMessage.forwardResults); |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | /** |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 139 | * Sends request messages to all hosts in VPLS 2. |
| 140 | * Request messages should be received from other hosts in VPLS 2. |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 141 | */ |
| 142 | @Test |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 143 | public void vpls2RequestMessage() { |
| 144 | // Request messages from v100h2 (VPLS 2) should be received by v200h2 |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 145 | TestMessageContext requestMessage = |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 146 | makeBroadcastRequestContext(V100HOST2); |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 147 | Set<Interface> expectInterfaces = ImmutableSet.of(V200H2); |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 148 | ((TestNeighbourService) vplsNeighbourHandler.neighbourService).sendNeighourMessage(requestMessage); |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 149 | assertEquals(IFACES_NOT_EXPECTED, expectInterfaces, requestMessage.forwardResults); |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 150 | |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 151 | // Request messages from v200h2 (VPLS 2) should be received by v100h2 |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 152 | requestMessage = makeBroadcastRequestContext(V200HOST2); |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 153 | expectInterfaces = ImmutableSet.of(V100H2); |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 154 | ((TestNeighbourService) vplsNeighbourHandler.neighbourService).sendNeighourMessage(requestMessage); |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 155 | assertEquals(IFACES_NOT_EXPECTED, expectInterfaces, requestMessage.forwardResults); |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | /** |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 159 | * Tests correct connection between untagged interfaces. |
| 160 | * |
| 161 | * Sends request messages to all hosts in VPLS 3. |
| 162 | * Request messages should be received from other hosts in VPLS 3. |
| 163 | */ |
| 164 | @Test |
| 165 | public void vpls3RequestMessage() { |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 166 | // Request messages from VNONEHOST1 (VPLS 3) should be received by VNONEHOST2 |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 167 | TestMessageContext requestMessage = |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 168 | makeBroadcastRequestContext(VNONEHOST1); |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 169 | Set<Interface> expectInterfaces = ImmutableSet.of(VNONEH2); |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 170 | ((TestNeighbourService) vplsNeighbourHandler.neighbourService).sendNeighourMessage(requestMessage); |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 171 | assertEquals(IFACES_NOT_EXPECTED, expectInterfaces, requestMessage.forwardResults); |
| 172 | |
| 173 | // Request messages from vNoneh2 (VPLS 3) should be received by vNoneh1 |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 174 | requestMessage = makeBroadcastRequestContext(VNONEHOST2); |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 175 | expectInterfaces = ImmutableSet.of(VNONEH1); |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 176 | ((TestNeighbourService) vplsNeighbourHandler.neighbourService).sendNeighourMessage(requestMessage); |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 177 | assertEquals(IFACES_NOT_EXPECTED, expectInterfaces, requestMessage.forwardResults); |
| 178 | } |
| 179 | |
| 180 | /** |
| 181 | * Tests correct connection between tagged and untagged interfaces. |
| 182 | * |
| 183 | * Sends request messages to all hosts in VPLS 4. |
| 184 | * Request messages should be received from other hosts in VPLS 4. |
| 185 | */ |
| 186 | @Test |
| 187 | public void vpls4RequestMessage() { |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 188 | // Request messages from V400HOST1 (VPLS 4) should be received by VNONEHOST3 |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 189 | TestMessageContext requestMessage = |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 190 | makeBroadcastRequestContext(V400HOST1); |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 191 | Set<Interface> expectInterfaces = ImmutableSet.of(VNONEH3); |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 192 | ((TestNeighbourService) vplsNeighbourHandler.neighbourService).sendNeighourMessage(requestMessage); |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 193 | assertEquals(IFACES_NOT_EXPECTED, expectInterfaces, requestMessage.forwardResults); |
| 194 | |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 195 | // Request messages from VNONEHOST3 (VPLS 4) should be received by V400HOST1 |
| 196 | requestMessage = makeBroadcastRequestContext(VNONEHOST3); |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 197 | expectInterfaces = ImmutableSet.of(V400H1); |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 198 | ((TestNeighbourService) vplsNeighbourHandler.neighbourService).sendNeighourMessage(requestMessage); |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 199 | assertEquals(IFACES_NOT_EXPECTED, expectInterfaces, requestMessage.forwardResults); |
| 200 | } |
| 201 | |
| 202 | /** |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 203 | * Sends reply messages to hosts in VPLS 1. |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 204 | * Reply messages should be received by the host with MAC address equal to |
| 205 | * the dstMac of the message context. |
| 206 | */ |
| 207 | @Test |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 208 | public void vpls1ReplyMessage() { |
| 209 | // Reply messages from v100h1 (VPLS 1) should be received by v200h1 |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 210 | TestMessageContext replyMessage = |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 211 | makeReplyContext(V100HOST1, V200HOST1); |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 212 | Set<Interface> expectInterfaces = ImmutableSet.of(V200H1); |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 213 | ((TestNeighbourService) vplsNeighbourHandler.neighbourService).sendNeighourMessage(replyMessage); |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 214 | assertEquals(IFACES_NOT_EXPECTED, expectInterfaces, replyMessage.forwardResults); |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 215 | |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 216 | // Reply messages from v200h1 (VPLS 1) should be received by v300h1 |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 217 | replyMessage = makeReplyContext(V200HOST1, V300HOST1); |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 218 | expectInterfaces = ImmutableSet.of(V300H1); |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 219 | ((TestNeighbourService) vplsNeighbourHandler.neighbourService).sendNeighourMessage(replyMessage); |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 220 | assertEquals(IFACES_NOT_EXPECTED, expectInterfaces, replyMessage.forwardResults); |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 221 | |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 222 | // Reply messages from v300h1 (VPLS 1) should be received by v100h1 |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 223 | replyMessage = makeReplyContext(V300HOST1, V100HOST1); |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 224 | expectInterfaces = ImmutableSet.of(V100H1); |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 225 | ((TestNeighbourService) vplsNeighbourHandler.neighbourService).sendNeighourMessage(replyMessage); |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 226 | assertEquals(IFACES_NOT_EXPECTED, expectInterfaces, replyMessage.forwardResults); |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | /** |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 230 | * Sends reply messages to hosts in VPLS 2. |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 231 | * Reply messages should be received by the host with MAC address equal to |
| 232 | * the dstMac of the message context. |
| 233 | */ |
| 234 | @Test |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 235 | public void vpls2ReplyMessage() { |
| 236 | // Reply messages from v100h2 (VPLS 2) should be received by v200h2 |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 237 | TestMessageContext replyMessage = |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 238 | makeReplyContext(V100HOST2, V200HOST2); |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 239 | Set<Interface> expectInterfaces = ImmutableSet.of(V200H2); |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 240 | ((TestNeighbourService) vplsNeighbourHandler.neighbourService).sendNeighourMessage(replyMessage); |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 241 | assertEquals(IFACES_NOT_EXPECTED, expectInterfaces, replyMessage.forwardResults); |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 242 | |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 243 | // Reply messages from v200h2 (VPLS 2) should be received by v100h2 |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 244 | replyMessage = makeReplyContext(V200HOST2, V100HOST2); |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 245 | expectInterfaces = ImmutableSet.of(V100H2); |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 246 | ((TestNeighbourService) vplsNeighbourHandler.neighbourService).sendNeighourMessage(replyMessage); |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 247 | assertEquals(IFACES_NOT_EXPECTED, expectInterfaces, replyMessage.forwardResults); |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | /** |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 251 | * Sends reply messages to hosts in VPLS 3. |
| 252 | * Reply messages should be received by the host with MAC address equal to |
| 253 | * the dstMac of the message context. |
| 254 | */ |
| 255 | @Test |
| 256 | public void vpls3ReplyMessage() { |
| 257 | // Reply messages from vNoneh1 (VPLS 3) should be received by vNoneh2 |
| 258 | TestMessageContext replyMessage = |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 259 | makeReplyContext(VNONEHOST1, VNONEHOST2); |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 260 | Set<Interface> expectInterfaces = ImmutableSet.of(VNONEH2); |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 261 | ((TestNeighbourService) vplsNeighbourHandler.neighbourService).sendNeighourMessage(replyMessage); |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 262 | assertEquals(IFACES_NOT_EXPECTED, expectInterfaces, replyMessage.forwardResults); |
| 263 | |
| 264 | // Reply messages from vNoneh2 (VPLS 3) should be received by vNoneh1 |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 265 | replyMessage = makeReplyContext(VNONEHOST2, VNONEHOST1); |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 266 | expectInterfaces = ImmutableSet.of(VNONEH1); |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 267 | ((TestNeighbourService) vplsNeighbourHandler.neighbourService).sendNeighourMessage(replyMessage); |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 268 | assertEquals(IFACES_NOT_EXPECTED, expectInterfaces, replyMessage.forwardResults); |
| 269 | } |
| 270 | |
| 271 | /** |
| 272 | * Sends reply messages to hosts in VPLS 4. |
| 273 | * Reply messages should be received by the host with MAC address equal to |
| 274 | * the dstMac of the message context. |
| 275 | */ |
| 276 | @Test |
| 277 | public void vpls4ReplyMessage() { |
| 278 | // Reply messages from v400h1 (VPLS 4) should be received by vNoneh3 |
| 279 | TestMessageContext replyMessage = |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 280 | makeReplyContext(V400HOST1, VNONEHOST3); |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 281 | Set<Interface> expectInterfaces = ImmutableSet.of(VNONEH3); |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 282 | ((TestNeighbourService) vplsNeighbourHandler.neighbourService).sendNeighourMessage(replyMessage); |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 283 | assertEquals(IFACES_NOT_EXPECTED, expectInterfaces, replyMessage.forwardResults); |
| 284 | |
| 285 | // Reply messages from vNoneh3 (VPLS 4) should be received by v400h1 |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 286 | replyMessage = makeReplyContext(VNONEHOST3, V400HOST1); |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 287 | expectInterfaces = ImmutableSet.of(V400H1); |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 288 | ((TestNeighbourService) vplsNeighbourHandler.neighbourService).sendNeighourMessage(replyMessage); |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 289 | assertEquals(IFACES_NOT_EXPECTED, expectInterfaces, replyMessage.forwardResults); |
| 290 | } |
| 291 | |
| 292 | /** |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 293 | * Sends wrong reply messages to hosts. |
| 294 | * The source and the destination MAC addresses are not set on any host of the VPLS. |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 295 | * The reply messages will not be received by any hosts. |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 296 | */ |
| 297 | @Test |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 298 | public void wrongReplyMessage() { |
| 299 | // Reply message from v100h1 (VPLS 1) to v100h2 (VPLS 2). |
| 300 | // Forward results should be empty |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 301 | TestMessageContext replyMessage = makeReplyContext(V100HOST1, V100HOST2); |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 302 | Set<Interface> expectInterfaces = ImmutableSet.of(); |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 303 | ((TestNeighbourService) vplsNeighbourHandler.neighbourService).sendNeighourMessage(replyMessage); |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 304 | assertEquals(IFACES_NOT_EXPECTED, expectInterfaces, replyMessage.forwardResults); |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 305 | |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 306 | // Reply message from v200h2 (VPLS 2) to v300h1 (VPLS 1). |
| 307 | // Forward results should be empty |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 308 | replyMessage = makeReplyContext(V200HOST2, V300HOST1); |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 309 | expectInterfaces = ImmutableSet.of(); |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 310 | ((TestNeighbourService) vplsNeighbourHandler.neighbourService).sendNeighourMessage(replyMessage); |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 311 | assertEquals(IFACES_NOT_EXPECTED, expectInterfaces, replyMessage.forwardResults); |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 312 | |
| 313 | // Reply message from vNoneh1 (VPLS 3) to v400h1 (VPLS 4). |
| 314 | // Forward results should be empty |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 315 | replyMessage = makeReplyContext(VNONEHOST1, V400HOST1); |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 316 | expectInterfaces = ImmutableSet.of(); |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 317 | ((TestNeighbourService) vplsNeighbourHandler.neighbourService).sendNeighourMessage(replyMessage); |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 318 | assertEquals(IFACES_NOT_EXPECTED, expectInterfaces, replyMessage.forwardResults); |
| 319 | |
| 320 | // Reply message from vNoneh3 (VPLS 4) to vNoneH2 (VPLS 3). |
| 321 | // Forward results should be empty |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 322 | replyMessage = makeReplyContext(VNONEHOST3, VNONEHOST2); |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 323 | expectInterfaces = ImmutableSet.of(); |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 324 | ((TestNeighbourService) vplsNeighbourHandler.neighbourService).sendNeighourMessage(replyMessage); |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 325 | assertEquals(IFACES_NOT_EXPECTED, expectInterfaces, replyMessage.forwardResults); |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | /** |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 329 | * Sends reply and request message from a host which not related to any VPLS. |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 330 | */ |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 331 | @Test |
| 332 | public void testVplsNotfound() { |
| 333 | TestMessageContext replyMessage = makeReplyContext(V300HOST2, V100HOST1); |
| 334 | Set<Interface> expectInterfaces = ImmutableSet.of(); |
| 335 | ((TestNeighbourService) vplsNeighbourHandler.neighbourService).sendNeighourMessage(replyMessage); |
| 336 | assertEquals(IFACES_NOT_EXPECTED, expectInterfaces, replyMessage.forwardResults); |
| 337 | assertTrue(replyMessage.dropped()); |
| 338 | |
| 339 | TestMessageContext requestMessage = makeBroadcastRequestContext(V300HOST2); |
| 340 | ((TestNeighbourService) vplsNeighbourHandler.neighbourService).sendNeighourMessage(requestMessage); |
| 341 | assertEquals(IFACES_NOT_EXPECTED, expectInterfaces, requestMessage.forwardResults); |
| 342 | assertTrue(requestMessage.dropped()); |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 343 | } |
| 344 | |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 345 | /** |
| 346 | * Generates broadcast request message context by given source host. |
| 347 | * |
| 348 | * @param host the source host |
| 349 | * @return the request message context |
| 350 | */ |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 351 | private TestMessageContext makeBroadcastRequestContext(Host host) { |
| 352 | return new TestMessageContext(host.location(), |
| 353 | host.mac(), |
| 354 | MacAddress.BROADCAST, |
| 355 | host.vlan(), |
| 356 | NeighbourMessageType.REQUEST); |
| 357 | } |
| 358 | |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 359 | /** |
| 360 | * Generates reply message context by given source and destination host. |
| 361 | * |
| 362 | * @param src the source host |
| 363 | * @param dst the destination host |
| 364 | * @return the reply message context |
| 365 | */ |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 366 | private TestMessageContext makeReplyContext(Host src, Host dst) { |
| 367 | return new TestMessageContext(src.location(), |
| 368 | src.mac(), |
| 369 | dst.mac(), |
| 370 | src.vlan(), |
| 371 | NeighbourMessageType.REPLY); |
| 372 | } |
| 373 | |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 374 | /** |
| 375 | * Test message context. |
| 376 | */ |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 377 | private class TestMessageContext implements NeighbourMessageContext { |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 378 | private final NeighbourMessageType type; |
| 379 | private final MacAddress srcMac; |
| 380 | private final MacAddress dstMac; |
| 381 | private final ConnectPoint inPort; |
| 382 | private final VlanId vlanId; |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 383 | private boolean dropped = false; |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 384 | public Set<Interface> forwardResults; |
| 385 | |
| 386 | /** |
| 387 | * Creates new neighbour message context for test. |
| 388 | * |
| 389 | * @param inPort the input port |
| 390 | * @param srcMac the source Mac |
| 391 | * @param dstMac the destination Mac |
| 392 | * @param vlanId the VLAN Id |
| 393 | * @param type the message context type |
| 394 | */ |
| 395 | public TestMessageContext( |
| 396 | ConnectPoint inPort, |
| 397 | MacAddress srcMac, |
| 398 | MacAddress dstMac, |
| 399 | VlanId vlanId, |
| 400 | NeighbourMessageType type) { |
| 401 | |
| 402 | this.inPort = inPort; |
| 403 | this.srcMac = srcMac; |
| 404 | this.dstMac = dstMac; |
| 405 | this.vlanId = vlanId; |
| 406 | this.type = type; |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 407 | this.forwardResults = Sets.newHashSet(); |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 408 | this.dropped = false; |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 409 | } |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 410 | |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 411 | @Override |
| 412 | public ConnectPoint inPort() { |
| 413 | return inPort; |
| 414 | } |
| 415 | |
| 416 | @Override |
| 417 | public NeighbourMessageType type() { |
| 418 | return type; |
| 419 | } |
| 420 | |
| 421 | @Override |
| 422 | public VlanId vlan() { |
| 423 | return vlanId; |
| 424 | } |
| 425 | |
| 426 | @Override |
| 427 | public MacAddress srcMac() { |
| 428 | return srcMac; |
| 429 | } |
| 430 | |
| 431 | @Override |
| 432 | public MacAddress dstMac() { |
| 433 | return dstMac; |
| 434 | } |
| 435 | |
| 436 | @Override |
| 437 | public IpAddress target() { |
| 438 | return null; |
| 439 | } |
| 440 | |
| 441 | @Override |
| 442 | public IpAddress sender() { |
| 443 | return null; |
| 444 | } |
| 445 | |
| 446 | @Override |
| 447 | public void forward(ConnectPoint outPort) { |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 448 | } |
| 449 | |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 450 | /** |
| 451 | * Records all forward network interface information. |
| 452 | * @param outIntf output interface |
| 453 | */ |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 454 | @Override |
| 455 | public void forward(Interface outIntf) { |
| 456 | forwardResults.add(outIntf); |
| 457 | } |
| 458 | |
| 459 | @Override |
| 460 | public void reply(MacAddress targetMac) { |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | @Override |
| 464 | public void flood() { |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | @Override |
| 468 | public void drop() { |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 469 | this.dropped = true; |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | @Override |
| 473 | public Ethernet packet() { |
| 474 | return null; |
| 475 | } |
| 476 | |
| 477 | @Override |
| 478 | public NeighbourProtocol protocol() { |
| 479 | return null; |
| 480 | } |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 481 | |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 482 | public boolean dropped() { |
| 483 | return dropped; |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 484 | } |
| 485 | } |
| 486 | |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 487 | /** |
| 488 | * Test neighbour service; records all registrations between neighbour |
| 489 | * message handler and interfaces. |
| 490 | */ |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 491 | private class TestNeighbourService implements NeighbourResolutionService { |
| 492 | private SetMultimap<ConnectPoint, NeighbourHandlerRegistration> handlerRegs; |
| 493 | |
| 494 | public TestNeighbourService() { |
| 495 | handlerRegs = HashMultimap.create(); |
| 496 | } |
| 497 | |
| 498 | @Override |
| 499 | public void registerNeighbourHandler(ConnectPoint connectPoint, |
| 500 | NeighbourMessageHandler handler, |
| 501 | ApplicationId appId) { |
| 502 | Interface intf = |
| 503 | new Interface(null, connectPoint, null, null, null); |
| 504 | |
| 505 | NeighbourHandlerRegistration reg = |
| 506 | new HandlerRegistration(handler, intf, appId); |
| 507 | |
| 508 | handlerRegs.put(connectPoint, reg); |
| 509 | } |
| 510 | |
| 511 | @Override |
| 512 | public void registerNeighbourHandler(Interface intf, |
| 513 | NeighbourMessageHandler handler, |
| 514 | ApplicationId appId) { |
| 515 | NeighbourHandlerRegistration reg = |
| 516 | new HandlerRegistration(handler, intf, appId); |
| 517 | handlerRegs.put(intf.connectPoint(), reg); |
| 518 | } |
| 519 | |
| 520 | @Override |
| 521 | public void unregisterNeighbourHandler(ConnectPoint connectPoint, |
| 522 | NeighbourMessageHandler handler, |
| 523 | ApplicationId appId) { |
| 524 | handlerRegs.removeAll(connectPoint); |
| 525 | } |
| 526 | |
| 527 | @Override |
| 528 | public void unregisterNeighbourHandler(Interface intf, |
| 529 | NeighbourMessageHandler handler, |
| 530 | ApplicationId appId) { |
| 531 | handlerRegs.removeAll(intf.connectPoint()); |
| 532 | } |
| 533 | |
| 534 | @Override |
| 535 | public void unregisterNeighbourHandlers(ApplicationId appId) { |
| 536 | handlerRegs.clear(); |
| 537 | } |
| 538 | |
| 539 | @Override |
| 540 | public Map<ConnectPoint, Collection<NeighbourHandlerRegistration>> getHandlerRegistrations() { |
| 541 | return handlerRegs.asMap(); |
| 542 | } |
| 543 | |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 544 | /** |
| 545 | * Sends neighbour message context to all handler which related to the |
| 546 | * context. |
| 547 | * |
| 548 | * @param context the neighbour message context |
| 549 | */ |
| 550 | public void sendNeighourMessage(NeighbourMessageContext context) { |
| 551 | ConnectPoint connectPoint = context.inPort(); |
| 552 | VlanId vlanId = context.vlan(); |
| 553 | Collection<NeighbourHandlerRegistration> registrations = handlerRegs.get(connectPoint); |
| 554 | registrations.forEach(reg -> { |
| 555 | if (reg.intf().vlan().equals(vlanId)) { |
| 556 | reg.handler().handleMessage(context, hostService); |
| 557 | } |
| 558 | }); |
| 559 | } |
| 560 | |
| 561 | /** |
| 562 | * Test handler registration. |
| 563 | */ |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 564 | private class HandlerRegistration implements NeighbourHandlerRegistration { |
| 565 | private final Interface intf; |
| 566 | private final NeighbourMessageHandler handler; |
| 567 | private final ApplicationId appId; |
| 568 | |
| 569 | /** |
| 570 | * Creates a new registration handler. |
| 571 | * |
| 572 | * @param handler the neighbour message handler |
| 573 | * @param intf the interface |
| 574 | */ |
| 575 | public HandlerRegistration(NeighbourMessageHandler handler, |
| 576 | Interface intf, |
| 577 | ApplicationId appId) { |
| 578 | this.intf = intf; |
| 579 | this.handler = handler; |
| 580 | this.appId = appId; |
| 581 | } |
| 582 | |
| 583 | @Override |
| 584 | public Interface intf() { |
| 585 | return intf; |
| 586 | } |
| 587 | |
| 588 | @Override |
| 589 | public NeighbourMessageHandler handler() { |
| 590 | return handler; |
| 591 | } |
| 592 | |
| 593 | @Override |
| 594 | public ApplicationId appId() { |
| 595 | return appId; |
| 596 | } |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 597 | } |
| 598 | } |
Yong-hwan Kim | fbf653c | 2016-09-21 10:05:22 -0700 | [diff] [blame] | 599 | } |