Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [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 | */ |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 16 | |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 17 | package org.onosproject.vpls; |
| 18 | |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 19 | import com.fasterxml.jackson.databind.JsonNode; |
| 20 | import com.fasterxml.jackson.databind.ObjectMapper; |
Luca Prete | 1346564 | 2017-01-04 10:31:48 -0800 | [diff] [blame] | 21 | import com.google.common.collect.ImmutableSet; |
Luca Prete | 1346564 | 2017-01-04 10:31:48 -0800 | [diff] [blame] | 22 | import com.google.common.collect.Lists; |
| 23 | import com.google.common.collect.Maps; |
Luca Prete | 1346564 | 2017-01-04 10:31:48 -0800 | [diff] [blame] | 24 | import com.google.common.collect.Sets; |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 25 | import org.onlab.packet.Ip4Address; |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 26 | import org.onlab.packet.IpAddress; |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 27 | import org.onlab.packet.MacAddress; |
| 28 | import org.onlab.packet.VlanId; |
| 29 | import org.onosproject.TestApplicationId; |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 30 | import org.onosproject.cluster.LeadershipEvent; |
| 31 | import org.onosproject.cluster.LeadershipEventListener; |
| 32 | import org.onosproject.cluster.LeadershipServiceAdapter; |
| 33 | import org.onosproject.cluster.NodeId; |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 34 | import org.onosproject.core.ApplicationId; |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 35 | import org.onosproject.core.CoreServiceAdapter; |
Ray Milkey | facf286 | 2017-08-03 11:58:29 -0700 | [diff] [blame] | 36 | import org.onosproject.net.intf.Interface; |
| 37 | import org.onosproject.net.intf.InterfaceListener; |
| 38 | import org.onosproject.net.intf.InterfaceService; |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 39 | import org.onosproject.net.ConnectPoint; |
| 40 | import org.onosproject.net.DefaultHost; |
| 41 | import org.onosproject.net.DeviceId; |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 42 | import org.onosproject.net.EncapsulationType; |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 43 | import org.onosproject.net.Host; |
| 44 | import org.onosproject.net.HostId; |
| 45 | import org.onosproject.net.HostLocation; |
| 46 | import org.onosproject.net.PortNumber; |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 47 | import org.onosproject.net.config.Config; |
| 48 | import org.onosproject.net.config.ConfigApplyDelegate; |
| 49 | import org.onosproject.net.config.NetworkConfigEvent; |
| 50 | import org.onosproject.net.config.NetworkConfigListener; |
| 51 | import org.onosproject.net.config.NetworkConfigServiceAdapter; |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 52 | import org.onosproject.net.host.HostEvent; |
| 53 | import org.onosproject.net.host.HostListener; |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 54 | import org.onosproject.net.host.HostServiceAdapter; |
Yuta HIGUCHI | 488a94c | 2018-01-26 17:24:09 -0800 | [diff] [blame] | 55 | import org.onosproject.net.host.InterfaceIpAddress; |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 56 | import org.onosproject.net.intent.Intent; |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 57 | import org.onosproject.net.intent.IntentData; |
| 58 | import org.onosproject.net.intent.IntentEvent; |
| 59 | import org.onosproject.net.intent.IntentListener; |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 60 | import org.onosproject.net.intent.IntentServiceAdapter; |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 61 | import org.onosproject.net.intent.IntentState; |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 62 | import org.onosproject.net.provider.ProviderId; |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 63 | import org.onosproject.store.StoreDelegate; |
| 64 | import org.onosproject.store.service.WallClockTimestamp; |
| 65 | import org.onosproject.vpls.api.Vpls; |
| 66 | import org.onosproject.vpls.api.VplsData; |
| 67 | import org.onosproject.vpls.config.VplsAppConfig; |
| 68 | import org.onosproject.vpls.config.VplsAppConfigTest; |
| 69 | import org.onosproject.vpls.config.VplsConfig; |
| 70 | import org.onosproject.vpls.store.VplsStoreAdapter; |
| 71 | import org.onosproject.vpls.store.VplsStoreEvent; |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 72 | |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 73 | import java.io.IOException; |
Luca Prete | 1346564 | 2017-01-04 10:31:48 -0800 | [diff] [blame] | 74 | import java.util.Collection; |
| 75 | import java.util.Collections; |
Luca Prete | 1346564 | 2017-01-04 10:31:48 -0800 | [diff] [blame] | 76 | import java.util.List; |
| 77 | import java.util.Map; |
| 78 | import java.util.Set; |
Luca Prete | 1346564 | 2017-01-04 10:31:48 -0800 | [diff] [blame] | 79 | import java.util.stream.Collectors; |
| 80 | |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 81 | /** |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 82 | * Class provides data for VPLS testing. |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 83 | */ |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 84 | public abstract class VplsTest { |
| 85 | protected static final String APP_NAME = "org.onosproject.vpls"; |
| 86 | protected static final ApplicationId APPID = TestApplicationId.create(APP_NAME); |
| 87 | protected static final String DASH = "-"; |
| 88 | protected static final int PRIORITY_OFFSET = 1000; |
| 89 | protected static final String VPLS1 = "vpls1"; |
| 90 | protected static final String VPLS2 = "vpls2"; |
| 91 | protected static final String VPLS3 = "vpls3"; |
| 92 | protected static final String VPLS4 = "vpls4"; |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 93 | |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 94 | protected static final PortNumber P1 = PortNumber.portNumber(1); |
| 95 | protected static final PortNumber P2 = PortNumber.portNumber(2); |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 96 | |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 97 | protected static final DeviceId DID1 = getDeviceId(1); |
| 98 | protected static final DeviceId DID2 = getDeviceId(2); |
| 99 | protected static final DeviceId DID3 = getDeviceId(3); |
| 100 | protected static final DeviceId DID4 = getDeviceId(4); |
| 101 | protected static final DeviceId DID5 = getDeviceId(5); |
| 102 | protected static final DeviceId DID6 = getDeviceId(6); |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 103 | |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 104 | protected static final ConnectPoint CP1 = new ConnectPoint(DID1, P1); |
| 105 | protected static final ConnectPoint CP2 = new ConnectPoint(DID2, P1); |
| 106 | protected static final ConnectPoint CP3 = new ConnectPoint(DID3, P1); |
| 107 | protected static final ConnectPoint CP4 = new ConnectPoint(DID4, P1); |
| 108 | protected static final ConnectPoint CP5 = new ConnectPoint(DID5, P1); |
| 109 | protected static final ConnectPoint CP6 = new ConnectPoint(DID6, P1); |
| 110 | protected static final ConnectPoint CP7 = new ConnectPoint(DID4, P2); |
| 111 | protected static final ConnectPoint CP8 = new ConnectPoint(DID3, P2); |
| 112 | protected static final ConnectPoint CP9 = new ConnectPoint(DID5, P1); |
| 113 | protected static final ConnectPoint CP10 = new ConnectPoint(DID5, P2); |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 114 | |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 115 | protected static final VlanId VLAN100 = VlanId.vlanId((short) 100); |
| 116 | protected static final VlanId VLAN200 = VlanId.vlanId((short) 200); |
| 117 | protected static final VlanId VLAN300 = VlanId.vlanId((short) 300); |
| 118 | protected static final VlanId VLAN400 = VlanId.vlanId((short) 400); |
| 119 | protected static final VlanId VLAN_NONE = VlanId.NONE; |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 120 | |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 121 | protected static final MacAddress MAC1 = getMac(1); |
| 122 | protected static final MacAddress MAC2 = getMac(2); |
| 123 | protected static final MacAddress MAC3 = getMac(3); |
| 124 | protected static final MacAddress MAC4 = getMac(4); |
| 125 | protected static final MacAddress MAC5 = getMac(5); |
| 126 | protected static final MacAddress MAC6 = getMac(6); |
| 127 | protected static final MacAddress MAC7 = getMac(7); |
| 128 | protected static final MacAddress MAC8 = getMac(8); |
| 129 | protected static final MacAddress MAC9 = getMac(9); |
| 130 | protected static final MacAddress MAC10 = getMac(10); |
| 131 | protected static final MacAddress MAC11 = getMac(11); |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 132 | |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 133 | protected static final Ip4Address IP1 = Ip4Address.valueOf("192.168.1.1"); |
| 134 | protected static final Ip4Address IP2 = Ip4Address.valueOf("192.168.1.2"); |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 135 | |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 136 | protected static final HostId HID1 = HostId.hostId(MAC1, VLAN100); |
| 137 | protected static final HostId HID2 = HostId.hostId(MAC2, VLAN100); |
| 138 | protected static final HostId HID3 = HostId.hostId(MAC3, VLAN200); |
| 139 | protected static final HostId HID4 = HostId.hostId(MAC4, VLAN200); |
| 140 | protected static final HostId HID5 = HostId.hostId(MAC5, VLAN300); |
| 141 | protected static final HostId HID6 = HostId.hostId(MAC6, VLAN300); |
| 142 | protected static final HostId HID7 = HostId.hostId(MAC7, VLAN300); |
| 143 | protected static final HostId HID8 = HostId.hostId(MAC8, VLAN400); |
| 144 | protected static final HostId HID9 = HostId.hostId(MAC9); |
| 145 | protected static final HostId HID10 = HostId.hostId(MAC10); |
| 146 | protected static final HostId HID11 = HostId.hostId(MAC11); |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 147 | |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 148 | protected static final ProviderId PID = new ProviderId("of", "foo"); |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 149 | |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 150 | protected static final NodeId NODE_ID_1 = new NodeId("Node1"); |
| 151 | protected static final NodeId NODE_ID_2 = new NodeId("Node2"); |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 152 | |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 153 | protected static final Interface V100H1 = |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 154 | new Interface("v100h1", CP1, null, null, VLAN100); |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 155 | protected static final Interface V100H2 = |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 156 | new Interface("v100h2", CP2, null, null, VLAN100); |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 157 | protected static final Interface V200H1 = |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 158 | new Interface("v200h1", CP3, null, null, VLAN200); |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 159 | protected static final Interface V200H2 = |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 160 | new Interface("v200h2", CP4, null, null, VLAN200); |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 161 | protected static final Interface V300H1 = |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 162 | new Interface("v300h1", CP5, null, null, VLAN300); |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 163 | protected static final Interface V300H2 = |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 164 | new Interface("v300h2", CP6, null, null, VLAN300); |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 165 | protected static final Interface V400H1 = |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 166 | new Interface("v400h1", CP7, null, null, VLAN400); |
| 167 | |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 168 | protected static final Interface VNONEH1 = |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 169 | new Interface("vNoneh1", CP8, null, null, VLAN_NONE); |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 170 | protected static final Interface VNONEH2 = |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 171 | new Interface("vNoneh2", CP9, null, null, VLAN_NONE); |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 172 | protected static final Interface VNONEH3 = |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 173 | new Interface("vNoneh3", CP10, null, null, VLAN_NONE); |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 174 | |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 175 | protected static final Host V100HOST1 = |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 176 | new DefaultHost(PID, HID1, MAC1, VLAN100, |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 177 | getLocation(1), Collections.singleton(IP1)); |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 178 | protected static final Host V100HOST2 = |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 179 | new DefaultHost(PID, HID2, MAC2, VLAN100, |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 180 | getLocation(2), Sets.newHashSet()); |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 181 | protected static final Host V200HOST1 = |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 182 | new DefaultHost(PID, HID3, MAC3, VLAN200, |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 183 | getLocation(3), Collections.singleton(IP2)); |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 184 | protected static final Host V200HOST2 = |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 185 | new DefaultHost(PID, HID4, MAC4, VLAN200, |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 186 | getLocation(4), Sets.newHashSet()); |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 187 | protected static final Host V300HOST1 = |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 188 | new DefaultHost(PID, HID5, MAC5, VLAN300, |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 189 | getLocation(5), Sets.newHashSet()); |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 190 | protected static final Host V300HOST2 = |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 191 | new DefaultHost(PID, HID6, MAC6, VLAN300, |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 192 | getLocation(6), Sets.newHashSet()); |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 193 | protected static final Host V300HOST3 = |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 194 | new DefaultHost(PID, HID7, MAC7, VLAN300, |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 195 | getLocation(7), Sets.newHashSet()); |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 196 | protected static final Host V400HOST1 = |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 197 | new DefaultHost(PID, HID8, MAC8, VLAN400, |
| 198 | getLocation(4, 2), Sets.newHashSet()); |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 199 | |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 200 | protected static final Host VNONEHOST1 = |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 201 | new DefaultHost(PID, HID9, MAC9, VlanId.NONE, |
| 202 | getLocation(3, 2), Sets.newHashSet()); |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 203 | protected static final Host VNONEHOST2 = |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 204 | new DefaultHost(PID, HID10, MAC10, VlanId.NONE, |
| 205 | getLocation(5, 1), Sets.newHashSet()); |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 206 | protected static final Host VNONEHOST3 = |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 207 | new DefaultHost(PID, HID11, MAC11, VlanId.NONE, |
| 208 | getLocation(5, 2), Sets.newHashSet()); |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 209 | |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 210 | protected static final Set<Interface> AVAILABLE_INTERFACES = |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 211 | ImmutableSet.of(V100H1, V100H2, V200H1, V200H2, V300H1, V300H2, |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 212 | V400H1, VNONEH1, VNONEH2, VNONEH3); |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 213 | |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 214 | protected static final Set<Host> AVAILABLE_HOSTS = |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 215 | ImmutableSet.of(V100HOST1, V100HOST2, V200HOST1, |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 216 | V200HOST2, V300HOST1, V300HOST2, V300HOST3, |
| 217 | VNONEHOST1, VNONEHOST2, |
| 218 | V400HOST1, VNONEHOST3); |
| 219 | |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 220 | |
| 221 | /** |
| 222 | * Returns the device Id of the ith device. |
| 223 | * |
| 224 | * @param i the device to get the Id of |
| 225 | * @return the device Id |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 226 | */ |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 227 | protected static DeviceId getDeviceId(int i) { |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 228 | return DeviceId.deviceId("" + i); |
| 229 | } |
| 230 | |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 231 | /** |
| 232 | * Generates a mac address by given number. |
| 233 | * |
| 234 | * @param n the number to generate mac address |
| 235 | * @return the mac address |
| 236 | */ |
| 237 | protected static MacAddress getMac(int n) { |
Dominika Molenda | 52cc3a9 | 2017-06-19 17:08:35 +0200 | [diff] [blame] | 238 | return MacAddress.valueOf(String.format("00:00:00:00:00:%02x", n)); |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 239 | } |
| 240 | |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 241 | /** |
| 242 | * Generates a host location by given device number. |
| 243 | * |
| 244 | * @param i the given number |
| 245 | * @return the host location |
| 246 | */ |
| 247 | protected static HostLocation getLocation(int i) { |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 248 | return new HostLocation(new ConnectPoint(getDeviceId(i), P1), 123L); |
| 249 | } |
| 250 | |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 251 | /** |
| 252 | * Generates host location by given device number and port number. |
| 253 | * |
| 254 | * @param d the device number |
| 255 | * @param p the port number |
| 256 | * @return the host location |
| 257 | */ |
| 258 | protected static HostLocation getLocation(int d, int p) { |
Carolina Fernandez | b1cef5c | 2016-11-22 19:18:40 +0100 | [diff] [blame] | 259 | return new HostLocation(new ConnectPoint(getDeviceId(d), |
| 260 | PortNumber.portNumber(p)), 123L); |
| 261 | } |
| 262 | |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 263 | /** |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 264 | * Test core service; For generate test application ID. |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 265 | */ |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 266 | public class TestCoreService extends CoreServiceAdapter { |
| 267 | @Override |
| 268 | public ApplicationId registerApplication(String name) { |
| 269 | return TestApplicationId.create(name); |
| 270 | } |
| 271 | } |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 272 | |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 273 | /** |
| 274 | * Test intent service. |
| 275 | * Always install or withdraw success for any Intents. |
| 276 | */ |
| 277 | public class TestIntentService extends IntentServiceAdapter { |
| 278 | IntentListener listener; |
| 279 | List<IntentData> intents; |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 280 | |
| 281 | public TestIntentService() { |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 282 | intents = Lists.newArrayList(); |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | @Override |
| 286 | public void submit(Intent intent) { |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 287 | intents.add(new IntentData(intent, IntentState.INSTALLED, new WallClockTimestamp())); |
| 288 | if (listener != null) { |
| 289 | IntentEvent.getEvent(IntentState.INSTALLED, intent).ifPresent(listener::event); |
| 290 | |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | @Override |
| 295 | public void withdraw(Intent intent) { |
| 296 | intents.forEach(intentData -> { |
| 297 | if (intentData.intent().key().equals(intent.key())) { |
| 298 | intentData.setState(IntentState.WITHDRAWN); |
| 299 | |
| 300 | if (listener != null) { |
| 301 | IntentEvent.getEvent(IntentState.WITHDRAWN, intent).ifPresent(listener::event); |
| 302 | } |
| 303 | } |
| 304 | }); |
| 305 | } |
| 306 | |
| 307 | @Override |
| 308 | public Iterable<Intent> getIntents() { |
| 309 | return intents.stream() |
| 310 | .map(IntentData::intent) |
| 311 | .collect(Collectors.toList()); |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | @Override |
| 315 | public long getIntentCount() { |
| 316 | return intents.size(); |
| 317 | } |
| 318 | |
| 319 | @Override |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 320 | public void addListener(IntentListener listener) { |
| 321 | this.listener = listener; |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | @Override |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 325 | public void removeListener(IntentListener listener) { |
| 326 | this.listener = null; |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 327 | } |
| 328 | } |
| 329 | |
| 330 | /** |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 331 | * Test leadership service. |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 332 | */ |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 333 | public class TestLeadershipService extends LeadershipServiceAdapter { |
| 334 | LeadershipEventListener listener; |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 335 | |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 336 | @Override |
| 337 | public void addListener(LeadershipEventListener listener) { |
| 338 | this.listener = listener; |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | @Override |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 342 | public void removeListener(LeadershipEventListener listener) { |
| 343 | this.listener = null; |
| 344 | } |
| 345 | |
| 346 | /** |
| 347 | * Sends the leadership event to the listener. |
| 348 | * |
| 349 | * @param event the Intent event |
| 350 | */ |
| 351 | public void sendEvent(LeadershipEvent event) { |
| 352 | if (listener != null && listener.isRelevant(event)) { |
| 353 | listener.event(event); |
| 354 | } |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | @Override |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 358 | public NodeId getLeader(String path) { |
| 359 | return NODE_ID_1; |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | /** |
| 364 | * Test interface service; contains all interfaces which already generated. |
| 365 | */ |
| 366 | public class TestInterfaceService implements InterfaceService { |
| 367 | |
| 368 | @Override |
| 369 | public void addListener(InterfaceListener listener) { |
| 370 | } |
| 371 | |
| 372 | @Override |
| 373 | public void removeListener(InterfaceListener listener) { |
| 374 | } |
| 375 | |
| 376 | @Override |
| 377 | public Set<Interface> getInterfaces() { |
| 378 | return AVAILABLE_INTERFACES; |
| 379 | } |
| 380 | |
| 381 | @Override |
| 382 | public Interface getInterfaceByName(ConnectPoint connectPoint, |
| 383 | String name) { |
| 384 | return AVAILABLE_INTERFACES.stream() |
| 385 | .filter(intf -> intf.name().equals(name)) |
| 386 | .findFirst() |
| 387 | .orElse(null); |
| 388 | } |
| 389 | |
| 390 | @Override |
| 391 | public Set<Interface> getInterfacesByPort(ConnectPoint port) { |
| 392 | return AVAILABLE_INTERFACES.stream() |
| 393 | .filter(intf -> intf.connectPoint().equals(port)) |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 394 | .collect(Collectors.toSet()); |
| 395 | } |
| 396 | |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 397 | @Override |
| 398 | public Set<Interface> getInterfacesByIp(IpAddress ip) { |
| 399 | return AVAILABLE_INTERFACES.stream() |
Yuta HIGUCHI | 488a94c | 2018-01-26 17:24:09 -0800 | [diff] [blame] | 400 | .filter(intf -> intf.ipAddressesList().stream() |
| 401 | .map(InterfaceIpAddress::ipAddress) |
| 402 | .filter(ip::equals) |
| 403 | .findAny() |
| 404 | .isPresent()) |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 405 | .collect(Collectors.toSet()); |
| 406 | } |
| 407 | |
| 408 | @Override |
| 409 | public Set<Interface> getInterfacesByVlan(VlanId vlan) { |
| 410 | return AVAILABLE_INTERFACES.stream() |
| 411 | .filter(intf -> intf.vlan().equals(vlan)) |
| 412 | .collect(Collectors.toSet()); |
| 413 | } |
| 414 | |
| 415 | @Override |
| 416 | public Interface getMatchingInterface(IpAddress ip) { |
| 417 | return AVAILABLE_INTERFACES.stream() |
Yuta HIGUCHI | 488a94c | 2018-01-26 17:24:09 -0800 | [diff] [blame] | 418 | .filter(intf -> intf.ipAddressesList().stream() |
| 419 | .map(InterfaceIpAddress::ipAddress) |
| 420 | .filter(ip::equals) |
| 421 | .findAny() |
| 422 | .isPresent()) |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 423 | .findFirst() |
| 424 | .orElse(null); |
| 425 | } |
| 426 | |
| 427 | @Override |
| 428 | public Set<Interface> getMatchingInterfaces(IpAddress ip) { |
| 429 | return AVAILABLE_INTERFACES.stream() |
Yuta HIGUCHI | 488a94c | 2018-01-26 17:24:09 -0800 | [diff] [blame] | 430 | .filter(intf -> intf.ipAddressesList().stream() |
| 431 | .map(InterfaceIpAddress::ipAddress) |
| 432 | .filter(ip::equals) |
| 433 | .findAny() |
| 434 | .isPresent()) |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 435 | .collect(Collectors.toSet()); |
| 436 | } |
Saurav Das | 9a55429 | 2018-04-27 18:42:30 -0700 | [diff] [blame] | 437 | |
| 438 | @Override |
| 439 | public boolean isConfigured(ConnectPoint connectPoint) { |
| 440 | for (Interface intf : AVAILABLE_INTERFACES) { |
| 441 | if (!intf.connectPoint().equals(connectPoint)) { |
| 442 | continue; |
| 443 | } |
| 444 | if (!intf.ipAddressesList().isEmpty() |
| 445 | || intf.vlan() != VlanId.NONE |
| 446 | || intf.vlanNative() != VlanId.NONE |
| 447 | || intf.vlanUntagged() != VlanId.NONE |
| 448 | || !intf.vlanTagged().isEmpty()) { |
| 449 | return true; |
| 450 | } |
| 451 | } |
| 452 | return false; |
| 453 | } |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | /** |
| 457 | * Test VPLS store. |
| 458 | */ |
| 459 | public class TestVplsStore extends VplsStoreAdapter { |
| 460 | /** |
| 461 | * Clears the store. |
| 462 | */ |
| 463 | public void clear() { |
| 464 | vplsDataMap.clear(); |
| 465 | } |
| 466 | |
| 467 | /** |
| 468 | * Gets the store delegate. |
| 469 | * |
| 470 | * @return the store delegate |
| 471 | */ |
| 472 | public StoreDelegate<VplsStoreEvent> delegate() { |
| 473 | return this.delegate; |
| 474 | } |
| 475 | } |
| 476 | |
| 477 | /** |
| 478 | * Test VPLS. |
| 479 | * Provides basic VPLS functionality and stores VPLS information. |
| 480 | */ |
| 481 | public class TestVpls implements Vpls { |
| 482 | public Map<String, VplsData> testData; |
| 483 | |
| 484 | public TestVpls() { |
| 485 | testData = Maps.newHashMap(); |
| 486 | } |
| 487 | |
| 488 | public void initSampleData() { |
| 489 | testData.clear(); |
| 490 | VplsData vplsData = VplsData.of(VPLS1); |
| 491 | vplsData.addInterfaces(ImmutableSet.of(V100H1, V100H2)); |
| 492 | vplsData.state(VplsData.VplsState.ADDED); |
| 493 | testData.put(VPLS1, vplsData); |
| 494 | |
| 495 | vplsData = VplsData.of(VPLS2); |
| 496 | vplsData.addInterfaces(ImmutableSet.of(V200H1, V200H2)); |
| 497 | vplsData.state(VplsData.VplsState.ADDED); |
| 498 | testData.put(VPLS2, vplsData); |
| 499 | } |
| 500 | |
| 501 | @Override |
| 502 | public VplsData createVpls(String vplsName, EncapsulationType encapsulationType) { |
| 503 | VplsData vplsData = VplsData.of(vplsName, encapsulationType); |
Yi Tseng | 3069c61 | 2017-05-26 17:09:43 -0700 | [diff] [blame] | 504 | vplsData.state(VplsData.VplsState.ADDED); |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 505 | testData.put(vplsName, vplsData); |
| 506 | return vplsData; |
| 507 | } |
| 508 | |
| 509 | @Override |
| 510 | public VplsData removeVpls(VplsData vplsData) { |
| 511 | if (!testData.containsKey(vplsData.name())) { |
| 512 | return null; |
| 513 | } |
| 514 | |
| 515 | testData.remove(vplsData.name()); |
| 516 | return vplsData; |
| 517 | } |
| 518 | |
| 519 | @Override |
| 520 | public void addInterfaces(VplsData vplsData, Collection<Interface> interfaces) { |
| 521 | vplsData.addInterfaces(interfaces); |
| 522 | testData.put(vplsData.name(), vplsData); |
| 523 | } |
| 524 | |
| 525 | @Override |
| 526 | public void addInterface(VplsData vplsData, Interface iface) { |
| 527 | vplsData.addInterface(iface); |
| 528 | testData.put(vplsData.name(), vplsData); |
| 529 | } |
| 530 | |
| 531 | @Override |
| 532 | public void setEncapsulationType(VplsData vplsData, EncapsulationType encapsulationType) { |
| 533 | vplsData.encapsulationType(encapsulationType); |
| 534 | testData.put(vplsData.name(), vplsData); |
| 535 | } |
| 536 | |
| 537 | @Override |
| 538 | public VplsData getVpls(String vplsName) { |
| 539 | return testData.get(vplsName); |
| 540 | } |
| 541 | |
| 542 | @Override |
| 543 | public Collection<VplsData> getAllVpls() { |
| 544 | return testData.values(); |
| 545 | } |
| 546 | |
| 547 | @Override |
| 548 | public Collection<Interface> removeInterfaces(VplsData vplsData, Collection<Interface> interfaces) { |
| 549 | vplsData.removeInterfaces(interfaces); |
| 550 | testData.put(vplsData.name(), vplsData); |
| 551 | return interfaces; |
| 552 | } |
| 553 | |
| 554 | @Override |
| 555 | public Interface removeInterface(VplsData vplsData, Interface iface) { |
| 556 | vplsData.removeInterface(iface); |
| 557 | testData.put(vplsData.name(), vplsData); |
| 558 | return iface; |
| 559 | } |
| 560 | |
| 561 | @Override |
| 562 | public void removeAllVpls() { |
| 563 | testData.clear(); |
| 564 | } |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 565 | } |
| 566 | |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 567 | /** |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 568 | * Test host service; contains all hosts which already generated. |
| 569 | * |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 570 | */ |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 571 | public class TestHostService extends HostServiceAdapter { |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 572 | |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 573 | private HostListener listener; |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 574 | |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 575 | @Override |
| 576 | public Set<Host> getConnectedHosts(ConnectPoint connectPoint) { |
| 577 | return AVAILABLE_HOSTS.stream() |
| 578 | .filter(host -> host.location().equals(connectPoint)) |
| 579 | .collect(Collectors.toSet()); |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 580 | } |
| 581 | |
| 582 | @Override |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 583 | public Set<Host> getHostsByMac(MacAddress mac) { |
| 584 | return AVAILABLE_HOSTS.stream() |
| 585 | .filter(host -> host.mac().equals(mac)) |
| 586 | .collect(Collectors.toSet()); |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | @Override |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 590 | public Iterable<Host> getHosts() { |
| 591 | return AVAILABLE_HOSTS; |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | @Override |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 595 | public Set<Host> getHostsByVlan(VlanId vlanId) { |
| 596 | return AVAILABLE_HOSTS.stream() |
| 597 | .filter(host -> host.vlan().equals(vlanId)) |
| 598 | .collect(Collectors.toSet()); |
| 599 | } |
| 600 | |
| 601 | @Override |
| 602 | public int getHostCount() { |
| 603 | return AVAILABLE_HOSTS.size(); |
| 604 | } |
| 605 | |
| 606 | @Override |
| 607 | public Host getHost(HostId hostId) { |
| 608 | return AVAILABLE_HOSTS.stream() |
| 609 | .filter(host -> host.id().equals(hostId)) |
| 610 | .findFirst() |
| 611 | .orElse(null); |
| 612 | } |
| 613 | |
| 614 | @Override |
| 615 | public void addListener(HostListener listener) { |
| 616 | this.listener = listener; |
| 617 | } |
| 618 | |
| 619 | public void postHostEvent(HostEvent hostEvent) { |
| 620 | this.listener.event(hostEvent); |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 621 | } |
| 622 | } |
| 623 | |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 624 | /** |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 625 | * Test network configuration service. |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 626 | */ |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 627 | public class TestConfigService extends NetworkConfigServiceAdapter { |
| 628 | public static final String EMPTY_JSON_TREE = "{}"; |
| 629 | NetworkConfigListener listener; |
| 630 | VplsAppConfig vplsAppConfig; |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 631 | |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 632 | @Override |
| 633 | public void addListener(NetworkConfigListener listener) { |
| 634 | this.listener = listener; |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | @Override |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 638 | public void removeListener(NetworkConfigListener listener) { |
| 639 | this.listener = null; |
| 640 | } |
| 641 | |
| 642 | /** |
| 643 | * Sends network config event to listener. |
| 644 | * |
| 645 | * @param event the network config event |
| 646 | */ |
| 647 | public void sendEvent(NetworkConfigEvent event) { |
| 648 | if (listener != null) { |
| 649 | listener.event(event); |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 650 | } |
| 651 | } |
| 652 | |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 653 | /** |
| 654 | * Constructs test config service. |
| 655 | * Generates an VPLS configuration with sample VPLS configs. |
| 656 | */ |
| 657 | public TestConfigService() { |
| 658 | vplsAppConfig = new VplsAppConfig(); |
| 659 | final ObjectMapper mapper = new ObjectMapper(); |
| 660 | final ConfigApplyDelegate delegate = new VplsAppConfigTest.MockCfgDelegate(); |
| 661 | JsonNode tree = null; |
| 662 | try { |
| 663 | tree = new ObjectMapper().readTree(EMPTY_JSON_TREE); |
| 664 | } catch (IOException e) { |
| 665 | e.printStackTrace(); |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 666 | } |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 667 | vplsAppConfig.init(APPID, APP_NAME, tree, mapper, delegate); |
| 668 | VplsConfig vplsConfig = new VplsConfig(VPLS1, |
| 669 | ImmutableSet.of(V100H1.name(), V100H2.name()), |
| 670 | EncapsulationType.NONE); |
| 671 | vplsAppConfig.addVpls(vplsConfig); |
| 672 | vplsConfig = new VplsConfig(VPLS2, |
| 673 | ImmutableSet.of(V200H1.name(), V200H2.name()), |
| 674 | EncapsulationType.VLAN); |
| 675 | vplsAppConfig.addVpls(vplsConfig); |
| 676 | |
| 677 | } |
| 678 | |
| 679 | /** |
| 680 | * Overrides VPLS config to the config service. |
| 681 | * |
| 682 | * @param vplsAppConfig the new VPLS config |
| 683 | */ |
| 684 | public void setConfig(VplsAppConfig vplsAppConfig) { |
| 685 | this.vplsAppConfig = vplsAppConfig; |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 686 | } |
| 687 | |
| 688 | @Override |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 689 | public <S, C extends Config<S>> C getConfig(S subject, Class<C> configClass) { |
| 690 | return (C) vplsAppConfig; |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 691 | } |
| 692 | |
| 693 | @Override |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 694 | public <S, C extends Config<S>> C addConfig(S subject, Class<C> configClass) { |
| 695 | return (C) vplsAppConfig; |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 696 | } |
nosignal | 5fd282e | 2016-09-16 16:11:40 -0700 | [diff] [blame] | 697 | } |
Yi Tseng | f4e13e3 | 2017-03-30 15:38:39 -0700 | [diff] [blame] | 698 | |
Luca Prete | 9c2ee07 | 2016-02-16 11:00:44 -0800 | [diff] [blame] | 699 | } |