Committed by
Gerrit Code Review
[ONOS-2365]Unit test for PcepTunnelProvider
Change-Id: I2903756913225acf43b324da90faa76bd41b6533
Showing
8 changed files
with
833 additions
and
0 deletions
providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepClientAdapter.java
0 → 100644
| 1 | +package org.onosproject.provider.pcep.tunnel.impl; | ||
| 2 | + | ||
| 3 | +import static org.junit.Assert.assertNotNull; | ||
| 4 | + | ||
| 5 | +import java.util.List; | ||
| 6 | +import java.util.concurrent.RejectedExecutionException; | ||
| 7 | + | ||
| 8 | +import org.jboss.netty.channel.Channel; | ||
| 9 | +import org.onosproject.pcep.controller.PccId; | ||
| 10 | +import org.onosproject.pcep.controller.PcepClient; | ||
| 11 | +import org.onosproject.pcepio.protocol.PcepFactories; | ||
| 12 | +import org.onosproject.pcepio.protocol.PcepFactory; | ||
| 13 | +import org.onosproject.pcepio.protocol.PcepMessage; | ||
| 14 | +import org.onosproject.pcepio.protocol.PcepVersion; | ||
| 15 | + | ||
| 16 | +public class PcepClientAdapter implements PcepClient { | ||
| 17 | + | ||
| 18 | + private Channel channel; | ||
| 19 | + protected String channelId; | ||
| 20 | + | ||
| 21 | + private boolean connected; | ||
| 22 | + private PccId pccId; | ||
| 23 | + | ||
| 24 | + private PcepVersion pcepVersion; | ||
| 25 | + | ||
| 26 | + public void init(PccId pccId, PcepVersion pcepVersion) { | ||
| 27 | + this.pccId = pccId; | ||
| 28 | + this.pcepVersion = pcepVersion; | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + @Override | ||
| 32 | + public final void disconnectClient() { | ||
| 33 | + this.channel.close(); | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + @Override | ||
| 37 | + public final void sendMessage(PcepMessage m) { | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + @Override | ||
| 41 | + public final void sendMessage(List<PcepMessage> msgs) { | ||
| 42 | + try { | ||
| 43 | + PcepMessage pcepMsg = msgs.get(0); | ||
| 44 | + assertNotNull("PCEP MSG should be created.", pcepMsg); | ||
| 45 | + } catch (RejectedExecutionException e) { | ||
| 46 | + throw e; | ||
| 47 | + } | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + @Override | ||
| 51 | + public final boolean isConnected() { | ||
| 52 | + return this.connected; | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + @Override | ||
| 56 | + public String channelId() { | ||
| 57 | + return channelId; | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + @Override | ||
| 61 | + public final PccId getPccId() { | ||
| 62 | + return this.pccId; | ||
| 63 | + }; | ||
| 64 | + | ||
| 65 | + @Override | ||
| 66 | + public final String getStringId() { | ||
| 67 | + return this.pccId.toString(); | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + @Override | ||
| 71 | + public final void handleMessage(PcepMessage m) { | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + @Override | ||
| 75 | + public boolean isOptical() { | ||
| 76 | + return false; | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + @Override | ||
| 80 | + public PcepFactory factory() { | ||
| 81 | + return PcepFactories.getFactory(pcepVersion); | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + @Override | ||
| 85 | + public final boolean isSyncComplete() { | ||
| 86 | + return false; | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + @Override | ||
| 90 | + public final void setIsSyncComplete(boolean value) { | ||
| 91 | + } | ||
| 92 | +} |
| 1 | +package org.onosproject.provider.pcep.tunnel.impl; | ||
| 2 | + | ||
| 3 | +import java.util.Collection; | ||
| 4 | +import java.util.Collections; | ||
| 5 | +import java.util.HashSet; | ||
| 6 | +import java.util.Set; | ||
| 7 | +import java.util.concurrent.ConcurrentHashMap; | ||
| 8 | + | ||
| 9 | +import org.apache.felix.scr.annotations.Activate; | ||
| 10 | +import org.apache.felix.scr.annotations.Deactivate; | ||
| 11 | +import org.onlab.packet.IpAddress; | ||
| 12 | +import org.onosproject.pcep.controller.PccId; | ||
| 13 | +import org.onosproject.pcep.controller.PcepClient; | ||
| 14 | +import org.onosproject.pcep.controller.PcepClientController; | ||
| 15 | +import org.onosproject.pcep.controller.PcepClientListener; | ||
| 16 | +import org.onosproject.pcep.controller.PcepEventListener; | ||
| 17 | +import org.onosproject.pcep.controller.driver.PcepAgent; | ||
| 18 | +import org.onosproject.pcepio.protocol.PcepMessage; | ||
| 19 | +import org.onosproject.pcepio.protocol.PcepVersion; | ||
| 20 | + | ||
| 21 | +import com.google.common.collect.Sets; | ||
| 22 | + | ||
| 23 | +public class PcepClientControllerAdapter implements PcepClientController { | ||
| 24 | + | ||
| 25 | + protected ConcurrentHashMap<PccId, PcepClient> connectedClients = | ||
| 26 | + new ConcurrentHashMap<PccId, PcepClient>(); | ||
| 27 | + | ||
| 28 | + protected PcepClientAgent agent = new PcepClientAgent(); | ||
| 29 | + protected Set<PcepClientListener> pcepClientListener = new HashSet<>(); | ||
| 30 | + | ||
| 31 | + protected Set<PcepEventListener> pcepEventListener = Sets.newHashSet(); | ||
| 32 | + | ||
| 33 | + @Activate | ||
| 34 | + public void activate() { | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + @Deactivate | ||
| 38 | + public void deactivate() { | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + @Override | ||
| 42 | + public Collection<PcepClient> getClients() { | ||
| 43 | + return connectedClients.values(); | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + @Override | ||
| 47 | + public PcepClient getClient(PccId pccId) { | ||
| 48 | + //return connectedClients.get(pccIpAddress); | ||
| 49 | + PcepClientAdapter pc = new PcepClientAdapter(); | ||
| 50 | + pc.init(PccId.pccId(IpAddress.valueOf(0xac000001)), PcepVersion.PCEP_1); | ||
| 51 | + return pc; | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + @Override | ||
| 55 | + public void addListener(PcepClientListener listener) { | ||
| 56 | + if (!pcepClientListener.contains(listener)) { | ||
| 57 | + this.pcepClientListener.add(listener); | ||
| 58 | + } | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + @Override | ||
| 62 | + public void removeListener(PcepClientListener listener) { | ||
| 63 | + this.pcepClientListener.remove(listener); | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + @Override | ||
| 67 | + public void addEventListener(PcepEventListener listener) { | ||
| 68 | + pcepEventListener.add(listener); | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + @Override | ||
| 72 | + public void removeEventListener(PcepEventListener listener) { | ||
| 73 | + pcepEventListener.remove(listener); | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + @Override | ||
| 77 | + public void writeMessage(PccId pccId, PcepMessage msg) { | ||
| 78 | + this.getClient(pccId).sendMessage(msg); | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + @Override | ||
| 82 | + public void processClientMessage(PccId pccId, PcepMessage msg) { | ||
| 83 | + | ||
| 84 | + PcepClient pc = getClient(pccId); | ||
| 85 | + | ||
| 86 | + switch (msg.getType()) { | ||
| 87 | + case NONE: | ||
| 88 | + break; | ||
| 89 | + case OPEN: | ||
| 90 | + break; | ||
| 91 | + case KEEP_ALIVE: | ||
| 92 | + //log.debug("Sending Keep Alive Message to {" + pccIpAddress.toString() + "}"); | ||
| 93 | + pc.sendMessage(Collections.singletonList(pc.factory().buildKeepaliveMsg().build())); | ||
| 94 | + break; | ||
| 95 | + case PATH_COMPUTATION_REQUEST: | ||
| 96 | + break; | ||
| 97 | + case PATH_COMPUTATION_REPLY: | ||
| 98 | + break; | ||
| 99 | + case NOTIFICATION: | ||
| 100 | + break; | ||
| 101 | + case ERROR: | ||
| 102 | + break; | ||
| 103 | + case CLOSE: | ||
| 104 | + //log.debug("Sending Close Message to { }", pccIpAddress.toString()); | ||
| 105 | + pc.sendMessage(Collections.singletonList(pc.factory().buildCloseMsg().build())); | ||
| 106 | + break; | ||
| 107 | + case REPORT: | ||
| 108 | + for (PcepEventListener l : pcepEventListener) { | ||
| 109 | + l.handleMessage(pccId, msg); | ||
| 110 | + } | ||
| 111 | + break; | ||
| 112 | + case UPDATE: | ||
| 113 | + for (PcepEventListener l : pcepEventListener) { | ||
| 114 | + l.handleMessage(pccId, msg); | ||
| 115 | + } | ||
| 116 | + break; | ||
| 117 | + case INITIATE: | ||
| 118 | + for (PcepEventListener l : pcepEventListener) { | ||
| 119 | + l.handleMessage(pccId, msg); | ||
| 120 | + } | ||
| 121 | + break; | ||
| 122 | + case LABEL_UPDATE: | ||
| 123 | + break; | ||
| 124 | + case MAX: | ||
| 125 | + break; | ||
| 126 | + case END: | ||
| 127 | + break; | ||
| 128 | + default: | ||
| 129 | + break; | ||
| 130 | + } | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | + @Override | ||
| 134 | + public void closeConnectedClients() { | ||
| 135 | + PcepClient pc; | ||
| 136 | + for (PccId id : connectedClients.keySet()) { | ||
| 137 | + pc = getClient(id); | ||
| 138 | + pc.disconnectClient(); | ||
| 139 | + } | ||
| 140 | + } | ||
| 141 | + | ||
| 142 | + /** | ||
| 143 | + * Implementation of an Pcep Agent which is responsible for | ||
| 144 | + * keeping track of connected clients and the state in which | ||
| 145 | + * they are. | ||
| 146 | + */ | ||
| 147 | + public class PcepClientAgent implements PcepAgent { | ||
| 148 | + | ||
| 149 | + @Override | ||
| 150 | + public boolean addConnectedClient(PccId pccId, PcepClient pc) { | ||
| 151 | + | ||
| 152 | + if (connectedClients.get(pccId) != null) { | ||
| 153 | + return false; | ||
| 154 | + } else { | ||
| 155 | + connectedClients.put(pccId, pc); | ||
| 156 | + for (PcepClientListener l : pcepClientListener) { | ||
| 157 | + l.clientConnected(pccId); | ||
| 158 | + } | ||
| 159 | + return true; | ||
| 160 | + } | ||
| 161 | + } | ||
| 162 | + | ||
| 163 | + @Override | ||
| 164 | + public boolean validActivation(PccId pccId) { | ||
| 165 | + if (connectedClients.get(pccId) == null) { | ||
| 166 | + //log.error("Trying to activate client but is not in " | ||
| 167 | + // + "connected switches: pccIp {}. Aborting ..", pccIpAddress.toString()); | ||
| 168 | + return false; | ||
| 169 | + } | ||
| 170 | + | ||
| 171 | + return true; | ||
| 172 | + } | ||
| 173 | + | ||
| 174 | + @Override | ||
| 175 | + public void removeConnectedClient(PccId pccId) { | ||
| 176 | + connectedClients.remove(pccId); | ||
| 177 | + for (PcepClientListener l : pcepClientListener) { | ||
| 178 | + //log.warn("removal for {}", pccIpAddress.toString()); | ||
| 179 | + l.clientDisconnected(pccId); | ||
| 180 | + } | ||
| 181 | + } | ||
| 182 | + | ||
| 183 | + @Override | ||
| 184 | + public void processPcepMessage(PccId pccId, PcepMessage m) { | ||
| 185 | + processClientMessage(pccId, m); | ||
| 186 | + } | ||
| 187 | + } | ||
| 188 | + | ||
| 189 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2014 Open Networking Laboratory | ||
| 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 | + */ | ||
| 16 | + | ||
| 17 | +package org.onosproject.provider.pcep.tunnel.impl; | ||
| 18 | + | ||
| 19 | +import org.onosproject.net.DeviceId; | ||
| 20 | +import org.onosproject.pcep.api.PcepController; | ||
| 21 | +import org.onosproject.pcep.api.PcepDpid; | ||
| 22 | +import org.onosproject.pcep.api.PcepLinkListener; | ||
| 23 | +import org.onosproject.pcep.api.PcepSwitch; | ||
| 24 | +import org.onosproject.pcep.api.PcepSwitchListener; | ||
| 25 | +import org.onosproject.pcep.api.PcepTunnel; | ||
| 26 | +import org.onosproject.pcep.api.PcepTunnelListener; | ||
| 27 | + | ||
| 28 | +public class PcepControllerAdapter implements PcepController { | ||
| 29 | + | ||
| 30 | + @Override | ||
| 31 | + public Iterable<PcepSwitch> getSwitches() { | ||
| 32 | + return null; | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + @Override | ||
| 36 | + public PcepSwitch getSwitch(PcepDpid did) { | ||
| 37 | + return null; | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + @Override | ||
| 41 | + public void addListener(PcepSwitchListener listener) { | ||
| 42 | + | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + @Override | ||
| 46 | + public void removeListener(PcepSwitchListener listener) { | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + @Override | ||
| 50 | + public void addLinkListener(PcepLinkListener listener) { | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + @Override | ||
| 54 | + public void removeLinkListener(PcepLinkListener listener) { | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + @Override | ||
| 58 | + public void addTunnelListener(PcepTunnelListener listener) { | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + @Override | ||
| 62 | + public void removeTunnelListener(PcepTunnelListener listener) { | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + @Override | ||
| 66 | + public PcepTunnel applyTunnel(DeviceId srcDid, DeviceId dstDid, long srcPort, long dstPort, long bandwidth, | ||
| 67 | + String name) { | ||
| 68 | + return null; | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + @Override | ||
| 72 | + public Boolean deleteTunnel(String id) { | ||
| 73 | + return null; | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + @Override | ||
| 77 | + public Boolean updateTunnelBandwidth(String id, long bandwidth) { | ||
| 78 | + return null; | ||
| 79 | + } | ||
| 80 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2014 Open Networking Laboratory | ||
| 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 | + */ | ||
| 16 | +package org.onosproject.provider.pcep.tunnel.impl; | ||
| 17 | + | ||
| 18 | +import static org.onosproject.net.DefaultAnnotations.EMPTY; | ||
| 19 | + | ||
| 20 | +import java.io.IOException; | ||
| 21 | +import java.util.ArrayList; | ||
| 22 | +import java.util.List; | ||
| 23 | + | ||
| 24 | +import org.junit.After; | ||
| 25 | +import org.junit.Test; | ||
| 26 | +import org.onlab.packet.IpAddress; | ||
| 27 | +import org.onosproject.core.DefaultGroupId; | ||
| 28 | +import org.onosproject.incubator.net.tunnel.DefaultTunnel; | ||
| 29 | +import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint; | ||
| 30 | +import org.onosproject.incubator.net.tunnel.Tunnel; | ||
| 31 | +import org.onosproject.incubator.net.tunnel.TunnelId; | ||
| 32 | +import org.onosproject.incubator.net.tunnel.TunnelName; | ||
| 33 | +import org.onosproject.net.ConnectPoint; | ||
| 34 | +import org.onosproject.net.DefaultLink; | ||
| 35 | +import org.onosproject.net.DefaultPath; | ||
| 36 | +import org.onosproject.net.IpElementId; | ||
| 37 | +import org.onosproject.net.Link; | ||
| 38 | +import org.onosproject.net.Path; | ||
| 39 | +import org.onosproject.net.PortNumber; | ||
| 40 | +import org.onosproject.net.provider.ProviderId; | ||
| 41 | +import org.onosproject.pcepio.types.StatefulIPv4LspIdentidiersTlv; | ||
| 42 | + | ||
| 43 | + | ||
| 44 | +public class PcepReleaseTunnelProviderTest { | ||
| 45 | + | ||
| 46 | + static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep"; | ||
| 47 | + PcepTunnelProvider tunnelProvider = new PcepTunnelProvider(); | ||
| 48 | + private final TunnelProviderRegistryAdapter registry = new TunnelProviderRegistryAdapter(); | ||
| 49 | + private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter(); | ||
| 50 | + private final PcepControllerAdapter ctl = new PcepControllerAdapter(); | ||
| 51 | + private final PcepTunnelApiMapper pcepTunnelAPIMapper = new PcepTunnelApiMapper(); | ||
| 52 | + | ||
| 53 | + @Test | ||
| 54 | + public void testCasePcepReleaseTunnel() { | ||
| 55 | + tunnelProvider.tunnelProviderRegistry = registry; | ||
| 56 | + tunnelProvider.pcepClientController = controller; | ||
| 57 | + tunnelProvider.controller = ctl; | ||
| 58 | + tunnelProvider.pcepTunnelAPIMapper = pcepTunnelAPIMapper; | ||
| 59 | + tunnelProvider.activate(); | ||
| 60 | + | ||
| 61 | + Tunnel tunnel; | ||
| 62 | + Path path; | ||
| 63 | + List<Link> links = new ArrayList<Link>(); | ||
| 64 | + | ||
| 65 | + ProviderId pid = new ProviderId("pcep", PROVIDER_ID); | ||
| 66 | + | ||
| 67 | + IpAddress srcIp = IpAddress.valueOf(0xB6024E20); | ||
| 68 | + IpElementId srcElementId = IpElementId.ipElement(srcIp); | ||
| 69 | + | ||
| 70 | + IpAddress dstIp = IpAddress.valueOf(0xB6024E21); | ||
| 71 | + IpElementId dstElementId = IpElementId.ipElement(dstIp); | ||
| 72 | + | ||
| 73 | + IpTunnelEndPoint ipTunnelEndPointSrc; | ||
| 74 | + ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp); | ||
| 75 | + | ||
| 76 | + IpTunnelEndPoint ipTunnelEndPointDst; | ||
| 77 | + ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp); | ||
| 78 | + | ||
| 79 | + ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023)); | ||
| 80 | + | ||
| 81 | + ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023)); | ||
| 82 | + | ||
| 83 | + Link link = new DefaultLink(pid, src, dst, Link.Type.DIRECT, EMPTY); | ||
| 84 | + links.add(link); | ||
| 85 | + | ||
| 86 | + path = new DefaultPath(pid, links, 20, EMPTY); | ||
| 87 | + | ||
| 88 | + tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS, | ||
| 89 | + new DefaultGroupId(0), TunnelId.valueOf(1), TunnelName.tunnelName("T123"), | ||
| 90 | + path, EMPTY); | ||
| 91 | + | ||
| 92 | + // for releasing tunnel tunnel should exist in db | ||
| 93 | + PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.DELETE); | ||
| 94 | + pcepTunnelData.setPlspId(1); | ||
| 95 | + StatefulIPv4LspIdentidiersTlv tlv = new StatefulIPv4LspIdentidiersTlv(0, (short) 1, (short) 2, 3, 4); | ||
| 96 | + pcepTunnelData.setStatefulIpv4IndentifierTlv(tlv); | ||
| 97 | + tunnelProvider.pcepTunnelAPIMapper.addToTunnelIdMap(pcepTunnelData); | ||
| 98 | + | ||
| 99 | + tunnelProvider.pcepTunnelAPIMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData); | ||
| 100 | + | ||
| 101 | + tunnelProvider.releaseTunnel(tunnel); | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + | ||
| 105 | + @After | ||
| 106 | + public void tearDown() throws IOException { | ||
| 107 | + tunnelProvider.deactivate(); | ||
| 108 | + tunnelProvider.controller = null; | ||
| 109 | + tunnelProvider.pcepClientController = null; | ||
| 110 | + tunnelProvider.tunnelProviderRegistry = null; | ||
| 111 | + } | ||
| 112 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2014 Open Networking Laboratory | ||
| 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 | + */ | ||
| 16 | +package org.onosproject.provider.pcep.tunnel.impl; | ||
| 17 | + | ||
| 18 | +import static org.onosproject.net.DefaultAnnotations.EMPTY; | ||
| 19 | + | ||
| 20 | +import java.io.IOException; | ||
| 21 | +import java.util.ArrayList; | ||
| 22 | +import java.util.List; | ||
| 23 | + | ||
| 24 | +import org.junit.After; | ||
| 25 | +import org.junit.Test; | ||
| 26 | +import org.onlab.packet.IpAddress; | ||
| 27 | +import org.onosproject.core.DefaultGroupId; | ||
| 28 | +import org.onosproject.incubator.net.tunnel.DefaultTunnel; | ||
| 29 | +import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint; | ||
| 30 | +import org.onosproject.incubator.net.tunnel.Tunnel; | ||
| 31 | +import org.onosproject.incubator.net.tunnel.TunnelId; | ||
| 32 | +import org.onosproject.incubator.net.tunnel.TunnelName; | ||
| 33 | +import org.onosproject.net.ConnectPoint; | ||
| 34 | +import org.onosproject.net.DefaultLink; | ||
| 35 | +import org.onosproject.net.DefaultPath; | ||
| 36 | +import org.onosproject.net.IpElementId; | ||
| 37 | +import org.onosproject.net.Link; | ||
| 38 | +import org.onosproject.net.Path; | ||
| 39 | +import org.onosproject.net.PortNumber; | ||
| 40 | +import org.onosproject.net.provider.ProviderId; | ||
| 41 | + | ||
| 42 | +public class PcepSetupTunnelProviderTest { | ||
| 43 | + | ||
| 44 | + static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep"; | ||
| 45 | + PcepTunnelProvider tunnelProvider = new PcepTunnelProvider(); | ||
| 46 | + private final TunnelProviderRegistryAdapter registry = new TunnelProviderRegistryAdapter(); | ||
| 47 | + private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter(); | ||
| 48 | + private final PcepControllerAdapter ctl = new PcepControllerAdapter(); | ||
| 49 | + | ||
| 50 | + @Test | ||
| 51 | + public void testCasePcepSetupTunnel() { | ||
| 52 | + | ||
| 53 | + tunnelProvider.tunnelProviderRegistry = registry; | ||
| 54 | + tunnelProvider.pcepClientController = controller; | ||
| 55 | + tunnelProvider.controller = ctl; | ||
| 56 | + tunnelProvider.activate(); | ||
| 57 | + | ||
| 58 | + | ||
| 59 | + Tunnel tunnel; | ||
| 60 | + Path path; | ||
| 61 | + ProviderId pid = new ProviderId("pcep", PROVIDER_ID); | ||
| 62 | + List<Link> links = new ArrayList<Link>(); | ||
| 63 | + IpAddress srcIp = IpAddress.valueOf(0xC010101); | ||
| 64 | + IpElementId srcElementId = IpElementId.ipElement(srcIp); | ||
| 65 | + | ||
| 66 | + IpAddress dstIp = IpAddress.valueOf(0xC010102); | ||
| 67 | + IpElementId dstElementId = IpElementId.ipElement(dstIp); | ||
| 68 | + | ||
| 69 | + IpTunnelEndPoint ipTunnelEndPointSrc; | ||
| 70 | + ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp); | ||
| 71 | + | ||
| 72 | + IpTunnelEndPoint ipTunnelEndPointDst; | ||
| 73 | + ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp); | ||
| 74 | + | ||
| 75 | + ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023)); | ||
| 76 | + | ||
| 77 | + ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023)); | ||
| 78 | + | ||
| 79 | + Link link = new DefaultLink(pid, src, dst, Link.Type.DIRECT, EMPTY); | ||
| 80 | + links.add(link); | ||
| 81 | + | ||
| 82 | + path = new DefaultPath(pid, links, 10, EMPTY); | ||
| 83 | + | ||
| 84 | + tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS, | ||
| 85 | + new DefaultGroupId(0), TunnelId.valueOf(1), TunnelName.tunnelName("T123"), | ||
| 86 | + path, EMPTY); | ||
| 87 | + | ||
| 88 | + tunnelProvider.setupTunnel(tunnel, path); | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + @After | ||
| 92 | + public void tearDown() throws IOException { | ||
| 93 | + tunnelProvider.deactivate(); | ||
| 94 | + tunnelProvider.controller = null; | ||
| 95 | + tunnelProvider.pcepClientController = null; | ||
| 96 | + tunnelProvider.tunnelProviderRegistry = null; | ||
| 97 | + } | ||
| 98 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2014 Open Networking Laboratory | ||
| 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 | + */ | ||
| 16 | +package org.onosproject.provider.pcep.tunnel.impl; | ||
| 17 | + | ||
| 18 | +import static org.onosproject.net.DefaultAnnotations.EMPTY; | ||
| 19 | + | ||
| 20 | +import java.io.IOException; | ||
| 21 | +import java.util.ArrayList; | ||
| 22 | +import java.util.List; | ||
| 23 | + | ||
| 24 | +import org.junit.After; | ||
| 25 | +import org.junit.Test; | ||
| 26 | +import org.onlab.packet.IpAddress; | ||
| 27 | +import org.onosproject.core.DefaultGroupId; | ||
| 28 | +import org.onosproject.incubator.net.tunnel.DefaultTunnel; | ||
| 29 | +import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint; | ||
| 30 | +import org.onosproject.incubator.net.tunnel.Tunnel; | ||
| 31 | +import org.onosproject.incubator.net.tunnel.TunnelId; | ||
| 32 | +import org.onosproject.incubator.net.tunnel.TunnelName; | ||
| 33 | +import org.onosproject.net.ConnectPoint; | ||
| 34 | +import org.onosproject.net.DefaultLink; | ||
| 35 | +import org.onosproject.net.DefaultPath; | ||
| 36 | +import org.onosproject.net.IpElementId; | ||
| 37 | +import org.onosproject.net.Link; | ||
| 38 | +import org.onosproject.net.Path; | ||
| 39 | +import org.onosproject.net.PortNumber; | ||
| 40 | +import org.onosproject.net.provider.ProviderId; | ||
| 41 | + | ||
| 42 | +public class PcepTunnelProviderTest { | ||
| 43 | + | ||
| 44 | + static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep"; | ||
| 45 | + PcepTunnelProvider tunnelProvider = new PcepTunnelProvider(); | ||
| 46 | + private final TunnelProviderRegistryAdapter registry = new TunnelProviderRegistryAdapter(); | ||
| 47 | + private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter(); | ||
| 48 | + private final PcepControllerAdapter ctl = new PcepControllerAdapter(); | ||
| 49 | + | ||
| 50 | + @Test | ||
| 51 | + public void testCasePcepSetupTunnel() { | ||
| 52 | + | ||
| 53 | + tunnelProvider.tunnelProviderRegistry = registry; | ||
| 54 | + tunnelProvider.pcepClientController = controller; | ||
| 55 | + tunnelProvider.controller = ctl; | ||
| 56 | + tunnelProvider.activate(); | ||
| 57 | + | ||
| 58 | + Tunnel tunnel; | ||
| 59 | + Path path; | ||
| 60 | + ProviderId pid = new ProviderId("pcep", PROVIDER_ID); | ||
| 61 | + List<Link> links = new ArrayList<Link>(); | ||
| 62 | + IpAddress srcIp = IpAddress.valueOf(0xC010101); | ||
| 63 | + IpElementId srcElementId = IpElementId.ipElement(srcIp); | ||
| 64 | + | ||
| 65 | + IpAddress dstIp = IpAddress.valueOf(0xC010102); | ||
| 66 | + IpElementId dstElementId = IpElementId.ipElement(dstIp); | ||
| 67 | + | ||
| 68 | + IpTunnelEndPoint ipTunnelEndPointSrc; | ||
| 69 | + ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp); | ||
| 70 | + | ||
| 71 | + IpTunnelEndPoint ipTunnelEndPointDst; | ||
| 72 | + ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp); | ||
| 73 | + | ||
| 74 | + ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023)); | ||
| 75 | + | ||
| 76 | + ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023)); | ||
| 77 | + | ||
| 78 | + Link link = new DefaultLink(pid, src, dst, Link.Type.DIRECT, EMPTY); | ||
| 79 | + links.add(link); | ||
| 80 | + | ||
| 81 | + path = new DefaultPath(pid, links, 10, EMPTY); | ||
| 82 | + | ||
| 83 | + tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS, | ||
| 84 | + new DefaultGroupId(0), TunnelId.valueOf(1), TunnelName.tunnelName("T123"), | ||
| 85 | + path, EMPTY); | ||
| 86 | + | ||
| 87 | + tunnelProvider.setupTunnel(tunnel, path); | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + @After | ||
| 91 | + public void tearDown() throws IOException { | ||
| 92 | + tunnelProvider.deactivate(); | ||
| 93 | + tunnelProvider.controller = null; | ||
| 94 | + tunnelProvider.pcepClientController = null; | ||
| 95 | + tunnelProvider.tunnelProviderRegistry = null; | ||
| 96 | + } | ||
| 97 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2014 Open Networking Laboratory | ||
| 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 | + */ | ||
| 16 | +package org.onosproject.provider.pcep.tunnel.impl; | ||
| 17 | + | ||
| 18 | +import static org.onosproject.net.DefaultAnnotations.EMPTY; | ||
| 19 | + | ||
| 20 | +import java.io.IOException; | ||
| 21 | +import java.util.ArrayList; | ||
| 22 | +import java.util.List; | ||
| 23 | + | ||
| 24 | +import org.junit.After; | ||
| 25 | +import org.junit.Test; | ||
| 26 | +import org.onlab.packet.IpAddress; | ||
| 27 | +import org.onosproject.core.DefaultGroupId; | ||
| 28 | +import org.onosproject.incubator.net.tunnel.DefaultTunnel; | ||
| 29 | +import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint; | ||
| 30 | +import org.onosproject.incubator.net.tunnel.Tunnel; | ||
| 31 | +import org.onosproject.incubator.net.tunnel.TunnelId; | ||
| 32 | +import org.onosproject.incubator.net.tunnel.TunnelName; | ||
| 33 | +import org.onosproject.net.ConnectPoint; | ||
| 34 | +import org.onosproject.net.DefaultLink; | ||
| 35 | +import org.onosproject.net.DefaultPath; | ||
| 36 | +import org.onosproject.net.IpElementId; | ||
| 37 | +import org.onosproject.net.Link; | ||
| 38 | +import org.onosproject.net.Path; | ||
| 39 | +import org.onosproject.net.PortNumber; | ||
| 40 | +import org.onosproject.net.provider.ProviderId; | ||
| 41 | +import org.onosproject.pcepio.types.StatefulIPv4LspIdentidiersTlv; | ||
| 42 | + | ||
| 43 | + | ||
| 44 | +public class PcepUpdateTunnelProviderTest { | ||
| 45 | + | ||
| 46 | + static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep"; | ||
| 47 | + PcepTunnelProvider tunnelProvider = new PcepTunnelProvider(); | ||
| 48 | + private final TunnelProviderRegistryAdapter registry = new TunnelProviderRegistryAdapter(); | ||
| 49 | + private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter(); | ||
| 50 | + private final PcepControllerAdapter ctl = new PcepControllerAdapter(); | ||
| 51 | + private final PcepTunnelApiMapper pcepTunnelAPIMapper = new PcepTunnelApiMapper(); | ||
| 52 | + | ||
| 53 | + @Test | ||
| 54 | + public void testCasePcepUpdateTunnel() { | ||
| 55 | + tunnelProvider.tunnelProviderRegistry = registry; | ||
| 56 | + tunnelProvider.pcepClientController = controller; | ||
| 57 | + tunnelProvider.controller = ctl; | ||
| 58 | + tunnelProvider.pcepTunnelAPIMapper = pcepTunnelAPIMapper; | ||
| 59 | + tunnelProvider.activate(); | ||
| 60 | + | ||
| 61 | + Tunnel tunnel; | ||
| 62 | + Path path; | ||
| 63 | + ProviderId pid = new ProviderId("pcep", PROVIDER_ID); | ||
| 64 | + List<Link> links = new ArrayList<Link>(); | ||
| 65 | + IpAddress srcIp = IpAddress.valueOf(0xD010101); | ||
| 66 | + IpElementId srcElementId = IpElementId.ipElement(srcIp); | ||
| 67 | + | ||
| 68 | + IpAddress dstIp = IpAddress.valueOf(0xD010102); | ||
| 69 | + IpElementId dstElementId = IpElementId.ipElement(dstIp); | ||
| 70 | + | ||
| 71 | + IpTunnelEndPoint ipTunnelEndPointSrc; | ||
| 72 | + ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp); | ||
| 73 | + | ||
| 74 | + IpTunnelEndPoint ipTunnelEndPointDst; | ||
| 75 | + ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp); | ||
| 76 | + | ||
| 77 | + ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023)); | ||
| 78 | + | ||
| 79 | + ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023)); | ||
| 80 | + | ||
| 81 | + Link link = new DefaultLink(pid, src, dst, Link.Type.DIRECT, EMPTY); | ||
| 82 | + links.add(link); | ||
| 83 | + | ||
| 84 | + path = new DefaultPath(pid, links, 20, EMPTY); | ||
| 85 | + | ||
| 86 | + tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS, | ||
| 87 | + new DefaultGroupId(0), TunnelId.valueOf(1), TunnelName.tunnelName("T123"), | ||
| 88 | + path, EMPTY); | ||
| 89 | + | ||
| 90 | + // for updating tunnel tunnel should exist in db | ||
| 91 | + PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.UPDATE); | ||
| 92 | + pcepTunnelData.setPlspId(1); | ||
| 93 | + StatefulIPv4LspIdentidiersTlv tlv = new StatefulIPv4LspIdentidiersTlv(0, (short) 1, (short) 2, 3, 4); | ||
| 94 | + pcepTunnelData.setStatefulIpv4IndentifierTlv(tlv); | ||
| 95 | + tunnelProvider.pcepTunnelAPIMapper.addToTunnelIdMap(pcepTunnelData); | ||
| 96 | + | ||
| 97 | + tunnelProvider.pcepTunnelAPIMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData); | ||
| 98 | + | ||
| 99 | + tunnelProvider.updateTunnel(tunnel, path); | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + @After | ||
| 103 | + public void tearDown() throws IOException { | ||
| 104 | + tunnelProvider.deactivate(); | ||
| 105 | + tunnelProvider.controller = null; | ||
| 106 | + tunnelProvider.pcepClientController = null; | ||
| 107 | + tunnelProvider.tunnelProviderRegistry = null; | ||
| 108 | + } | ||
| 109 | +} |
| 1 | +package org.onosproject.provider.pcep.tunnel.impl; | ||
| 2 | + | ||
| 3 | +import java.util.Set; | ||
| 4 | + | ||
| 5 | +import org.onosproject.incubator.net.tunnel.Tunnel; | ||
| 6 | +import org.onosproject.incubator.net.tunnel.TunnelDescription; | ||
| 7 | +import org.onosproject.incubator.net.tunnel.TunnelId; | ||
| 8 | +import org.onosproject.incubator.net.tunnel.TunnelProvider; | ||
| 9 | +import org.onosproject.incubator.net.tunnel.TunnelProviderRegistry; | ||
| 10 | +import org.onosproject.incubator.net.tunnel.TunnelProviderService; | ||
| 11 | +import org.onosproject.net.provider.ProviderId; | ||
| 12 | + | ||
| 13 | +public class TunnelProviderRegistryAdapter implements TunnelProviderRegistry { | ||
| 14 | + TunnelProvider provider; | ||
| 15 | + | ||
| 16 | + @Override | ||
| 17 | + public TunnelProviderService register(TunnelProvider provider) { | ||
| 18 | + this.provider = provider; | ||
| 19 | + return new TestProviderService(); | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | + @Override | ||
| 23 | + public void unregister(TunnelProvider provider) { | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + @Override | ||
| 27 | + public Set<ProviderId> getProviders() { | ||
| 28 | + return null; | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + private class TestProviderService implements TunnelProviderService { | ||
| 32 | + | ||
| 33 | + @Override | ||
| 34 | + public TunnelProvider provider() { | ||
| 35 | + return null; | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + @Override | ||
| 39 | + public TunnelId tunnelAdded(TunnelDescription tunnel) { | ||
| 40 | + return null; | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + @Override | ||
| 44 | + public void tunnelRemoved(TunnelDescription tunnel) { | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + @Override | ||
| 48 | + public void tunnelUpdated(TunnelDescription tunnel) { | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + @Override | ||
| 52 | + public Tunnel tunnelQueryById(TunnelId tunnelId) { | ||
| 53 | + return null; | ||
| 54 | + } | ||
| 55 | + } | ||
| 56 | +} |
-
Please register or login to post a comment