Priyanka B
Committed by Gerrit Code Review

[ONOS-4167] Identify the impacted tunnels based on network events, notify to PCE…

… app and trigger MBB flow.

Change-Id: I1766f4afbc0ee2f4c05c75cf788c91f9df8aaa9a
Showing 19 changed files with 877 additions and 90 deletions
...@@ -19,7 +19,6 @@ import static org.hamcrest.MatcherAssert.assertThat; ...@@ -19,7 +19,6 @@ import static org.hamcrest.MatcherAssert.assertThat;
19 import static org.hamcrest.Matchers.is; 19 import static org.hamcrest.Matchers.is;
20 import static org.hamcrest.Matchers.notNullValue; 20 import static org.hamcrest.Matchers.notNullValue;
21 import static org.hamcrest.Matchers.nullValue; 21 import static org.hamcrest.Matchers.nullValue;
22 -
23 import static org.onosproject.net.Link.Type.DIRECT; 22 import static org.onosproject.net.Link.Type.DIRECT;
24 23
25 import java.util.Iterator; 24 import java.util.Iterator;
...@@ -29,7 +28,6 @@ import java.util.LinkedList; ...@@ -29,7 +28,6 @@ import java.util.LinkedList;
29 import org.junit.After; 28 import org.junit.After;
30 import org.junit.Before; 29 import org.junit.Before;
31 import org.junit.Test; 30 import org.junit.Test;
32 -
33 import org.onlab.packet.IpAddress; 31 import org.onlab.packet.IpAddress;
34 import org.onosproject.core.ApplicationId; 32 import org.onosproject.core.ApplicationId;
35 import org.onosproject.core.CoreService; 33 import org.onosproject.core.CoreService;
...@@ -165,6 +163,7 @@ public class BasicPceccHandlerTest { ...@@ -165,6 +163,7 @@ public class BasicPceccHandlerTest {
165 163
166 @After 164 @After
167 public void tearDown() throws Exception { 165 public void tearDown() throws Exception {
166 + PceManagerTest.flowsDownloaded = 0;
168 } 167 }
169 168
170 /** 169 /**
......
...@@ -129,7 +129,7 @@ public class PceManagerTest { ...@@ -129,7 +129,7 @@ public class PceManagerTest {
129 private Device deviceD1, deviceD2, deviceD3, deviceD4; 129 private Device deviceD1, deviceD2, deviceD3, deviceD4;
130 private Device pcepDeviceD1, pcepDeviceD2, pcepDeviceD3, pcepDeviceD4; 130 private Device pcepDeviceD1, pcepDeviceD2, pcepDeviceD3, pcepDeviceD4;
131 private Link link1, link2, link3, link4; 131 private Link link1, link2, link3, link4;
132 - private static int flowsDownloaded; 132 + protected static int flowsDownloaded;
133 private TunnelListener tunnelListener; 133 private TunnelListener tunnelListener;
134 134
135 @Before 135 @Before
......
...@@ -158,6 +158,7 @@ public class PceccSrTeBeHandlerTest { ...@@ -158,6 +158,7 @@ public class PceccSrTeBeHandlerTest {
158 158
159 @After 159 @After
160 public void tearDown() throws Exception { 160 public void tearDown() throws Exception {
161 + PceManagerTest.flowsDownloaded = 0;
161 } 162 }
162 163
163 /** 164 /**
......
1 +/*
2 + * Copyright 2016-present 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.pcep.controller;
17 +
18 +import java.util.Objects;
19 +
20 +import com.google.common.base.MoreObjects;
21 +
22 +/**
23 + * Representation of LSP info, it will be unique for each LSP.
24 + */
25 +public class LspKey {
26 + private int plspId;
27 + private short localLspId;
28 +
29 + /**
30 + * Creates new instance of LspInfo.
31 + *
32 + * @param plspId LSP id assigned per tunnel per session
33 + * @param localLspId LSP id assigned per tunnel
34 + */
35 + public LspKey(int plspId, short localLspId) {
36 + this.plspId = plspId;
37 + this.localLspId = localLspId;
38 + }
39 +
40 + /**
41 + * Obtains PLSP id.
42 + *
43 + * @return LSP id assigned per tunnel per session
44 + */
45 + public int plspId() {
46 + return plspId;
47 + }
48 +
49 + /**
50 + * Obtains local LSP id.
51 + *
52 + * @return LSP id assigned per tunnel
53 + */
54 + public short localLspId() {
55 + return localLspId;
56 + }
57 +
58 + @Override
59 + public int hashCode() {
60 + return Objects.hash(plspId, localLspId);
61 + }
62 +
63 + @Override
64 + public boolean equals(Object obj) {
65 + if (this == obj) {
66 + return true;
67 + }
68 +
69 + if (obj instanceof LspKey) {
70 + LspKey other = (LspKey) obj;
71 + return Objects.equals(plspId, other.plspId)
72 + && Objects.equals(localLspId, other.localLspId);
73 + }
74 +
75 + return false;
76 + }
77 +
78 + @Override
79 + public String toString() {
80 + return MoreObjects.toStringHelper(getClass())
81 + .add("plspId", plspId)
82 + .add("localLspId", localLspId)
83 + .toString();
84 + }
85 +}
...\ No newline at end of file ...\ No newline at end of file
...@@ -149,4 +149,20 @@ public interface PcepClient { ...@@ -149,4 +149,20 @@ public interface PcepClient {
149 * @param pccId PCEP client ID 149 * @param pccId PCEP client ID
150 */ 150 */
151 void deleteNode(PccId pccId); 151 void deleteNode(PccId pccId);
152 +
153 + /**
154 + * Sets D flag for the given LSP and its LSP info.
155 + *
156 + * @param lspKey contains LSP info
157 + * @param dFlag delegation flag in LSP object
158 + */
159 + void setLspAndDelegationInfo(LspKey lspKey, boolean dFlag);
160 +
161 + /**
162 + * Returns delegation flag for the given LSP info.
163 + *
164 + * @param lspKey contains LSP info
165 + * @return delegation flag
166 + */
167 + Boolean delegationInfo(LspKey lspKey);
152 } 168 }
......
...@@ -20,11 +20,13 @@ import java.net.InetSocketAddress; ...@@ -20,11 +20,13 @@ import java.net.InetSocketAddress;
20 import java.net.SocketAddress; 20 import java.net.SocketAddress;
21 import java.util.Collections; 21 import java.util.Collections;
22 import java.util.List; 22 import java.util.List;
23 +import java.util.Map;
23 import java.util.concurrent.RejectedExecutionException; 24 import java.util.concurrent.RejectedExecutionException;
24 25
25 import org.jboss.netty.channel.Channel; 26 import org.jboss.netty.channel.Channel;
26 import org.onlab.packet.IpAddress; 27 import org.onlab.packet.IpAddress;
27 import org.onosproject.pcep.controller.ClientCapability; 28 import org.onosproject.pcep.controller.ClientCapability;
29 +import org.onosproject.pcep.controller.LspKey;
28 import org.onosproject.pcep.controller.PccId; 30 import org.onosproject.pcep.controller.PccId;
29 import org.onosproject.pcep.controller.PcepClient; 31 import org.onosproject.pcep.controller.PcepClient;
30 import org.onosproject.pcep.controller.PcepPacketStats; 32 import org.onosproject.pcep.controller.PcepPacketStats;
...@@ -67,6 +69,7 @@ public class PcepClientImpl implements PcepClientDriver { ...@@ -67,6 +69,7 @@ public class PcepClientImpl implements PcepClientDriver {
67 private byte deadTime; 69 private byte deadTime;
68 private byte sessionId; 70 private byte sessionId;
69 private PcepPacketStatsImpl pktStats; 71 private PcepPacketStatsImpl pktStats;
72 + private Map<LspKey, Boolean> lspDelegationInfo;
70 73
71 @Override 74 @Override
72 public void init(PccId pccId, PcepVersion pcepVersion, PcepPacketStats pktStats) { 75 public void init(PccId pccId, PcepVersion pcepVersion, PcepPacketStats pktStats) {
...@@ -241,6 +244,16 @@ public class PcepClientImpl implements PcepClientDriver { ...@@ -241,6 +244,16 @@ public class PcepClientImpl implements PcepClientDriver {
241 } 244 }
242 245
243 @Override 246 @Override
247 + public void setLspAndDelegationInfo(LspKey lspKey, boolean dFlag) {
248 + lspDelegationInfo.put(lspKey, dFlag);
249 + }
250 +
251 + @Override
252 + public Boolean delegationInfo(LspKey lspKey) {
253 + return lspDelegationInfo.get(lspKey);
254 + }
255 +
256 + @Override
244 public boolean isOptical() { 257 public boolean isOptical() {
245 return false; 258 return false;
246 } 259 }
......
...@@ -29,14 +29,14 @@ public interface PcepBandwidthObject { ...@@ -29,14 +29,14 @@ public interface PcepBandwidthObject {
29 * 29 *
30 * @return bandwidth value 30 * @return bandwidth value
31 */ 31 */
32 - int getBandwidth(); 32 + float getBandwidth();
33 33
34 /** 34 /**
35 * Sets bandwidth with specified value. 35 * Sets bandwidth with specified value.
36 * 36 *
37 * @param iBandwidth Bandwidth's value 37 * @param iBandwidth Bandwidth's value
38 */ 38 */
39 - void setBandwidth(int iBandwidth); 39 + void setBandwidth(float iBandwidth);
40 40
41 /** 41 /**
42 * Writes the BandwidthObject into channel buffer. 42 * Writes the BandwidthObject into channel buffer.
......
...@@ -51,6 +51,7 @@ public class PcepBandwidthObjectVer1 implements PcepBandwidthObject { ...@@ -51,6 +51,7 @@ public class PcepBandwidthObjectVer1 implements PcepBandwidthObject {
51 public static final byte BANDWIDTH_OBJ_TYPE = 1; 51 public static final byte BANDWIDTH_OBJ_TYPE = 1;
52 public static final byte BANDWIDTH_OBJ_CLASS = 5; 52 public static final byte BANDWIDTH_OBJ_CLASS = 5;
53 public static final byte BANDWIDTH_OBJECT_VERSION = 1; 53 public static final byte BANDWIDTH_OBJECT_VERSION = 1;
54 + public static final int NO_OF_BITS = 8;
54 public static final short BANDWIDTH_OBJ_MINIMUM_LENGTH = 8; 55 public static final short BANDWIDTH_OBJ_MINIMUM_LENGTH = 8;
55 56
56 static final PcepObjectHeader DEFAULT_BANDWIDTH_OBJECT_HEADER = new PcepObjectHeader(BANDWIDTH_OBJ_CLASS, 57 static final PcepObjectHeader DEFAULT_BANDWIDTH_OBJECT_HEADER = new PcepObjectHeader(BANDWIDTH_OBJ_CLASS,
...@@ -58,7 +59,7 @@ public class PcepBandwidthObjectVer1 implements PcepBandwidthObject { ...@@ -58,7 +59,7 @@ public class PcepBandwidthObjectVer1 implements PcepBandwidthObject {
58 BANDWIDTH_OBJ_MINIMUM_LENGTH); 59 BANDWIDTH_OBJ_MINIMUM_LENGTH);
59 60
60 private PcepObjectHeader bandwidthObjHeader; 61 private PcepObjectHeader bandwidthObjHeader;
61 - private int iBandwidth; 62 + private float iBandwidth;
62 63
63 /** 64 /**
64 * Constructor to bandwidth object header and bandwidth. 65 * Constructor to bandwidth object header and bandwidth.
...@@ -66,7 +67,7 @@ public class PcepBandwidthObjectVer1 implements PcepBandwidthObject { ...@@ -66,7 +67,7 @@ public class PcepBandwidthObjectVer1 implements PcepBandwidthObject {
66 * @param bandwidthObjHeader bandwidth object header 67 * @param bandwidthObjHeader bandwidth object header
67 * @param iBandwidth bandwidth value 68 * @param iBandwidth bandwidth value
68 */ 69 */
69 - public PcepBandwidthObjectVer1(PcepObjectHeader bandwidthObjHeader, int iBandwidth) { 70 + public PcepBandwidthObjectVer1(PcepObjectHeader bandwidthObjHeader, float iBandwidth) {
70 this.bandwidthObjHeader = bandwidthObjHeader; 71 this.bandwidthObjHeader = bandwidthObjHeader;
71 this.iBandwidth = iBandwidth; 72 this.iBandwidth = iBandwidth;
72 } 73 }
...@@ -76,7 +77,7 @@ public class PcepBandwidthObjectVer1 implements PcepBandwidthObject { ...@@ -76,7 +77,7 @@ public class PcepBandwidthObjectVer1 implements PcepBandwidthObject {
76 * 77 *
77 * @param iBandwidth bandwidth value 78 * @param iBandwidth bandwidth value
78 */ 79 */
79 - public PcepBandwidthObjectVer1(int iBandwidth) { 80 + public PcepBandwidthObjectVer1(float iBandwidth) {
80 this.bandwidthObjHeader = DEFAULT_BANDWIDTH_OBJECT_HEADER; 81 this.bandwidthObjHeader = DEFAULT_BANDWIDTH_OBJECT_HEADER;
81 this.iBandwidth = iBandwidth; 82 this.iBandwidth = iBandwidth;
82 } 83 }
...@@ -100,12 +101,12 @@ public class PcepBandwidthObjectVer1 implements PcepBandwidthObject { ...@@ -100,12 +101,12 @@ public class PcepBandwidthObjectVer1 implements PcepBandwidthObject {
100 } 101 }
101 102
102 @Override 103 @Override
103 - public int getBandwidth() { 104 + public float getBandwidth() {
104 return this.iBandwidth; 105 return this.iBandwidth;
105 } 106 }
106 107
107 @Override 108 @Override
108 - public void setBandwidth(int iBandwidth) { 109 + public void setBandwidth(float iBandwidth) {
109 this.iBandwidth = iBandwidth; 110 this.iBandwidth = iBandwidth;
110 } 111 }
111 112
...@@ -119,12 +120,25 @@ public class PcepBandwidthObjectVer1 implements PcepBandwidthObject { ...@@ -119,12 +120,25 @@ public class PcepBandwidthObjectVer1 implements PcepBandwidthObject {
119 public static PcepBandwidthObject read(ChannelBuffer cb) throws PcepParseException { 120 public static PcepBandwidthObject read(ChannelBuffer cb) throws PcepParseException {
120 121
121 PcepObjectHeader bandwidthObjHeader; 122 PcepObjectHeader bandwidthObjHeader;
122 - int iBandwidth; 123 + float bandwidth;
123 124
124 bandwidthObjHeader = PcepObjectHeader.read(cb); 125 bandwidthObjHeader = PcepObjectHeader.read(cb);
125 - iBandwidth = cb.readInt(); 126 + bandwidth = ieeeToFloatRead(cb.readInt()) * NO_OF_BITS;
126 127
127 - return new PcepBandwidthObjectVer1(bandwidthObjHeader, iBandwidth); 128 + return new PcepBandwidthObjectVer1(bandwidthObjHeader, bandwidth);
129 + }
130 +
131 + /**
132 + * Parse the IEEE floating point notation and returns it in normal float.
133 + *
134 + * @param iVal IEEE floating point number
135 + * @return normal float
136 + */
137 + public static float ieeeToFloatRead(int iVal) {
138 + iVal = (((iVal & 0xFF) << 24) | ((iVal & 0xFF00) << 8)
139 + | ((iVal & 0xFF0000) >> 8) | ((iVal >> 24) & 0xFF));
140 +
141 + return Float.intBitsToFloat(iVal);
128 } 142 }
129 143
130 @Override 144 @Override
...@@ -138,7 +152,7 @@ public class PcepBandwidthObjectVer1 implements PcepBandwidthObject { ...@@ -138,7 +152,7 @@ public class PcepBandwidthObjectVer1 implements PcepBandwidthObject {
138 throw new PcepParseException("Failed to write bandwidth object header. Index " + objLenIndex); 152 throw new PcepParseException("Failed to write bandwidth object header. Index " + objLenIndex);
139 } 153 }
140 154
141 - cb.writeInt(iBandwidth); 155 + cb.writeInt(Float.floatToIntBits(iBandwidth));
142 short hLength = (short) (cb.writerIndex() - objStartIndex); 156 short hLength = (short) (cb.writerIndex() - objStartIndex);
143 cb.setShort(objLenIndex, hLength); 157 cb.setShort(objLenIndex, hLength);
144 //will be helpful during print(). 158 //will be helpful during print().
......
...@@ -16,8 +16,10 @@ ...@@ -16,8 +16,10 @@
16 16
17 package org.onosproject.pcepio.protocol.ver1; 17 package org.onosproject.pcepio.protocol.ver1;
18 18
19 +import java.util.Iterator;
19 import java.util.LinkedList; 20 import java.util.LinkedList;
20 import java.util.ListIterator; 21 import java.util.ListIterator;
22 +import java.util.Objects;
21 23
22 import org.jboss.netty.buffer.ChannelBuffer; 24 import org.jboss.netty.buffer.ChannelBuffer;
23 import org.onosproject.pcepio.exceptions.PcepParseException; 25 import org.onosproject.pcepio.exceptions.PcepParseException;
...@@ -399,10 +401,47 @@ public class PcepEroObjectVer1 implements PcepEroObject { ...@@ -399,10 +401,47 @@ public class PcepEroObjectVer1 implements PcepEroObject {
399 } 401 }
400 402
401 @Override 403 @Override
404 + public int hashCode() {
405 + return Objects.hash(eroObjHeader, subObjectList);
406 + }
407 +
408 + @Override
402 public String toString() { 409 public String toString() {
403 return MoreObjects.toStringHelper(getClass()).omitNullValues() 410 return MoreObjects.toStringHelper(getClass()).omitNullValues()
404 .add("EroObjHeader", eroObjHeader) 411 .add("EroObjHeader", eroObjHeader)
405 .add("SubObjects", subObjectList) 412 .add("SubObjects", subObjectList)
406 .toString(); 413 .toString();
407 } 414 }
415 +
416 + @Override
417 + public boolean equals(Object obj) {
418 + if (this == obj) {
419 + return true;
420 + }
421 +
422 + if (obj instanceof PcepEroObjectVer1) {
423 + int countObjSubTlv = 0;
424 + int countOtherSubTlv = 0;
425 + boolean isCommonSubTlv = true;
426 + PcepEroObjectVer1 other = (PcepEroObjectVer1) obj;
427 + Iterator<PcepValueType> objListIterator = other.subObjectList.iterator();
428 + countOtherSubTlv = other.subObjectList.size();
429 + countObjSubTlv = subObjectList.size();
430 + if (countObjSubTlv != countOtherSubTlv) {
431 + return false;
432 + } else {
433 + while (objListIterator.hasNext() && isCommonSubTlv) {
434 + PcepValueType subTlv = objListIterator.next();
435 + if (subObjectList.contains(subTlv)) {
436 + isCommonSubTlv = Objects.equals(subObjectList.get(subObjectList.indexOf(subTlv)),
437 + other.subObjectList.get(other.subObjectList.indexOf(subTlv)));
438 + } else {
439 + isCommonSubTlv = false;
440 + }
441 + }
442 + return isCommonSubTlv && Objects.equals(eroObjHeader, other.eroObjHeader);
443 + }
444 + }
445 + return false;
446 + }
408 } 447 }
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
16 16
17 package org.onosproject.pcepio.types; 17 package org.onosproject.pcepio.types;
18 18
19 +import java.util.Objects;
20 +
19 import org.jboss.netty.buffer.ChannelBuffer; 21 import org.jboss.netty.buffer.ChannelBuffer;
20 import org.slf4j.Logger; 22 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory; 23 import org.slf4j.LoggerFactory;
...@@ -212,6 +214,27 @@ public class PcepObjectHeader { ...@@ -212,6 +214,27 @@ public class PcepObjectHeader {
212 } 214 }
213 215
214 @Override 216 @Override
217 + public int hashCode() {
218 + return Objects.hash(objClass, objType, bPFlag, bIFlag, objLen);
219 + }
220 +
221 + @Override
222 + public boolean equals(Object obj) {
223 + if (this == obj) {
224 + return true;
225 + }
226 + if (obj instanceof PcepObjectHeader) {
227 + PcepObjectHeader other = (PcepObjectHeader) obj;
228 + return Objects.equals(objClass, other.objClass)
229 + && Objects.equals(objType, other.objType)
230 + && Objects.equals(bPFlag, other.bPFlag)
231 + && Objects.equals(bIFlag, other.bIFlag)
232 + && Objects.equals(objLen, other.objLen);
233 + }
234 + return false;
235 + }
236 +
237 + @Override
215 public String toString() { 238 public String toString() {
216 return MoreObjects.toStringHelper(getClass()) 239 return MoreObjects.toStringHelper(getClass())
217 .add("ObjectClass", objClass) 240 .add("ObjectClass", objClass)
......
...@@ -17,12 +17,15 @@ package org.onosproject.provider.pcep.topology.impl; ...@@ -17,12 +17,15 @@ package org.onosproject.provider.pcep.topology.impl;
17 17
18 import static org.junit.Assert.assertNotNull; 18 import static org.junit.Assert.assertNotNull;
19 19
20 +import java.util.HashMap;
20 import java.util.List; 21 import java.util.List;
22 +import java.util.Map;
21 import java.util.concurrent.RejectedExecutionException; 23 import java.util.concurrent.RejectedExecutionException;
22 24
23 import org.jboss.netty.channel.Channel; 25 import org.jboss.netty.channel.Channel;
24 import org.onosproject.pcep.controller.ClientCapability; 26 import org.onosproject.pcep.controller.ClientCapability;
25 import org.onosproject.pcep.controller.PccId; 27 import org.onosproject.pcep.controller.PccId;
28 +import org.onosproject.pcep.controller.LspKey;
26 import org.onosproject.pcep.controller.PcepClient; 29 import org.onosproject.pcep.controller.PcepClient;
27 import org.onosproject.pcep.controller.PcepSyncStatus; 30 import org.onosproject.pcep.controller.PcepSyncStatus;
28 import org.onosproject.pcepio.protocol.PcepFactories; 31 import org.onosproject.pcepio.protocol.PcepFactories;
...@@ -45,6 +48,7 @@ public class PcepClientAdapter implements PcepClient { ...@@ -45,6 +48,7 @@ public class PcepClientAdapter implements PcepClient {
45 private PcepVersion pcepVersion; 48 private PcepVersion pcepVersion;
46 private PcepSyncStatus lspDbSyncStatus; 49 private PcepSyncStatus lspDbSyncStatus;
47 private PcepSyncStatus labelDbSyncStatus; 50 private PcepSyncStatus labelDbSyncStatus;
51 + private Map<LspKey, Boolean> lspDelegationInfo = new HashMap<>();
48 52
49 /** 53 /**
50 * Initialize instance with specified parameters. 54 * Initialize instance with specified parameters.
...@@ -147,4 +151,14 @@ public class PcepClientAdapter implements PcepClient { ...@@ -147,4 +151,14 @@ public class PcepClientAdapter implements PcepClient {
147 @Override 151 @Override
148 public void deleteNode(PccId pccId) { 152 public void deleteNode(PccId pccId) {
149 } 153 }
154 +
155 + @Override
156 + public void setLspAndDelegationInfo(LspKey lspKey, boolean dFlag) {
157 + lspDelegationInfo.put(lspKey, dFlag);
158 + }
159 +
160 + @Override
161 + public Boolean delegationInfo(LspKey lspKey) {
162 + return lspDelegationInfo.get(lspKey);
163 + }
150 } 164 }
......
...@@ -36,6 +36,7 @@ import org.onosproject.incubator.net.tunnel.OpticalLogicId; ...@@ -36,6 +36,7 @@ import org.onosproject.incubator.net.tunnel.OpticalLogicId;
36 import org.onosproject.incubator.net.tunnel.OpticalTunnelEndPoint; 36 import org.onosproject.incubator.net.tunnel.OpticalTunnelEndPoint;
37 import org.onosproject.incubator.net.tunnel.Tunnel; 37 import org.onosproject.incubator.net.tunnel.Tunnel;
38 import org.onosproject.incubator.net.tunnel.Tunnel.State; 38 import org.onosproject.incubator.net.tunnel.Tunnel.State;
39 +import org.onosproject.incubator.net.tunnel.TunnelAdminService;
39 import org.onosproject.incubator.net.tunnel.TunnelDescription; 40 import org.onosproject.incubator.net.tunnel.TunnelDescription;
40 import org.onosproject.incubator.net.tunnel.TunnelEndPoint; 41 import org.onosproject.incubator.net.tunnel.TunnelEndPoint;
41 import org.onosproject.incubator.net.tunnel.TunnelId; 42 import org.onosproject.incubator.net.tunnel.TunnelId;
...@@ -45,11 +46,14 @@ import org.onosproject.incubator.net.tunnel.TunnelProviderRegistry; ...@@ -45,11 +46,14 @@ import org.onosproject.incubator.net.tunnel.TunnelProviderRegistry;
45 import org.onosproject.incubator.net.tunnel.TunnelProviderService; 46 import org.onosproject.incubator.net.tunnel.TunnelProviderService;
46 import org.onosproject.incubator.net.tunnel.TunnelService; 47 import org.onosproject.incubator.net.tunnel.TunnelService;
47 import org.onosproject.incubator.net.tunnel.TunnelStatistics; 48 import org.onosproject.incubator.net.tunnel.TunnelStatistics;
49 +import org.onosproject.mastership.MastershipService;
50 +import org.onosproject.net.AnnotationKeys;
48 import org.onosproject.net.ConnectPoint; 51 import org.onosproject.net.ConnectPoint;
49 import org.onosproject.net.DefaultAnnotations; 52 import org.onosproject.net.DefaultAnnotations;
50 import org.onosproject.net.DefaultAnnotations.Builder; 53 import org.onosproject.net.DefaultAnnotations.Builder;
51 import org.onosproject.net.DefaultLink; 54 import org.onosproject.net.DefaultLink;
52 import org.onosproject.net.DefaultPath; 55 import org.onosproject.net.DefaultPath;
56 +import org.onosproject.net.Device;
53 import org.onosproject.net.DeviceId; 57 import org.onosproject.net.DeviceId;
54 import org.onosproject.net.ElementId; 58 import org.onosproject.net.ElementId;
55 import org.onosproject.net.IpElementId; 59 import org.onosproject.net.IpElementId;
...@@ -57,6 +61,7 @@ import org.onosproject.net.Link; ...@@ -57,6 +61,7 @@ import org.onosproject.net.Link;
57 import org.onosproject.net.Path; 61 import org.onosproject.net.Path;
58 import org.onosproject.net.PortNumber; 62 import org.onosproject.net.PortNumber;
59 import org.onosproject.net.SparseAnnotations; 63 import org.onosproject.net.SparseAnnotations;
64 +import org.onosproject.net.device.DeviceService;
60 import org.onosproject.net.provider.AbstractProvider; 65 import org.onosproject.net.provider.AbstractProvider;
61 import org.onosproject.net.provider.ProviderId; 66 import org.onosproject.net.provider.ProviderId;
62 import org.onosproject.pcep.api.PcepController; 67 import org.onosproject.pcep.api.PcepController;
...@@ -68,6 +73,7 @@ import org.onosproject.pcep.api.PcepTunnel.PathState; ...@@ -68,6 +73,7 @@ import org.onosproject.pcep.api.PcepTunnel.PathState;
68 import org.onosproject.pcep.api.PcepTunnel.PathType; 73 import org.onosproject.pcep.api.PcepTunnel.PathType;
69 import org.onosproject.pcep.api.PcepTunnelListener; 74 import org.onosproject.pcep.api.PcepTunnelListener;
70 import org.onosproject.pcep.api.PcepTunnelStatistics; 75 import org.onosproject.pcep.api.PcepTunnelStatistics;
76 +import org.onosproject.pcep.controller.LspKey;
71 import org.onosproject.pcep.controller.PccId; 77 import org.onosproject.pcep.controller.PccId;
72 import org.onosproject.pcep.controller.PcepClient; 78 import org.onosproject.pcep.controller.PcepClient;
73 import org.onosproject.pcep.controller.PcepClientController; 79 import org.onosproject.pcep.controller.PcepClientController;
...@@ -109,6 +115,9 @@ import java.util.List; ...@@ -109,6 +115,9 @@ import java.util.List;
109 import java.util.ListIterator; 115 import java.util.ListIterator;
110 import java.util.Map; 116 import java.util.Map;
111 import java.util.Optional; 117 import java.util.Optional;
118 +import java.util.concurrent.Executors;
119 +import java.util.concurrent.ScheduledExecutorService;
120 +import java.util.concurrent.TimeUnit;
112 121
113 import static com.google.common.base.Preconditions.checkNotNull; 122 import static com.google.common.base.Preconditions.checkNotNull;
114 import static com.google.common.base.Strings.isNullOrEmpty; 123 import static com.google.common.base.Strings.isNullOrEmpty;
...@@ -126,6 +135,7 @@ import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.LSP_S ...@@ -126,6 +135,7 @@ import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.LSP_S
126 import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.PCC_TUNNEL_ID; 135 import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.PCC_TUNNEL_ID;
127 import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.PLSP_ID; 136 import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.PLSP_ID;
128 import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.PCE_INIT; 137 import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.PCE_INIT;
138 +import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.DELEGATE;
129 import static org.onosproject.provider.pcep.tunnel.impl.RequestType.CREATE; 139 import static org.onosproject.provider.pcep.tunnel.impl.RequestType.CREATE;
130 import static org.onosproject.provider.pcep.tunnel.impl.RequestType.DELETE; 140 import static org.onosproject.provider.pcep.tunnel.impl.RequestType.DELETE;
131 import static org.onosproject.provider.pcep.tunnel.impl.RequestType.LSP_STATE_RPT; 141 import static org.onosproject.provider.pcep.tunnel.impl.RequestType.LSP_STATE_RPT;
...@@ -148,6 +158,11 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -148,6 +158,11 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
148 private static final long MIN_BANDWIDTH = 64; 158 private static final long MIN_BANDWIDTH = 64;
149 private static final String BANDWIDTH_UINT = "kbps"; 159 private static final String BANDWIDTH_UINT = "kbps";
150 static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep"; 160 static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep";
161 + public static final long IDENTIFIER_SET = 0x100000000L;
162 + public static final long SET = 0xFFFFFFFFL;
163 + private static final int DELAY = 2;
164 + private static final int WAIT_TIME = 5;
165 + public static final String LSRID = "lsrId";
151 166
152 static final int POLL_INTERVAL = 10; 167 static final int POLL_INTERVAL = 10;
153 @Property(name = "tunnelStatsPollFrequency", intValue = POLL_INTERVAL, 168 @Property(name = "tunnelStatsPollFrequency", intValue = POLL_INTERVAL,
...@@ -171,6 +186,15 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -171,6 +186,15 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
171 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 186 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
172 protected ComponentConfigService cfgService; 187 protected ComponentConfigService cfgService;
173 188
189 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
190 + protected TunnelAdminService tunnelAdminService;
191 +
192 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
193 + protected MastershipService mastershipService;
194 +
195 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
196 + protected DeviceService deviceService;
197 +
174 TunnelProviderService service; 198 TunnelProviderService service;
175 199
176 HashMap<String, TunnelId> tunnelMap = new HashMap<String, TunnelId>(); 200 HashMap<String, TunnelId> tunnelMap = new HashMap<String, TunnelId>();
...@@ -263,7 +287,8 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -263,7 +287,8 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
263 } 287 }
264 288
265 //If stateful and PC Initiation capability is not supported by client not sending Initiate msg 289 //If stateful and PC Initiation capability is not supported by client not sending Initiate msg
266 - if (pc.capability().pcInstantiationCapability()) { 290 + //Only master will initiate setup tunnel
291 + if (pc.capability().pcInstantiationCapability() && mastershipService.isLocalMaster(getDevice(pc.getPccId()))) {
267 pcepSetupTunnel(tunnel, path, pc); 292 pcepSetupTunnel(tunnel, path, pc);
268 } 293 }
269 } 294 }
...@@ -300,7 +325,10 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -300,7 +325,10 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
300 return; 325 return;
301 } 326 }
302 327
303 - if (pc.capability().pcInstantiationCapability()) { 328 + //If stateful and PC Initiation capability is not supported by client not sending Initiate msg
329 + //Only master will initiate setup tunnel
330 + if (pc.capability().pcInstantiationCapability()
331 + && mastershipService.isLocalMaster(getDevice(pc.getPccId()))) {
304 pcepSetupTunnel(tunnel, path, pc); 332 pcepSetupTunnel(tunnel, path, pc);
305 } 333 }
306 } 334 }
...@@ -327,7 +355,9 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -327,7 +355,9 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
327 return; 355 return;
328 } 356 }
329 357
330 - if (pc.capability().pcInstantiationCapability()) { 358 + //Only master will release tunnel
359 + if (pc.capability().pcInstantiationCapability()
360 + && mastershipService.isLocalMaster(getDevice(pc.getPccId()))) {
331 pcepReleaseTunnel(tunnel, pc); 361 pcepReleaseTunnel(tunnel, pc);
332 } 362 }
333 } 363 }
...@@ -358,7 +388,9 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -358,7 +388,9 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
358 return; 388 return;
359 } 389 }
360 390
361 - if (pc.capability().pcInstantiationCapability()) { 391 + //Only master will release tunnel
392 + if (pc.capability().pcInstantiationCapability()
393 + && mastershipService.isLocalMaster(getDevice(pc.getPccId()))) {
362 pcepReleaseTunnel(tunnel, pc); 394 pcepReleaseTunnel(tunnel, pc);
363 } 395 }
364 } 396 }
...@@ -384,7 +416,12 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -384,7 +416,12 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
384 return; 416 return;
385 } 417 }
386 418
387 - if (pc.capability().statefulPceCapability()) { 419 + // If delegation flag is set then only send update message[means delegated PCE can send update msg for that
420 + // LSP].If annotation is null D flag is not set else it is set.
421 + if (pc.capability().statefulPceCapability()
422 + && pc.delegationInfo(
423 + new LspKey(Integer.valueOf(tunnel.annotations().value(PLSP_ID)), Short.valueOf(tunnel
424 + .annotations().value(LOCAL_LSP_ID)))) != null) {
388 pcepUpdateTunnel(tunnel, path, pc); 425 pcepUpdateTunnel(tunnel, path, pc);
389 } 426 }
390 } 427 }
...@@ -416,7 +453,12 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -416,7 +453,12 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
416 return; 453 return;
417 } 454 }
418 455
419 - if (pc.capability().statefulPceCapability()) { 456 + // If delegation flag is set then only send update message[means delegated PCE can send update msg for that
457 + // LSP].If annotation is null D flag is not set else it is set.
458 + if (pc.capability().statefulPceCapability()
459 + && pc.delegationInfo(
460 + new LspKey(Integer.valueOf(tunnel.annotations().value(PLSP_ID)), Short.valueOf(tunnel
461 + .annotations().value(LOCAL_LSP_ID)))) != null) {
420 pcepUpdateTunnel(tunnel, path, pc); 462 pcepUpdateTunnel(tunnel, path, pc);
421 } 463 }
422 } 464 }
...@@ -480,6 +522,43 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -480,6 +522,43 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
480 return tunnelId; 522 return tunnelId;
481 } 523 }
482 524
525 + private void tunnelUpdated(Tunnel tunnel, Path path) {
526 + handleTunnelUpdate(tunnel, path);
527 + }
528 +
529 + //Handles tunnel updated using tunnel admin service[specially to update annotations].
530 + private void handleTunnelUpdate(Tunnel tunnel, Path path) {
531 +
532 + if (tunnel.type() == MPLS) {
533 + pcepTunnelApiMapper.removeFromCoreTunnelRequestQueue(tunnel.tunnelId());
534 +
535 + tunnelAdminService.updateTunnel(tunnel, path);
536 +
537 + return;
538 + }
539 +
540 + Tunnel tunnelOld = tunnelQueryById(tunnel.tunnelId());
541 + if (tunnelOld.type() != Tunnel.Type.VLAN) {
542 + error("Illegal tunnel type. Only support VLAN tunnel update.");
543 + return;
544 + }
545 +
546 + long bandwidth = Long
547 + .parseLong(tunnel.annotations().value("bandwidth"));
548 + if (bandwidth < MIN_BANDWIDTH || bandwidth > MAX_BANDWIDTH) {
549 + error("Update failed, invalid bandwidth.");
550 + return;
551 + }
552 + String pcepTunnelId = getPcepTunnelKey(tunnel.tunnelId());
553 +
554 + checkNotNull(pcepTunnelId, "Invalid tunnel id");
555 + if (!controller.updateTunnelBandwidth(pcepTunnelId, bandwidth)) {
556 + error("Update failed,maybe invalid bandwidth.");
557 + return;
558 + }
559 + tunnelAdminService.updateTunnel(tunnel, path);
560 + }
561 +
483 @Override 562 @Override
484 public void tunnelRemoved(TunnelDescription tunnel) { 563 public void tunnelRemoved(TunnelDescription tunnel) {
485 if (tunnel.type() == MPLS) { 564 if (tunnel.type() == MPLS) {
...@@ -1226,27 +1305,19 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -1226,27 +1305,19 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
1226 } 1305 }
1227 } 1306 }
1228 1307
1229 - private void handleRptWithoutSrpId(PcepStateReport stateRpt, PccId pccId, PcepSyncStatus syncStatus) { 1308 + private SparseAnnotations getAnnotations(PcepLspObject lspObj, StatefulIPv4LspIdentifiersTlv ipv4LspIdenTlv,
1230 - ProviderId providerId = new ProviderId("pcep", PROVIDER_ID); 1309 + float bandwidth, LspType lspType) {
1231 - PcepStateReport.PcepMsgPath msgPath = stateRpt.getMsgPath(); 1310 + SparseAnnotations annotations = DefaultAnnotations.builder()
1232 - checkNotNull(msgPath); 1311 + .set(BANDWIDTH, (new Float(bandwidth)).toString()).set(LSP_SIG_TYPE, lspType.name())
1233 - PcepEroObject eroObj = msgPath.getEroObject(); 1312 + .set(PCC_TUNNEL_ID, String.valueOf(ipv4LspIdenTlv.getTunnelId()))
1234 - if (eroObj == null) { 1313 + .set(PLSP_ID, String.valueOf(lspObj.getPlspId()))
1235 - log.error("ERO object is null in report message."); 1314 + .set(LOCAL_LSP_ID, String.valueOf(ipv4LspIdenTlv.getLspId()))
1236 - return; 1315 + .set(DELEGATE, String.valueOf(lspObj.getDFlag()))
1237 - } 1316 + .build();
1238 - Path path = buildPathFromEroObj(eroObj, providerId); 1317 + return annotations;
1239 -
1240 - int bandwidth = 0;
1241 - if (msgPath.getBandwidthObject() != null) {
1242 - bandwidth = msgPath.getBandwidthObject().getBandwidth();
1243 } 1318 }
1244 1319
1245 - /* 1320 + private LspType getLspType(PcepSrpObject srpObj) {
1246 - * To carry PST TLV, SRP object can be present with value 0 even when PCRpt is not in response to any action
1247 - * from PCE.
1248 - */
1249 - PcepSrpObject srpObj = stateRpt.getSrpObject();
1250 LspType lspType = WITH_SIGNALLING; 1321 LspType lspType = WITH_SIGNALLING;
1251 1322
1252 if (null != srpObj) { 1323 if (null != srpObj) {
...@@ -1266,6 +1337,31 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -1266,6 +1337,31 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
1266 } 1337 }
1267 } 1338 }
1268 } 1339 }
1340 + return lspType;
1341 + }
1342 +
1343 + private void handleRptWithoutSrpId(PcepStateReport stateRpt, PccId pccId, PcepSyncStatus syncStatus) {
1344 + ProviderId providerId = new ProviderId("pcep", PROVIDER_ID);
1345 + PcepStateReport.PcepMsgPath msgPath = stateRpt.getMsgPath();
1346 + checkNotNull(msgPath);
1347 + PcepEroObject eroObj = msgPath.getEroObject();
1348 + if (eroObj == null) {
1349 + log.error("ERO object is null in report message.");
1350 + return;
1351 + }
1352 + Path path = buildPathFromEroObj(eroObj, providerId);
1353 +
1354 + float bandwidth = 0;
1355 + if (msgPath.getBandwidthObject() != null) {
1356 + bandwidth = msgPath.getBandwidthObject().getBandwidth();
1357 + }
1358 +
1359 + /*
1360 + * To carry PST TLV, SRP object can be present with value 0 even when PCRpt is not in response to any action
1361 + * from PCE.
1362 + */
1363 + PcepSrpObject srpObj = stateRpt.getSrpObject();
1364 + LspType lspType = getLspType(srpObj);
1269 1365
1270 PcepLspObject lspObj = stateRpt.getLspObject(); 1366 PcepLspObject lspObj = stateRpt.getLspObject();
1271 ListIterator<PcepValueType> listTlvIterator = lspObj.getOptionalTlv().listIterator(); 1367 ListIterator<PcepValueType> listTlvIterator = lspObj.getOptionalTlv().listIterator();
...@@ -1287,7 +1383,6 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -1287,7 +1383,6 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
1287 break; 1383 break;
1288 } 1384 }
1289 } 1385 }
1290 -
1291 /* 1386 /*
1292 * Draft says: The LSP-IDENTIFIERS TLV MUST be included in the LSP object in PCRpt messages for 1387 * Draft says: The LSP-IDENTIFIERS TLV MUST be included in the LSP object in PCRpt messages for
1293 * RSVP-signaled LSPs. For ONOS PCECC implementation, it is mandatory. 1388 * RSVP-signaled LSPs. For ONOS PCECC implementation, it is mandatory.
...@@ -1303,6 +1398,14 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -1303,6 +1398,14 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
1303 .ipTunnelPoint(IpAddress.valueOf(ipv4LspIdenTlv.getIpv4EgressAddress())); 1398 .ipTunnelPoint(IpAddress.valueOf(ipv4LspIdenTlv.getIpv4EgressAddress()));
1304 Collection<Tunnel> tunnelQueryResult = tunnelService.queryTunnel(tunnelEndPointSrc, tunnelEndPointDst); 1399 Collection<Tunnel> tunnelQueryResult = tunnelService.queryTunnel(tunnelEndPointSrc, tunnelEndPointDst);
1305 1400
1401 + // Store delegation flag info and that LSP info because only delegated PCE sends update message
1402 + // Storing if D flag is set, if not dont store. while checking whether delegation if annotation for D flag
1403 + // not present then non-delegated , if present it is delegated.
1404 + if (lspObj.getDFlag()) {
1405 + pcepClientController.getClient(pccId).setLspAndDelegationInfo(
1406 + new LspKey(lspObj.getPlspId(), ipv4LspIdenTlv.getLspId()), lspObj.getDFlag());
1407 + }
1408 +
1306 Tunnel tunnel = null; 1409 Tunnel tunnel = null;
1307 // Asynchronous status change message from PCC for LSP reported earlier. 1410 // Asynchronous status change message from PCC for LSP reported earlier.
1308 for (Tunnel tunnelObj : tunnelQueryResult) { 1411 for (Tunnel tunnelObj : tunnelQueryResult) {
...@@ -1321,7 +1424,6 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -1321,7 +1424,6 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
1321 } 1424 }
1322 continue; 1425 continue;
1323 } 1426 }
1324 -
1325 if ((Integer.valueOf(tunnelObj.annotations().value(PLSP_ID)) == lspObj.getPlspId()) && (Integer 1427 if ((Integer.valueOf(tunnelObj.annotations().value(PLSP_ID)) == lspObj.getPlspId()) && (Integer
1326 .valueOf(tunnelObj.annotations().value(LOCAL_LSP_ID)) == ipv4LspIdenTlv.getLspId())) { 1428 .valueOf(tunnelObj.annotations().value(LOCAL_LSP_ID)) == ipv4LspIdenTlv.getLspId())) {
1327 tunnel = tunnelObj; 1429 tunnel = tunnelObj;
...@@ -1330,6 +1432,7 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -1330,6 +1432,7 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
1330 } 1432 }
1331 1433
1332 DefaultTunnelDescription td; 1434 DefaultTunnelDescription td;
1435 + SparseAnnotations annotations = null;
1333 State tunnelState = PcepLspStatus.getTunnelStatusFromLspStatus(PcepLspStatus.values()[lspObj.getOFlag()]); 1436 State tunnelState = PcepLspStatus.getTunnelStatusFromLspStatus(PcepLspStatus.values()[lspObj.getOFlag()]);
1334 if (tunnel == null) { 1437 if (tunnel == null) {
1335 if (lspObj.getRFlag()) { 1438 if (lspObj.getRFlag()) {
...@@ -1345,21 +1448,15 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -1345,21 +1448,15 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
1345 * While in sync, if PCRpt is received for PCE init LSP and PCE doesn't have entry, mark to send 1448 * While in sync, if PCRpt is received for PCE init LSP and PCE doesn't have entry, mark to send
1346 * delete message on end of sync. 1449 * delete message on end of sync.
1347 */ 1450 */
1348 - SparseAnnotations annotations = DefaultAnnotations.builder() 1451 + annotations = getAnnotations(lspObj, ipv4LspIdenTlv, bandwidth, lspType);
1349 - .set(BANDWIDTH, (new Integer(bandwidth)).toString())
1350 - .set(LSP_SIG_TYPE, lspType.name())
1351 - .set(PCC_TUNNEL_ID, String.valueOf(ipv4LspIdenTlv.getTunnelId()))
1352 - .set(PLSP_ID, String.valueOf(lspObj.getPlspId()))
1353 - .set(LOCAL_LSP_ID, String.valueOf(ipv4LspIdenTlv.getLspId())).build();
1354 1452
1355 - // Gnenerate tunnel id for the temporary tunnel. 1453 + // Generate tunnel id for the temporary tunnel.
1356 String onosTunnelId = "PCC" + String.valueOf(ipv4LspIdenTlv.getTunnelId()); 1454 String onosTunnelId = "PCC" + String.valueOf(ipv4LspIdenTlv.getTunnelId());
1357 Tunnel tunnelToBeDeleted = new DefaultTunnel(providerId, tunnelEndPointSrc, tunnelEndPointDst, MPLS, 1455 Tunnel tunnelToBeDeleted = new DefaultTunnel(providerId, tunnelEndPointSrc, tunnelEndPointDst, MPLS,
1358 new DefaultGroupId(0), TunnelId.valueOf(onosTunnelId), 1456 new DefaultGroupId(0), TunnelId.valueOf(onosTunnelId),
1359 TunnelName.tunnelName(String 1457 TunnelName.tunnelName(String
1360 .valueOf(pathNameTlv.getValue())), 1458 .valueOf(pathNameTlv.getValue())),
1361 path, annotations); 1459 path, annotations);
1362 -
1363 /* 1460 /*
1364 * Need to send PCInitiate delete msg for a tunnel which does not exist at PCE. For that some dummy 1461 * Need to send PCInitiate delete msg for a tunnel which does not exist at PCE. For that some dummy
1365 * data-structures need to be populated. 1462 * data-structures need to be populated.
...@@ -1378,31 +1475,61 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -1378,31 +1475,61 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
1378 syncCompleteDeleteList.put(pccId.ipAddress(), tunnelToBeDeletedList); 1475 syncCompleteDeleteList.put(pccId.ipAddress(), tunnelToBeDeletedList);
1379 return; 1476 return;
1380 } 1477 }
1478 + DeviceId deviceId = getDevice(pccId);
1479 + if (deviceId == null) {
1480 + log.error("Ingress deviceId not found");
1481 + return;
1482 + }
1483 + annotations = getAnnotations(lspObj, ipv4LspIdenTlv, bandwidth, lspType);
1381 1484
1382 - SparseAnnotations annotations = DefaultAnnotations.builder() 1485 + td = new DefaultTunnelDescription(null, tunnelEndPointSrc, tunnelEndPointDst, MPLS, new DefaultGroupId(
1383 - .set(BANDWIDTH, (new Integer(bandwidth)).toString()) 1486 + 0), providerId, TunnelName.tunnelName(new String(pathNameTlv.getValue())), path,
1384 - .set(LSP_SIG_TYPE, lspType.name())
1385 - .set(PCC_TUNNEL_ID, String.valueOf(ipv4LspIdenTlv.getTunnelId()))
1386 - .set(PLSP_ID, String.valueOf(lspObj.getPlspId()))
1387 - .set(LOCAL_LSP_ID, String.valueOf(ipv4LspIdenTlv.getLspId())).build();
1388 -
1389 - td = new DefaultTunnelDescription(null, tunnelEndPointSrc, tunnelEndPointDst, MPLS,
1390 - new DefaultGroupId(0), providerId,
1391 - TunnelName.tunnelName(String.valueOf(pathNameTlv.getValue())), path,
1392 annotations); 1487 annotations);
1393 - 1488 + /*
1489 + * If ONOS instance is master for PCC then set delegated flag as annotation and add the tunnel to store.
1490 + * Because all LSPs need not be delegated, hence mastership for the PCC is confirmed whereas not the
1491 + * delegation set to all LSPs.If ONOS is not the master for that PCC then check if D flag is set, if yes
1492 + * wait for 2 seconds [while master has added the tunnel to the store] then update the tunnel. Tunnel is
1493 + * updated because in case of resilency only delegated LSPs are recomputed and only delegated PCE can
1494 + * send update message to that client.
1495 + *
1496 + * 1)Master can 1st get the Rpt message
1497 + * a)Master adds the tunnel into core.
1498 + * b)If a non-master for ingress gets Rpt message with D flag set[as delegation owner]
1499 + * after master, then runs timer then update the tunnel with D flag set.
1500 + * 2)Non-Master can 1st get the Rpt message
1501 + * a)Non-Master runs the timer check for the tunnel then updates the tunnel with D flag set
1502 + * b)Master would have got the message while the non-master running timer, hence master adds
1503 + * tunnel to core
1504 + *
1505 + * In general always master adds the tunnel to the core
1506 + * while delegated owner [master or non-master with D flag set] always updates the tunnel running timer
1507 + */
1508 + if (mastershipService.isLocalMaster(deviceId)) {
1394 TunnelId tId = tunnelAdded(td, tunnelState); 1509 TunnelId tId = tunnelAdded(td, tunnelState);
1395 Tunnel tunnelInserted = new DefaultTunnel(providerId, tunnelEndPointSrc, tunnelEndPointDst, MPLS, 1510 Tunnel tunnelInserted = new DefaultTunnel(providerId, tunnelEndPointSrc, tunnelEndPointDst, MPLS,
1396 - tunnelState, new DefaultGroupId(0), tId, 1511 + tunnelState, new DefaultGroupId(0), tId, TunnelName.tunnelName(String.valueOf(pathNameTlv
1397 - TunnelName.tunnelName(String.valueOf(pathNameTlv.getValue())), 1512 + .getValue())), path, annotations);
1398 - path, annotations);
1399 1513
1400 PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnelInserted, path, LSP_STATE_RPT); 1514 PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnelInserted, path, LSP_STATE_RPT);
1401 pcepTunnelData.setStatefulIpv4IndentifierTlv(ipv4LspIdenTlv); 1515 pcepTunnelData.setStatefulIpv4IndentifierTlv(ipv4LspIdenTlv);
1402 pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData); 1516 pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
1517 + } else if (!mastershipService.isLocalMaster(deviceId) && lspObj.getDFlag()) {
1518 + //Start timer then update the tunnel with D flag
1519 + tunnelUpdateInDelegatedCase(pccId, annotations, td, providerId);
1520 + }
1403 return; 1521 return;
1404 } 1522 }
1405 1523
1524 + //delegated owner will update can be a master or non-master
1525 + if (lspObj.getDFlag()) {
1526 + annotations = getAnnotations(lspObj, ipv4LspIdenTlv, bandwidth, lspType);
1527 + td = new DefaultTunnelDescription(null, tunnelEndPointSrc, tunnelEndPointDst, MPLS, new DefaultGroupId(
1528 + 0), providerId, TunnelName.tunnelName(new String(pathNameTlv.getValue())), path,
1529 + annotations);
1530 + tunnelUpdateInDelegatedCase(pccId, annotations, td, providerId);
1531 + }
1532 +
1406 if ((syncStatus == IN_SYNC) && (lspObj.getCFlag()) && (tunnelState != tunnel.state())) { 1533 if ((syncStatus == IN_SYNC) && (lspObj.getCFlag()) && (tunnelState != tunnel.state())) {
1407 // Mark to send PCUpd msg with state known at PCE. 1534 // Mark to send PCUpd msg with state known at PCE.
1408 List<Tunnel> tunnelToBeUpdateList = syncCompleteUpdateList.get(pccId.ipAddress()); 1535 List<Tunnel> tunnelToBeUpdateList = syncCompleteUpdateList.get(pccId.ipAddress());
...@@ -1410,12 +1537,15 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -1410,12 +1537,15 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
1410 syncCompleteUpdateList.put(pccId.ipAddress(), tunnelToBeUpdateList); 1537 syncCompleteUpdateList.put(pccId.ipAddress(), tunnelToBeUpdateList);
1411 return; 1538 return;
1412 } 1539 }
1540 + removeOrUpdatetunnel(tunnel, pccId, lspObj, providerId, syncStatus, tunnelState);
1541 + return;
1542 + }
1413 1543
1414 - td = new DefaultTunnelDescription(tunnel.tunnelId(), tunnel.src(), tunnel.dst(), 1544 + private void removeOrUpdatetunnel(Tunnel tunnel, PccId pccId, PcepLspObject lspObj, ProviderId providerId,
1415 - tunnel.type(), tunnel.groupId(), providerId, 1545 + PcepSyncStatus syncStatus, State tunnelState) {
1416 - tunnel.tunnelName(), tunnel.path(), 1546 + DefaultTunnelDescription td = new DefaultTunnelDescription(tunnel.tunnelId(), tunnel.src(), tunnel.dst(),
1547 + tunnel.type(), tunnel.groupId(), providerId, tunnel.tunnelName(), tunnel.path(),
1417 (SparseAnnotations) tunnel.annotations()); 1548 (SparseAnnotations) tunnel.annotations());
1418 -
1419 if (lspObj.getRFlag()) { 1549 if (lspObj.getRFlag()) {
1420 tunnelRemoved(td); 1550 tunnelRemoved(td);
1421 } else { 1551 } else {
...@@ -1424,7 +1554,21 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -1424,7 +1554,21 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
1424 } 1554 }
1425 tunnelUpdated(td, tunnelState); 1555 tunnelUpdated(td, tunnelState);
1426 } 1556 }
1427 - return; 1557 + }
1558 +
1559 + private void tunnelUpdateInDelegatedCase(PccId pccId, SparseAnnotations annotations,
1560 + DefaultTunnelDescription td, ProviderId providerId) {
1561 + //Wait for 2sec then query tunnel based on ingress PLSP-ID and local LSP-ID
1562 +
1563 + /*
1564 + * If ONOS is not the master for that PCC then check if D flag is set, if yes wait [while
1565 + * master has added the tunnel to the store] then update the tunnel.
1566 + */
1567 + ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
1568 +
1569 + // Thread is started after 2 seconds first time later periodically after 2 seconds to update the tunnel
1570 + executor.scheduleAtFixedRate(new UpdateDelegation(td, providerId, annotations, pccId,
1571 + executor), DELAY, DELAY, TimeUnit.SECONDS);
1428 } 1572 }
1429 1573
1430 /** 1574 /**
...@@ -1578,4 +1722,83 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -1578,4 +1722,83 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
1578 pcepClientController.getClient(pccId).setLabelDbSyncStatus(IN_SYNC); 1722 pcepClientController.getClient(pccId).setLabelDbSyncStatus(IN_SYNC);
1579 } 1723 }
1580 } 1724 }
1725 +
1726 + private DeviceId getDevice(PccId pccId) {
1727 + // Get lsrId of the PCEP client from the PCC ID. Session info is based on lsrID.
1728 + IpAddress lsrId = pccId.ipAddress();
1729 + String lsrIdentifier = String.valueOf(lsrId);
1730 +
1731 + // Find PCC deviceID from lsrId stored as annotations
1732 + Iterable<Device> devices = deviceService.getAvailableDevices();
1733 + for (Device dev : devices) {
1734 + if (dev.annotations().value(AnnotationKeys.TYPE).equals("L3")
1735 + && dev.annotations().value(LSRID).equals(lsrIdentifier)) {
1736 + return dev.id();
1737 + }
1738 + }
1739 + return null;
1740 + }
1741 +
1742 + /**
1743 + * Updates the tunnel with updated tunnel annotation after a delay of two seconds and checks it till
1744 + * tunnel is found.
1745 + */
1746 + private class UpdateDelegation implements Runnable {
1747 + DefaultTunnelDescription td;
1748 + ProviderId providerId;
1749 + SparseAnnotations annotations;
1750 + PccId pccId;
1751 + ScheduledExecutorService executor;
1752 +
1753 + /**
1754 + * Creates an instance of UpdateDelegation.
1755 + *
1756 + * @param td tunnel description
1757 + * @param providerId provider id
1758 + * @param annotations tunnel annotations
1759 + * @param pccId PCEP client id
1760 + * @param executor service of delegated owner
1761 + */
1762 + public UpdateDelegation(DefaultTunnelDescription td, ProviderId providerId, SparseAnnotations annotations,
1763 + PccId pccId, ScheduledExecutorService executor) {
1764 + this.td = td;
1765 + this.providerId = providerId;
1766 + this.annotations = annotations;
1767 + this.pccId = pccId;
1768 + this.executor = executor;
1769 + }
1770 +
1771 + //Temporary using annotations later will use projection/network config service
1772 + @Override
1773 + public void run() {
1774 + Collection<Tunnel> tunnelQueryResult = tunnelService.queryTunnel(td.src(), td.dst());
1775 + TunnelId tempTunnelId = null;
1776 + for (Tunnel t : tunnelQueryResult) {
1777 + if (t.annotations().value(LOCAL_LSP_ID) == null || t.annotations().value(PLSP_ID) == null) {
1778 + continue;
1779 + }
1780 +
1781 + if (t.annotations().value(LOCAL_LSP_ID).equals(td.annotations().value(LOCAL_LSP_ID))
1782 + && t.annotations().value(PLSP_ID).equals(td.annotations().value(PLSP_ID))
1783 + && ((IpTunnelEndPoint) t.src()).ip().equals(pccId.id())) {
1784 + tempTunnelId = t.tunnelId();
1785 + break;
1786 + }
1787 + }
1788 +
1789 + //If tunnel is found update the tunnel and shutdown the thread otherwise thread will be executing
1790 + //periodically
1791 + if (tempTunnelId != null) {
1792 + Tunnel tunnel = new DefaultTunnel(providerId, td.src(), td.dst(), MPLS, new DefaultGroupId(0),
1793 + tempTunnelId, td.tunnelName(), td.path(), annotations);
1794 + tunnelUpdated(tunnel, td.path());
1795 + executor.shutdown();
1796 + try {
1797 + executor.awaitTermination(WAIT_TIME, TimeUnit.SECONDS);
1798 + } catch (InterruptedException e) {
1799 + log.error("updating delegation failed");
1800 + }
1801 + }
1802 + }
1803 + }
1581 } 1804 }
......
...@@ -17,11 +17,14 @@ package org.onosproject.provider.pcep.tunnel.impl; ...@@ -17,11 +17,14 @@ package org.onosproject.provider.pcep.tunnel.impl;
17 17
18 import static org.junit.Assert.assertNotNull; 18 import static org.junit.Assert.assertNotNull;
19 19
20 +import java.util.HashMap;
20 import java.util.List; 21 import java.util.List;
22 +import java.util.Map;
21 import java.util.concurrent.RejectedExecutionException; 23 import java.util.concurrent.RejectedExecutionException;
22 24
23 import org.jboss.netty.channel.Channel; 25 import org.jboss.netty.channel.Channel;
24 import org.onosproject.pcep.controller.ClientCapability; 26 import org.onosproject.pcep.controller.ClientCapability;
27 +import org.onosproject.pcep.controller.LspKey;
25 import org.onosproject.pcep.controller.PccId; 28 import org.onosproject.pcep.controller.PccId;
26 import org.onosproject.pcep.controller.PcepClient; 29 import org.onosproject.pcep.controller.PcepClient;
27 import org.onosproject.pcep.controller.PcepSyncStatus; 30 import org.onosproject.pcep.controller.PcepSyncStatus;
...@@ -45,6 +48,7 @@ public class PcepClientAdapter implements PcepClient { ...@@ -45,6 +48,7 @@ public class PcepClientAdapter implements PcepClient {
45 private PcepVersion pcepVersion; 48 private PcepVersion pcepVersion;
46 private PcepSyncStatus lspDbSyncStatus; 49 private PcepSyncStatus lspDbSyncStatus;
47 private PcepSyncStatus labelDbSyncStatus; 50 private PcepSyncStatus labelDbSyncStatus;
51 + private Map<LspKey, Boolean> lspDelegationInfo = new HashMap<>();
48 52
49 /** 53 /**
50 * Initialize instance with specified parameters. 54 * Initialize instance with specified parameters.
...@@ -147,4 +151,14 @@ public class PcepClientAdapter implements PcepClient { ...@@ -147,4 +151,14 @@ public class PcepClientAdapter implements PcepClient {
147 @Override 151 @Override
148 public void deleteNode(PccId pccId) { 152 public void deleteNode(PccId pccId) {
149 } 153 }
154 +
155 + @Override
156 + public void setLspAndDelegationInfo(LspKey lspKey, boolean dFlag) {
157 + lspDelegationInfo.put(lspKey, dFlag);
158 + }
159 +
160 + @Override
161 + public Boolean delegationInfo(LspKey lspKey) {
162 + return lspDelegationInfo.get(lspKey);
163 + }
150 } 164 }
......
...@@ -24,8 +24,6 @@ import java.util.concurrent.ConcurrentHashMap; ...@@ -24,8 +24,6 @@ import java.util.concurrent.ConcurrentHashMap;
24 24
25 import org.apache.felix.scr.annotations.Activate; 25 import org.apache.felix.scr.annotations.Activate;
26 import org.apache.felix.scr.annotations.Deactivate; 26 import org.apache.felix.scr.annotations.Deactivate;
27 -import org.onlab.packet.IpAddress;
28 -import org.onosproject.pcep.controller.ClientCapability;
29 import org.onosproject.pcep.controller.PccId; 27 import org.onosproject.pcep.controller.PccId;
30 import org.onosproject.pcep.controller.PcepClient; 28 import org.onosproject.pcep.controller.PcepClient;
31 import org.onosproject.pcep.controller.PcepClientController; 29 import org.onosproject.pcep.controller.PcepClientController;
...@@ -75,16 +73,11 @@ public class PcepClientControllerAdapter implements PcepClientController { ...@@ -75,16 +73,11 @@ public class PcepClientControllerAdapter implements PcepClientController {
75 73
76 @Override 74 @Override
77 public PcepClient getClient(PccId pccId) { 75 public PcepClient getClient(PccId pccId) {
78 - if (null != connectedClients.get(pccId)) { 76 + if (connectedClients.get(pccId) != null) {
79 return connectedClients.get(pccId); 77 return connectedClients.get(pccId);
80 } 78 }
81 PcepClientAdapter pc = new PcepClientAdapter(); 79 PcepClientAdapter pc = new PcepClientAdapter();
82 - if (pccId.ipAddress().equals(IpAddress.valueOf(0xC010103)) 80 +
83 - || pccId.ipAddress().equals(IpAddress.valueOf(0xB6024E22))) {
84 - pc.setCapability(new ClientCapability(true, false, false, false, false));
85 - } else {
86 - pc.setCapability(new ClientCapability(true, true, true, false, false));
87 - }
88 pc.init(PccId.pccId(pccId.ipAddress()), PcepVersion.PCEP_1); 81 pc.init(PccId.pccId(pccId.ipAddress()), PcepVersion.PCEP_1);
89 connectedClients.put(pccId, pc); 82 connectedClients.put(pccId, pc);
90 return pc; 83 return pc;
......
...@@ -40,6 +40,7 @@ import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint; ...@@ -40,6 +40,7 @@ import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint;
40 import org.onosproject.incubator.net.tunnel.Tunnel; 40 import org.onosproject.incubator.net.tunnel.Tunnel;
41 import org.onosproject.incubator.net.tunnel.TunnelId; 41 import org.onosproject.incubator.net.tunnel.TunnelId;
42 import org.onosproject.incubator.net.tunnel.TunnelName; 42 import org.onosproject.incubator.net.tunnel.TunnelName;
43 +import org.onosproject.mastership.MastershipServiceAdapter;
43 import org.onosproject.net.Annotations; 44 import org.onosproject.net.Annotations;
44 import org.onosproject.net.ConnectPoint; 45 import org.onosproject.net.ConnectPoint;
45 import org.onosproject.net.DefaultAnnotations; 46 import org.onosproject.net.DefaultAnnotations;
...@@ -49,7 +50,10 @@ import org.onosproject.net.IpElementId; ...@@ -49,7 +50,10 @@ import org.onosproject.net.IpElementId;
49 import org.onosproject.net.Link; 50 import org.onosproject.net.Link;
50 import org.onosproject.net.Path; 51 import org.onosproject.net.Path;
51 import org.onosproject.net.PortNumber; 52 import org.onosproject.net.PortNumber;
53 +import org.onosproject.net.device.DeviceServiceAdapter;
52 import org.onosproject.net.provider.ProviderId; 54 import org.onosproject.net.provider.ProviderId;
55 +import org.onosproject.pcep.controller.ClientCapability;
56 +import org.onosproject.pcep.controller.PccId;
53 import org.onosproject.pcepio.types.StatefulIPv4LspIdentifiersTlv; 57 import org.onosproject.pcepio.types.StatefulIPv4LspIdentifiersTlv;
54 58
55 /** 59 /**
...@@ -64,12 +68,16 @@ public class PcepReleaseTunnelProviderTest { ...@@ -64,12 +68,16 @@ public class PcepReleaseTunnelProviderTest {
64 private final PcepControllerAdapter ctl = new PcepControllerAdapter(); 68 private final PcepControllerAdapter ctl = new PcepControllerAdapter();
65 private final PcepTunnelApiMapper pcepTunnelAPIMapper = new PcepTunnelApiMapper(); 69 private final PcepTunnelApiMapper pcepTunnelAPIMapper = new PcepTunnelApiMapper();
66 private final TunnelServiceAdapter tunnelService = new TunnelServiceAdapter(); 70 private final TunnelServiceAdapter tunnelService = new TunnelServiceAdapter();
71 + private final DeviceServiceAdapter deviceService = new DeviceServiceAdapter();
72 + private final MastershipServiceAdapter mastershipService = new MastershipServiceAdapter();
67 73
68 @Before 74 @Before
69 public void setUp() throws IOException { 75 public void setUp() throws IOException {
70 tunnelProvider.tunnelProviderRegistry = registry; 76 tunnelProvider.tunnelProviderRegistry = registry;
71 tunnelProvider.pcepClientController = controller; 77 tunnelProvider.pcepClientController = controller;
72 tunnelProvider.controller = ctl; 78 tunnelProvider.controller = ctl;
79 + tunnelProvider.deviceService = deviceService;
80 + tunnelProvider.mastershipService = mastershipService;
73 tunnelProvider.tunnelService = tunnelService; 81 tunnelProvider.tunnelService = tunnelService;
74 tunnelProvider.pcepTunnelApiMapper = pcepTunnelAPIMapper; 82 tunnelProvider.pcepTunnelApiMapper = pcepTunnelAPIMapper;
75 tunnelProvider.cfgService = new ComponentConfigAdapter(); 83 tunnelProvider.cfgService = new ComponentConfigAdapter();
...@@ -125,6 +133,8 @@ public class PcepReleaseTunnelProviderTest { ...@@ -125,6 +133,8 @@ public class PcepReleaseTunnelProviderTest {
125 tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData); 133 tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
126 134
127 tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData); 135 tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData);
136 + controller.getClient(PccId.pccId(IpAddress.valueOf(0xB6024E20))).setCapability(
137 + new ClientCapability(true, true, true, true, true));
128 138
129 tunnelProvider.releaseTunnel(tunnel); 139 tunnelProvider.releaseTunnel(tunnel);
130 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue())); 140 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
...@@ -179,6 +189,8 @@ public class PcepReleaseTunnelProviderTest { ...@@ -179,6 +189,8 @@ public class PcepReleaseTunnelProviderTest {
179 tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData); 189 tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
180 190
181 tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData); 191 tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData);
192 + controller.getClient(PccId.pccId(IpAddress.valueOf(0xB6024E22))).setCapability(
193 + new ClientCapability(true, false, false, true, true));
182 194
183 tunnelProvider.releaseTunnel(tunnel); 195 tunnelProvider.releaseTunnel(tunnel);
184 assertThat(tunnelProvider.pcepTunnelApiMapper.checkFromTunnelRequestQueue(1), is(false)); 196 assertThat(tunnelProvider.pcepTunnelApiMapper.checkFromTunnelRequestQueue(1), is(false));
...@@ -233,6 +245,8 @@ public class PcepReleaseTunnelProviderTest { ...@@ -233,6 +245,8 @@ public class PcepReleaseTunnelProviderTest {
233 tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData); 245 tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
234 246
235 tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData); 247 tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData);
248 + controller.getClient(PccId.pccId(IpAddress.valueOf(0xB6024E20))).setCapability(
249 + new ClientCapability(true, true, true, true, true));
236 250
237 tunnelProvider.releaseTunnel(tunnel); 251 tunnelProvider.releaseTunnel(tunnel);
238 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue())); 252 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
...@@ -287,6 +301,8 @@ public class PcepReleaseTunnelProviderTest { ...@@ -287,6 +301,8 @@ public class PcepReleaseTunnelProviderTest {
287 tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData); 301 tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
288 302
289 tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData); 303 tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData);
304 + controller.getClient(PccId.pccId(IpAddress.valueOf(0xB6024E20))).setCapability(
305 + new ClientCapability(true, true, true, true, true));
290 306
291 tunnelProvider.releaseTunnel(tunnel); 307 tunnelProvider.releaseTunnel(tunnel);
292 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue())); 308 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
...@@ -298,5 +314,7 @@ public class PcepReleaseTunnelProviderTest { ...@@ -298,5 +314,7 @@ public class PcepReleaseTunnelProviderTest {
298 tunnelProvider.controller = null; 314 tunnelProvider.controller = null;
299 tunnelProvider.pcepClientController = null; 315 tunnelProvider.pcepClientController = null;
300 tunnelProvider.tunnelProviderRegistry = null; 316 tunnelProvider.tunnelProviderRegistry = null;
317 + tunnelProvider.deviceService = null;
318 + tunnelProvider.mastershipService = null;
301 } 319 }
302 } 320 }
......
...@@ -40,6 +40,7 @@ import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint; ...@@ -40,6 +40,7 @@ import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint;
40 import org.onosproject.incubator.net.tunnel.Tunnel; 40 import org.onosproject.incubator.net.tunnel.Tunnel;
41 import org.onosproject.incubator.net.tunnel.TunnelId; 41 import org.onosproject.incubator.net.tunnel.TunnelId;
42 import org.onosproject.incubator.net.tunnel.TunnelName; 42 import org.onosproject.incubator.net.tunnel.TunnelName;
43 +import org.onosproject.mastership.MastershipServiceAdapter;
43 import org.onosproject.net.Annotations; 44 import org.onosproject.net.Annotations;
44 import org.onosproject.net.ConnectPoint; 45 import org.onosproject.net.ConnectPoint;
45 import org.onosproject.net.DefaultAnnotations; 46 import org.onosproject.net.DefaultAnnotations;
...@@ -49,7 +50,10 @@ import org.onosproject.net.IpElementId; ...@@ -49,7 +50,10 @@ import org.onosproject.net.IpElementId;
49 import org.onosproject.net.Link; 50 import org.onosproject.net.Link;
50 import org.onosproject.net.Path; 51 import org.onosproject.net.Path;
51 import org.onosproject.net.PortNumber; 52 import org.onosproject.net.PortNumber;
53 +import org.onosproject.net.device.DeviceServiceAdapter;
52 import org.onosproject.net.provider.ProviderId; 54 import org.onosproject.net.provider.ProviderId;
55 +import org.onosproject.pcep.controller.ClientCapability;
56 +import org.onosproject.pcep.controller.PccId;
53 57
54 /** 58 /**
55 * Test for PCEP setup tunnel. 59 * Test for PCEP setup tunnel.
...@@ -62,12 +66,16 @@ public class PcepSetupTunnelProviderTest { ...@@ -62,12 +66,16 @@ public class PcepSetupTunnelProviderTest {
62 private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter(); 66 private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter();
63 private final PcepControllerAdapter ctl = new PcepControllerAdapter(); 67 private final PcepControllerAdapter ctl = new PcepControllerAdapter();
64 private final TunnelServiceAdapter tunnelService = new TunnelServiceAdapter(); 68 private final TunnelServiceAdapter tunnelService = new TunnelServiceAdapter();
69 + private final DeviceServiceAdapter deviceService = new DeviceServiceAdapter();
70 + private final MastershipServiceAdapter mastershipService = new MastershipServiceAdapter();
65 71
66 @Before 72 @Before
67 public void setUp() throws IOException { 73 public void setUp() throws IOException {
68 tunnelProvider.tunnelProviderRegistry = registry; 74 tunnelProvider.tunnelProviderRegistry = registry;
69 tunnelProvider.pcepClientController = controller; 75 tunnelProvider.pcepClientController = controller;
70 tunnelProvider.controller = ctl; 76 tunnelProvider.controller = ctl;
77 + tunnelProvider.deviceService = deviceService;
78 + tunnelProvider.mastershipService = mastershipService;
71 tunnelProvider.cfgService = new ComponentConfigAdapter(); 79 tunnelProvider.cfgService = new ComponentConfigAdapter();
72 tunnelProvider.tunnelService = tunnelService; 80 tunnelProvider.tunnelService = tunnelService;
73 tunnelProvider.activate(); 81 tunnelProvider.activate();
...@@ -111,6 +119,8 @@ public class PcepSetupTunnelProviderTest { ...@@ -111,6 +119,8 @@ public class PcepSetupTunnelProviderTest {
111 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS, 119 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
112 new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"), 120 new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
113 path, annotations); 121 path, annotations);
122 + controller.getClient(PccId.pccId(IpAddress.valueOf(0xC010101))).setCapability(
123 + new ClientCapability(true, true, true, true, true));
114 124
115 tunnelProvider.setupTunnel(tunnel, path); 125 tunnelProvider.setupTunnel(tunnel, path);
116 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue())); 126 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
...@@ -154,6 +164,8 @@ public class PcepSetupTunnelProviderTest { ...@@ -154,6 +164,8 @@ public class PcepSetupTunnelProviderTest {
154 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS, 164 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
155 new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"), 165 new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
156 path, annotations); 166 path, annotations);
167 + controller.getClient(PccId.pccId(IpAddress.valueOf(0xC010103))).setCapability(
168 + new ClientCapability(true, true, true, true, true));
157 169
158 tunnelProvider.setupTunnel(tunnel, path); 170 tunnelProvider.setupTunnel(tunnel, path);
159 assertThat(tunnelProvider.pcepTunnelApiMapper.checkFromTunnelRequestQueue(1), is(false)); 171 assertThat(tunnelProvider.pcepTunnelApiMapper.checkFromTunnelRequestQueue(1), is(false));
...@@ -197,6 +209,8 @@ public class PcepSetupTunnelProviderTest { ...@@ -197,6 +209,8 @@ public class PcepSetupTunnelProviderTest {
197 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS, 209 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
198 new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"), 210 new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
199 path, annotations); 211 path, annotations);
212 + controller.getClient(PccId.pccId(IpAddress.valueOf(0xC010101))).setCapability(
213 + new ClientCapability(true, true, true, true, true));
200 214
201 tunnelProvider.setupTunnel(tunnel, path); 215 tunnelProvider.setupTunnel(tunnel, path);
202 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue())); 216 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
...@@ -240,6 +254,8 @@ public class PcepSetupTunnelProviderTest { ...@@ -240,6 +254,8 @@ public class PcepSetupTunnelProviderTest {
240 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS, 254 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
241 new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"), 255 new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
242 path, annotations); 256 path, annotations);
257 + controller.getClient(PccId.pccId(IpAddress.valueOf(0xC010101))).setCapability(
258 + new ClientCapability(true, true, true, true, true));
243 259
244 tunnelProvider.setupTunnel(tunnel, path); 260 tunnelProvider.setupTunnel(tunnel, path);
245 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue())); 261 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
...@@ -251,5 +267,7 @@ public class PcepSetupTunnelProviderTest { ...@@ -251,5 +267,7 @@ public class PcepSetupTunnelProviderTest {
251 tunnelProvider.controller = null; 267 tunnelProvider.controller = null;
252 tunnelProvider.pcepClientController = null; 268 tunnelProvider.pcepClientController = null;
253 tunnelProvider.tunnelProviderRegistry = null; 269 tunnelProvider.tunnelProviderRegistry = null;
270 + tunnelProvider.deviceService = null;
271 + tunnelProvider.mastershipService = null;
254 } 272 }
255 } 273 }
......
...@@ -24,27 +24,36 @@ import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.LOCAL ...@@ -24,27 +24,36 @@ import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.LOCAL
24 import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.LSP_SIG_TYPE; 24 import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.LSP_SIG_TYPE;
25 import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.PCC_TUNNEL_ID; 25 import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.PCC_TUNNEL_ID;
26 import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.PLSP_ID; 26 import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.PLSP_ID;
27 +import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.DELEGATE;
27 import static org.onosproject.provider.pcep.tunnel.impl.LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR; 28 import static org.onosproject.provider.pcep.tunnel.impl.LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR;
28 import static org.onosproject.pcep.controller.PcepSyncStatus.SYNCED; 29 import static org.onosproject.pcep.controller.PcepSyncStatus.SYNCED;
29 import static org.onosproject.pcep.controller.PcepSyncStatus.IN_SYNC; 30 import static org.onosproject.pcep.controller.PcepSyncStatus.IN_SYNC;
31 +import static org.onosproject.net.Device.Type.ROUTER;
32 +import static org.onosproject.net.MastershipRole.MASTER;
30 33
31 import java.io.IOException; 34 import java.io.IOException;
32 import java.util.Collection; 35 import java.util.Collection;
33 import java.util.Collections; 36 import java.util.Collections;
34 import java.util.HashMap; 37 import java.util.HashMap;
35 import java.util.HashSet; 38 import java.util.HashSet;
39 +import java.util.LinkedList;
40 +import java.util.List;
41 +import java.util.concurrent.TimeUnit;
36 42
37 import org.jboss.netty.buffer.ChannelBuffer; 43 import org.jboss.netty.buffer.ChannelBuffer;
38 import org.jboss.netty.buffer.ChannelBuffers; 44 import org.jboss.netty.buffer.ChannelBuffers;
39 import org.junit.After; 45 import org.junit.After;
40 import org.junit.Before; 46 import org.junit.Before;
41 import org.junit.Test; 47 import org.junit.Test;
48 +import org.onlab.packet.ChassisId;
42 import org.onlab.packet.IpAddress; 49 import org.onlab.packet.IpAddress;
43 import org.onosproject.cfg.ComponentConfigAdapter; 50 import org.onosproject.cfg.ComponentConfigAdapter;
44 import org.onosproject.core.ApplicationId; 51 import org.onosproject.core.ApplicationId;
45 import org.onosproject.incubator.net.tunnel.DefaultTunnel; 52 import org.onosproject.incubator.net.tunnel.DefaultTunnel;
46 import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint; 53 import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint;
47 import org.onosproject.incubator.net.tunnel.Tunnel; 54 import org.onosproject.incubator.net.tunnel.Tunnel;
55 +import org.onosproject.incubator.net.tunnel.Tunnel.Type;
56 +import org.onosproject.incubator.net.tunnel.TunnelAdminService;
48 import org.onosproject.incubator.net.tunnel.TunnelDescription; 57 import org.onosproject.incubator.net.tunnel.TunnelDescription;
49 import org.onosproject.incubator.net.tunnel.TunnelEndPoint; 58 import org.onosproject.incubator.net.tunnel.TunnelEndPoint;
50 import org.onosproject.incubator.net.tunnel.TunnelId; 59 import org.onosproject.incubator.net.tunnel.TunnelId;
...@@ -52,16 +61,26 @@ import org.onosproject.incubator.net.tunnel.TunnelName; ...@@ -52,16 +61,26 @@ import org.onosproject.incubator.net.tunnel.TunnelName;
52 import org.onosproject.incubator.net.tunnel.TunnelProvider; 61 import org.onosproject.incubator.net.tunnel.TunnelProvider;
53 import org.onosproject.incubator.net.tunnel.TunnelProviderService; 62 import org.onosproject.incubator.net.tunnel.TunnelProviderService;
54 import org.onosproject.incubator.net.tunnel.Tunnel.State; 63 import org.onosproject.incubator.net.tunnel.Tunnel.State;
64 +import org.onosproject.mastership.MastershipServiceAdapter;
65 +import org.onosproject.net.AnnotationKeys;
55 import org.onosproject.net.DefaultAnnotations; 66 import org.onosproject.net.DefaultAnnotations;
67 +import org.onosproject.net.DefaultDevice;
68 +import org.onosproject.net.Device;
69 +import org.onosproject.net.DeviceId;
56 import org.onosproject.net.ElementId; 70 import org.onosproject.net.ElementId;
71 +import org.onosproject.net.MastershipRole;
57 import org.onosproject.net.Path; 72 import org.onosproject.net.Path;
58 import org.onosproject.net.SparseAnnotations; 73 import org.onosproject.net.SparseAnnotations;
74 +import org.onosproject.net.device.DeviceServiceAdapter;
75 +import org.onosproject.net.provider.ProviderId;
59 import org.onosproject.pcepio.exceptions.PcepOutOfBoundMessageException; 76 import org.onosproject.pcepio.exceptions.PcepOutOfBoundMessageException;
60 import org.onosproject.pcepio.exceptions.PcepParseException; 77 import org.onosproject.pcepio.exceptions.PcepParseException;
61 import org.onosproject.pcepio.protocol.PcepFactories; 78 import org.onosproject.pcepio.protocol.PcepFactories;
62 import org.onosproject.pcepio.protocol.PcepMessage; 79 import org.onosproject.pcepio.protocol.PcepMessage;
63 import org.onosproject.pcepio.protocol.PcepMessageReader; 80 import org.onosproject.pcepio.protocol.PcepMessageReader;
81 +import org.onosproject.pcepio.protocol.PcepVersion;
64 import org.onosproject.pcep.controller.ClientCapability; 82 import org.onosproject.pcep.controller.ClientCapability;
83 +import org.onosproject.pcep.controller.LspKey;
65 import org.onosproject.pcep.controller.PccId; 84 import org.onosproject.pcep.controller.PccId;
66 85
67 import com.google.common.collect.ImmutableSet; 86 import com.google.common.collect.ImmutableSet;
...@@ -71,13 +90,73 @@ import com.google.common.collect.ImmutableSet; ...@@ -71,13 +90,73 @@ import com.google.common.collect.ImmutableSet;
71 */ 90 */
72 public class PcepTunnelAddedTest { 91 public class PcepTunnelAddedTest {
73 92
74 - static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep"; 93 + public static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep";
94 + public static final String UNKOWN = "UNKOWN";
75 PcepTunnelProvider tunnelProvider = new PcepTunnelProvider(); 95 PcepTunnelProvider tunnelProvider = new PcepTunnelProvider();
76 private final MockTunnelProviderRegistryAdapter registry = new MockTunnelProviderRegistryAdapter(); 96 private final MockTunnelProviderRegistryAdapter registry = new MockTunnelProviderRegistryAdapter();
77 private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter(); 97 private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter();
78 private final PcepControllerAdapter ctl = new PcepControllerAdapter(); 98 private final PcepControllerAdapter ctl = new PcepControllerAdapter();
79 private final PcepTunnelApiMapper pcepTunnelAPIMapper = new PcepTunnelApiMapper(); 99 private final PcepTunnelApiMapper pcepTunnelAPIMapper = new PcepTunnelApiMapper();
80 private final MockTunnelServiceAdapter tunnelService = new MockTunnelServiceAdapter(); 100 private final MockTunnelServiceAdapter tunnelService = new MockTunnelServiceAdapter();
101 + public final MockDeviceService deviceService = new MockDeviceService();
102 + private final MockMasterShipService masterShipService = new MockMasterShipService();
103 + private final MockTunnelAdminService tunnelAdminService = new MockTunnelAdminService();
104 +
105 + private class MockTunnelAdminService implements TunnelAdminService {
106 +
107 + @Override
108 + public void removeTunnel(TunnelId tunnelId) {
109 + // TODO Auto-generated method stub
110 + }
111 +
112 + @Override
113 + public void removeTunnels(TunnelEndPoint src, TunnelEndPoint dst, ProviderId producerName) {
114 + // TODO Auto-generated method stub
115 + }
116 +
117 + @Override
118 + public void removeTunnels(TunnelEndPoint src, TunnelEndPoint dst, Type type, ProviderId producerName) {
119 + // TODO Auto-generated method stub
120 + }
121 +
122 + @Override
123 + public void updateTunnel(Tunnel tunnel, Path path) {
124 + if (tunnelService.tunnelIdAsKeyStore.containsKey(tunnel.tunnelId())) {
125 + tunnelService.tunnelIdAsKeyStore.replace(tunnel.tunnelId(), tunnel);
126 + }
127 + }
128 + }
129 +
130 + private class MockMasterShipService extends MastershipServiceAdapter {
131 + boolean set;
132 +
133 + private void setMaster(boolean isMaster) {
134 + this.set = isMaster;
135 + }
136 +
137 + @Override
138 + public MastershipRole getLocalRole(DeviceId deviceId) {
139 + return set ? MastershipRole.MASTER : MastershipRole.STANDBY;
140 + }
141 +
142 + @Override
143 + public boolean isLocalMaster(DeviceId deviceId) {
144 + return getLocalRole(deviceId) == MASTER;
145 + }
146 + }
147 +
148 + private class MockDeviceService extends DeviceServiceAdapter {
149 + List<Device> devices = new LinkedList<>();
150 +
151 + private void addDevice(Device dev) {
152 + devices.add(dev);
153 + }
154 +
155 + @Override
156 + public Iterable<Device> getAvailableDevices() {
157 + return devices;
158 + }
159 + }
81 160
82 private class MockTunnelProviderRegistryAdapter extends TunnelProviderRegistryAdapter { 161 private class MockTunnelProviderRegistryAdapter extends TunnelProviderRegistryAdapter {
83 public long tunnelIdCounter; 162 public long tunnelIdCounter;
...@@ -97,12 +176,34 @@ public class PcepTunnelAddedTest { ...@@ -97,12 +176,34 @@ public class PcepTunnelAddedTest {
97 176
98 @Override 177 @Override
99 public TunnelId tunnelAdded(TunnelDescription tunnel) { 178 public TunnelId tunnelAdded(TunnelDescription tunnel) {
100 - return TunnelId.valueOf(String.valueOf(++tunnelIdCounter)); 179 + TunnelId id = TunnelId.valueOf(String.valueOf(++tunnelIdCounter));
180 + Tunnel storedTunnel = new DefaultTunnel(ProviderId.NONE,
181 + tunnel.src(), tunnel.dst(),
182 + tunnel.type(),
183 + tunnel.groupId(),
184 + id,
185 + tunnel.tunnelName(),
186 + tunnel.path(),
187 + tunnel.resource(),
188 + tunnel.annotations());
189 + tunnelService.tunnelIdAsKeyStore.put(id, storedTunnel);
190 + return id;
101 } 191 }
102 192
103 @Override 193 @Override
104 public TunnelId tunnelAdded(TunnelDescription tunnel, State state) { 194 public TunnelId tunnelAdded(TunnelDescription tunnel, State state) {
105 - return TunnelId.valueOf(String.valueOf(++tunnelIdCounter)); 195 + TunnelId id = TunnelId.valueOf(String.valueOf(++tunnelIdCounter));
196 + Tunnel storedTunnel = new DefaultTunnel(ProviderId.NONE,
197 + tunnel.src(), tunnel.dst(),
198 + tunnel.type(),
199 + tunnel.groupId(),
200 + id,
201 + tunnel.tunnelName(),
202 + tunnel.path(),
203 + tunnel.resource(),
204 + tunnel.annotations());
205 + tunnelService.tunnelIdAsKeyStore.put(id, storedTunnel);
206 + return id;
106 } 207 }
107 208
108 @Override 209 @Override
...@@ -168,9 +269,12 @@ public class PcepTunnelAddedTest { ...@@ -168,9 +269,12 @@ public class PcepTunnelAddedTest {
168 tunnelProvider.tunnelProviderRegistry = registry; 269 tunnelProvider.tunnelProviderRegistry = registry;
169 tunnelProvider.pcepClientController = controller; 270 tunnelProvider.pcepClientController = controller;
170 tunnelProvider.controller = ctl; 271 tunnelProvider.controller = ctl;
272 + tunnelProvider.deviceService = deviceService;
273 + tunnelProvider.mastershipService = masterShipService;
171 tunnelProvider.pcepTunnelApiMapper = pcepTunnelAPIMapper; 274 tunnelProvider.pcepTunnelApiMapper = pcepTunnelAPIMapper;
172 tunnelProvider.cfgService = new ComponentConfigAdapter(); 275 tunnelProvider.cfgService = new ComponentConfigAdapter();
173 tunnelProvider.tunnelService = tunnelService; 276 tunnelProvider.tunnelService = tunnelService;
277 + tunnelProvider.tunnelAdminService = tunnelAdminService;
174 tunnelProvider.service = registry.register(tunnelProvider); 278 tunnelProvider.service = registry.register(tunnelProvider);
175 tunnelProvider.activate(); 279 tunnelProvider.activate();
176 } 280 }
...@@ -210,6 +314,19 @@ public class PcepTunnelAddedTest { ...@@ -210,6 +314,19 @@ public class PcepTunnelAddedTest {
210 314
211 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); 315 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
212 PcepMessage message = reader.readFrom(buffer); 316 PcepMessage message = reader.readFrom(buffer);
317 +
318 + DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder();
319 + newBuilder.set(PcepTunnelProvider.LSRID, "1.1.1.1");
320 + newBuilder.set(AnnotationKeys.TYPE, "L3");
321 + Device device = new DefaultDevice(ProviderId.NONE, DeviceId.deviceId("1.1.1.1"), ROUTER,
322 + UNKOWN, UNKOWN, UNKOWN,
323 + UNKOWN, new ChassisId(),
324 + newBuilder.build());
325 +
326 + deviceService.addDevice(device);
327 + controller.getClient(PccId.pccId(IpAddress.valueOf("1.1.1.1"))).setCapability(
328 + new ClientCapability(true, true, true, true, true));
329 + masterShipService.setMaster(true);
213 controller.processClientMessage(PccId.pccId(IpAddress.valueOf("1.1.1.1")), message); 330 controller.processClientMessage(PccId.pccId(IpAddress.valueOf("1.1.1.1")), message);
214 331
215 assertThat(registry.tunnelIdCounter, is((long) 1)); 332 assertThat(registry.tunnelIdCounter, is((long) 1));
...@@ -254,14 +371,20 @@ public class PcepTunnelAddedTest { ...@@ -254,14 +371,20 @@ public class PcepTunnelAddedTest {
254 .set(LSP_SIG_TYPE, WITHOUT_SIGNALLING_AND_WITHOUT_SR.name()) 371 .set(LSP_SIG_TYPE, WITHOUT_SIGNALLING_AND_WITHOUT_SR.name())
255 .set(PCC_TUNNEL_ID, String.valueOf(1)) 372 .set(PCC_TUNNEL_ID, String.valueOf(1))
256 .set(PLSP_ID, String.valueOf(1)) 373 .set(PLSP_ID, String.valueOf(1))
257 - .set(LOCAL_LSP_ID, String.valueOf(1)).build(); 374 + .set(LOCAL_LSP_ID, String.valueOf(1))
375 + .set(DELEGATE, String.valueOf("true"))
376 + .build();
258 377
259 Tunnel tunnel = new DefaultTunnel(null, tunnelEndPointSrc, tunnelEndPointDst, MPLS, INIT, null, null, 378 Tunnel tunnel = new DefaultTunnel(null, tunnelEndPointSrc, tunnelEndPointDst, MPLS, INIT, null, null,
260 TunnelName.tunnelName("T123"), null, annotations); 379 TunnelName.tunnelName("T123"), null, annotations);
261 tunnelService.setupTunnel(null, null, tunnel, null); 380 tunnelService.setupTunnel(null, null, tunnel, null);
262 381
263 PccId pccId = PccId.pccId(IpAddress.valueOf(0x4e1f0400)); 382 PccId pccId = PccId.pccId(IpAddress.valueOf(0x4e1f0400));
264 - controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, false, false)); 383 + PcepClientAdapter pc = new PcepClientAdapter();
384 + pc.init(pccId, PcepVersion.PCEP_1);
385 + masterShipService.setMaster(true);
386 + controller.getClient(pccId).setLspAndDelegationInfo(new LspKey(1, (short) 1), true);
387 + controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, true, true));
265 controller.getClient(pccId).setLspDbSyncStatus(SYNCED); 388 controller.getClient(pccId).setLspDbSyncStatus(SYNCED);
266 389
267 // Process update message. 390 // Process update message.
...@@ -308,15 +431,127 @@ public class PcepTunnelAddedTest { ...@@ -308,15 +431,127 @@ public class PcepTunnelAddedTest {
308 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); 431 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
309 PcepMessage message = reader.readFrom(buffer); 432 PcepMessage message = reader.readFrom(buffer);
310 433
434 + DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder();
435 + newBuilder.set(PcepTunnelProvider.LSRID, "1.1.1.1");
436 + newBuilder.set(AnnotationKeys.TYPE, "L3");
437 + Device device = new DefaultDevice(ProviderId.NONE, DeviceId.deviceId("1.1.1.1"), ROUTER,
438 + UNKOWN, UNKOWN, UNKOWN,
439 + UNKOWN, new ChassisId(),
440 + newBuilder.build());
441 +
442 + deviceService.addDevice(device);
443 +
311 PccId pccId = PccId.pccId(IpAddress.valueOf("1.1.1.1")); 444 PccId pccId = PccId.pccId(IpAddress.valueOf("1.1.1.1"));
312 controller.getClient(pccId).setLspDbSyncStatus(SYNCED); 445 controller.getClient(pccId).setLspDbSyncStatus(SYNCED);
313 - controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, false, false)); 446 + controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, true, true));
447 +
448 + PcepClientAdapter pc = new PcepClientAdapter();
449 + pc.init(pccId, PcepVersion.PCEP_1);
450 + controller.getClient(pccId).setLspAndDelegationInfo(new LspKey(1, (short) 1), true);
451 + masterShipService.setMaster(true);
314 controller.processClientMessage(pccId, message); 452 controller.processClientMessage(pccId, message);
315 453
316 assertThat(registry.tunnelIdCounter, is((long) 1)); 454 assertThat(registry.tunnelIdCounter, is((long) 1));
317 } 455 }
318 456
319 /** 457 /**
458 + * Tests PCRpt msg with D flag set and delegated to non-master.
459 + *
460 + * @throws InterruptedException while waiting for delay
461 + */
462 + @Test
463 + public void tunnelProviderAddedTest4() throws PcepParseException, PcepOutOfBoundMessageException,
464 + InterruptedException {
465 + byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x84,
466 + 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object
467 + 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV
468 + 0x00, 0x00, 0x00, 0x02,
469 + 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x02, //LSP object
470 + 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv
471 + 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
472 + 0x01, 0x01, 0x01, 0x01,
473 + 0x00, 0x01, 0x00, 0x01,
474 + 0x01, 0x01, 0x01, 0x01,
475 + 0x05, 0x05, 0x05, 0x05,
476 +
477 + 0x07, 0x10, 0x00, 0x14, //ERO object
478 + 0x01, 0x08, (byte) 0x01, 0x01, 0x01, 0x01, 0x04, 0x00, // ERO IPv4 sub objects
479 + 0x01, 0x08, (byte) 0x05, 0x05, 0x05, 0x05, 0x04, 0x00,
480 +
481 + 0x08, 0x10, 0x00, 0x34, //RRO object
482 + 0x01, 0x08, 0x11, 0x01, 0x01, 0x01, 0x04, 0x00, // RRO IPv4 sub objects
483 + 0x01, 0x08, 0x11, 0x01, 0x01, 0x02, 0x04, 0x00,
484 + 0x01, 0x08, 0x06, 0x06, 0x06, 0x06, 0x04, 0x00,
485 + 0x01, 0x08, 0x12, 0x01, 0x01, 0x02, 0x04, 0x00,
486 + 0x01, 0x08, 0x12, 0x01, 0x01, 0x01, 0x04, 0x00,
487 + 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00
488 + };
489 +
490 + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
491 + buffer.writeBytes(reportMsg);
492 +
493 + PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
494 + PcepMessage message = reader.readFrom(buffer);
495 +
496 + //PCC 1.1.1.1, D=0, ONOS as master
497 + masterShipService.setMaster(true);
498 + DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder();
499 + newBuilder.set(PcepTunnelProvider.LSRID, "1.1.1.1");
500 + newBuilder.set(AnnotationKeys.TYPE, "L3");
501 + Device device = new DefaultDevice(ProviderId.NONE, DeviceId.deviceId("1.1.1.1"), ROUTER,
502 + UNKOWN, UNKOWN, UNKOWN,
503 + UNKOWN, new ChassisId(),
504 + newBuilder.build());
505 +
506 + deviceService.addDevice(device);
507 + controller.getClient(PccId.pccId(IpAddress.valueOf("1.1.1.1"))).setCapability(
508 + new ClientCapability(true, true, true, true, true));
509 + controller.processClientMessage(PccId.pccId(IpAddress.valueOf("1.1.1.1")), message);
510 + assertThat(tunnelService.tunnelIdAsKeyStore.values().iterator().next().annotations().value(DELEGATE),
511 + is("false"));
512 +
513 + //PCC 1.1.1.1, D=1, non-master
514 + masterShipService.setMaster(false);
515 +
516 + reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x84,
517 + 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object
518 + 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV
519 + 0x00, 0x00, 0x00, 0x02,
520 + 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x03, //LSP object
521 + 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv
522 + 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
523 + 0x01, 0x01, 0x01, 0x01,
524 + 0x00, 0x01, 0x00, 0x01,
525 + 0x01, 0x01, 0x01, 0x01,
526 + 0x05, 0x05, 0x05, 0x05,
527 +
528 + 0x07, 0x10, 0x00, 0x14, //ERO object
529 + 0x01, 0x08, (byte) 0x01, 0x01, 0x01, 0x01, 0x04, 0x00, // ERO IPv4 sub objects
530 + 0x01, 0x08, (byte) 0x05, 0x05, 0x05, 0x05, 0x04, 0x00,
531 +
532 + 0x08, 0x10, 0x00, 0x34, //RRO object
533 + 0x01, 0x08, 0x11, 0x01, 0x01, 0x01, 0x04, 0x00, // RRO IPv4 sub objects
534 + 0x01, 0x08, 0x11, 0x01, 0x01, 0x02, 0x04, 0x00,
535 + 0x01, 0x08, 0x06, 0x06, 0x06, 0x06, 0x04, 0x00,
536 + 0x01, 0x08, 0x12, 0x01, 0x01, 0x02, 0x04, 0x00,
537 + 0x01, 0x08, 0x12, 0x01, 0x01, 0x01, 0x04, 0x00,
538 + 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00
539 + };
540 +
541 + buffer = ChannelBuffers.dynamicBuffer();
542 + buffer.writeBytes(reportMsg);
543 +
544 + reader = PcepFactories.getGenericReader();
545 + message = reader.readFrom(buffer);
546 +
547 + controller.processClientMessage(PccId.pccId(IpAddress.valueOf("1.1.1.1")), message);
548 + TimeUnit.MILLISECONDS.sleep(4000);
549 + assertThat(registry.tunnelIdCounter, is((long) 1));
550 + assertThat(tunnelService.tunnelIdAsKeyStore.values().iterator().next().annotations().value(DELEGATE),
551 + is("true"));
552 + }
553 +
554 + /**
320 * Tests LSPDB sync where PCC reports less LSPs than known by PCE and PCE deletes at the end of DB sync. 555 * Tests LSPDB sync where PCC reports less LSPs than known by PCE and PCE deletes at the end of DB sync.
321 */ 556 */
322 @Test 557 @Test
...@@ -355,8 +590,23 @@ public class PcepTunnelAddedTest { ...@@ -355,8 +590,23 @@ public class PcepTunnelAddedTest {
355 PcepMessageReader<PcepMessage> reader1 = PcepFactories.getGenericReader(); 590 PcepMessageReader<PcepMessage> reader1 = PcepFactories.getGenericReader();
356 PcepMessage message1 = reader1.readFrom(buffer1); 591 PcepMessage message1 = reader1.readFrom(buffer1);
357 592
593 + DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder();
594 + newBuilder.set(PcepTunnelProvider.LSRID, "1.1.1.1");
595 + newBuilder.set(AnnotationKeys.TYPE, "L3");
596 + Device device = new DefaultDevice(ProviderId.NONE, DeviceId.deviceId("1.1.1.1"), ROUTER,
597 + UNKOWN, UNKOWN, UNKOWN,
598 + UNKOWN, new ChassisId(),
599 + newBuilder.build());
600 +
601 + deviceService.addDevice(device);
602 +
358 PccId pccId = PccId.pccId(IpAddress.valueOf("1.1.1.1")); 603 PccId pccId = PccId.pccId(IpAddress.valueOf("1.1.1.1"));
359 - controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, false, false)); 604 + controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, true, true));
605 +
606 + PcepClientAdapter pc = new PcepClientAdapter();
607 + pc.init(pccId, PcepVersion.PCEP_1);
608 + controller.getClient(pccId).setLspAndDelegationInfo(new LspKey(2, (short) 2), true);
609 + masterShipService.setMaster(true);
360 controller.processClientMessage(pccId, message1); 610 controller.processClientMessage(pccId, message1);
361 611
362 /* create 2nd LSP */ 612 /* create 2nd LSP */
...@@ -494,8 +744,24 @@ public class PcepTunnelAddedTest { ...@@ -494,8 +744,24 @@ public class PcepTunnelAddedTest {
494 PcepMessageReader<PcepMessage> reader1 = PcepFactories.getGenericReader(); 744 PcepMessageReader<PcepMessage> reader1 = PcepFactories.getGenericReader();
495 PcepMessage message1 = reader1.readFrom(buffer1); 745 PcepMessage message1 = reader1.readFrom(buffer1);
496 746
747 + DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder();
748 + newBuilder.set(PcepTunnelProvider.LSRID, "1.1.1.1");
749 + newBuilder.set(AnnotationKeys.TYPE, "L3");
750 + Device device = new DefaultDevice(ProviderId.NONE, DeviceId.deviceId("1.1.1.1"), ROUTER,
751 + UNKOWN, UNKOWN, UNKOWN,
752 + UNKOWN, new ChassisId(),
753 + newBuilder.build());
754 +
755 + deviceService.addDevice(device);
756 +
497 PccId pccId = PccId.pccId(IpAddress.valueOf("1.1.1.1")); 757 PccId pccId = PccId.pccId(IpAddress.valueOf("1.1.1.1"));
498 - controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, false, false)); 758 + controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, true, true));
759 +
760 + PcepClientAdapter pc = new PcepClientAdapter();
761 + pc.init(pccId, PcepVersion.PCEP_1);
762 + masterShipService.setMaster(true);
763 + controller.getClient(pccId).setLspAndDelegationInfo(new LspKey(2, (short) 2), true);
764 +
499 controller.processClientMessage(pccId, message1); 765 controller.processClientMessage(pccId, message1);
500 766
501 /* create 2nd LSP */ 767 /* create 2nd LSP */
...@@ -604,6 +870,9 @@ public class PcepTunnelAddedTest { ...@@ -604,6 +870,9 @@ public class PcepTunnelAddedTest {
604 tunnelProvider.pcepTunnelApiMapper = null; 870 tunnelProvider.pcepTunnelApiMapper = null;
605 tunnelProvider.cfgService = null; 871 tunnelProvider.cfgService = null;
606 tunnelProvider.tunnelService = null; 872 tunnelProvider.tunnelService = null;
873 + tunnelProvider.tunnelAdminService = null;
874 + tunnelProvider.deviceService = null;
875 + tunnelProvider.mastershipService = null;
607 tunnelProvider.service = null; 876 tunnelProvider.service = null;
608 } 877 }
609 } 878 }
......
...@@ -35,6 +35,7 @@ import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint; ...@@ -35,6 +35,7 @@ import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint;
35 import org.onosproject.incubator.net.tunnel.Tunnel; 35 import org.onosproject.incubator.net.tunnel.Tunnel;
36 import org.onosproject.incubator.net.tunnel.TunnelId; 36 import org.onosproject.incubator.net.tunnel.TunnelId;
37 import org.onosproject.incubator.net.tunnel.TunnelName; 37 import org.onosproject.incubator.net.tunnel.TunnelName;
38 +import org.onosproject.mastership.MastershipServiceAdapter;
38 import org.onosproject.net.Annotations; 39 import org.onosproject.net.Annotations;
39 import org.onosproject.net.ConnectPoint; 40 import org.onosproject.net.ConnectPoint;
40 import org.onosproject.net.DefaultAnnotations; 41 import org.onosproject.net.DefaultAnnotations;
...@@ -44,7 +45,10 @@ import org.onosproject.net.IpElementId; ...@@ -44,7 +45,10 @@ import org.onosproject.net.IpElementId;
44 import org.onosproject.net.Link; 45 import org.onosproject.net.Link;
45 import org.onosproject.net.Path; 46 import org.onosproject.net.Path;
46 import org.onosproject.net.PortNumber; 47 import org.onosproject.net.PortNumber;
48 +import org.onosproject.net.device.DeviceServiceAdapter;
47 import org.onosproject.net.provider.ProviderId; 49 import org.onosproject.net.provider.ProviderId;
50 +import org.onosproject.pcep.controller.ClientCapability;
51 +import org.onosproject.pcep.controller.PccId;
48 import org.onosproject.cfg.ComponentConfigAdapter; 52 import org.onosproject.cfg.ComponentConfigAdapter;
49 53
50 public class PcepTunnelProviderTest { 54 public class PcepTunnelProviderTest {
...@@ -55,6 +59,8 @@ public class PcepTunnelProviderTest { ...@@ -55,6 +59,8 @@ public class PcepTunnelProviderTest {
55 private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter(); 59 private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter();
56 private final PcepControllerAdapter ctl = new PcepControllerAdapter(); 60 private final PcepControllerAdapter ctl = new PcepControllerAdapter();
57 private final TunnelServiceAdapter tunnelService = new TunnelServiceAdapter(); 61 private final TunnelServiceAdapter tunnelService = new TunnelServiceAdapter();
62 + private final DeviceServiceAdapter deviceService = new DeviceServiceAdapter();
63 + private final MastershipServiceAdapter mastershipService = new MastershipServiceAdapter();
58 64
59 @Test 65 @Test
60 public void testCasePcepSetupTunnel() { 66 public void testCasePcepSetupTunnel() {
...@@ -62,6 +68,8 @@ public class PcepTunnelProviderTest { ...@@ -62,6 +68,8 @@ public class PcepTunnelProviderTest {
62 tunnelProvider.tunnelProviderRegistry = registry; 68 tunnelProvider.tunnelProviderRegistry = registry;
63 tunnelProvider.pcepClientController = controller; 69 tunnelProvider.pcepClientController = controller;
64 tunnelProvider.controller = ctl; 70 tunnelProvider.controller = ctl;
71 + tunnelProvider.deviceService = deviceService;
72 + tunnelProvider.mastershipService = mastershipService;
65 tunnelProvider.cfgService = new ComponentConfigAdapter(); 73 tunnelProvider.cfgService = new ComponentConfigAdapter();
66 tunnelProvider.tunnelService = tunnelService; 74 tunnelProvider.tunnelService = tunnelService;
67 tunnelProvider.activate(); 75 tunnelProvider.activate();
...@@ -99,6 +107,8 @@ public class PcepTunnelProviderTest { ...@@ -99,6 +107,8 @@ public class PcepTunnelProviderTest {
99 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS, 107 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
100 new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"), 108 new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
101 path, annotations); 109 path, annotations);
110 + controller.getClient(PccId.pccId(IpAddress.valueOf(0xC010101))).setCapability(
111 + new ClientCapability(true, true, true, true, true));
102 112
103 tunnelProvider.setupTunnel(tunnel, path); 113 tunnelProvider.setupTunnel(tunnel, path);
104 114
...@@ -109,6 +119,8 @@ public class PcepTunnelProviderTest { ...@@ -109,6 +119,8 @@ public class PcepTunnelProviderTest {
109 public void tearDown() throws IOException { 119 public void tearDown() throws IOException {
110 tunnelProvider.deactivate(); 120 tunnelProvider.deactivate();
111 tunnelProvider.controller = null; 121 tunnelProvider.controller = null;
122 + tunnelProvider.deviceService = null;
123 + tunnelProvider.mastershipService = null;
112 tunnelProvider.pcepClientController = null; 124 tunnelProvider.pcepClientController = null;
113 tunnelProvider.tunnelProviderRegistry = null; 125 tunnelProvider.tunnelProviderRegistry = null;
114 } 126 }
......
...@@ -47,6 +47,10 @@ import org.onosproject.net.Link; ...@@ -47,6 +47,10 @@ import org.onosproject.net.Link;
47 import org.onosproject.net.Path; 47 import org.onosproject.net.Path;
48 import org.onosproject.net.PortNumber; 48 import org.onosproject.net.PortNumber;
49 import org.onosproject.net.provider.ProviderId; 49 import org.onosproject.net.provider.ProviderId;
50 +import org.onosproject.pcep.controller.ClientCapability;
51 +import org.onosproject.pcep.controller.LspKey;
52 +import org.onosproject.pcep.controller.PccId;
53 +import org.onosproject.pcepio.protocol.PcepVersion;
50 import org.onosproject.pcepio.types.StatefulIPv4LspIdentifiersTlv; 54 import org.onosproject.pcepio.types.StatefulIPv4LspIdentifiersTlv;
51 55
52 import static org.onosproject.provider.pcep.tunnel.impl.LspType.WITH_SIGNALLING; 56 import static org.onosproject.provider.pcep.tunnel.impl.LspType.WITH_SIGNALLING;
...@@ -99,7 +103,7 @@ public class PcepUpdateTunnelProviderTest { ...@@ -99,7 +103,7 @@ public class PcepUpdateTunnelProviderTest {
99 103
100 ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023)); 104 ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023));
101 105
102 - ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023)); 106 + ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10024));
103 107
104 Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst) 108 Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
105 .type(Link.Type.DIRECT).build(); 109 .type(Link.Type.DIRECT).build();
...@@ -108,6 +112,8 @@ public class PcepUpdateTunnelProviderTest { ...@@ -108,6 +112,8 @@ public class PcepUpdateTunnelProviderTest {
108 path = new DefaultPath(pid, links, 20, EMPTY); 112 path = new DefaultPath(pid, links, 20, EMPTY);
109 113
110 Annotations annotations = DefaultAnnotations.builder() 114 Annotations annotations = DefaultAnnotations.builder()
115 + .set(PcepAnnotationKeys.PLSP_ID, "1")
116 + .set(PcepAnnotationKeys.LOCAL_LSP_ID, "1")
111 .set(LSP_SIG_TYPE, WITH_SIGNALLING.name()) 117 .set(LSP_SIG_TYPE, WITH_SIGNALLING.name())
112 .build(); 118 .build();
113 119
...@@ -124,6 +130,12 @@ public class PcepUpdateTunnelProviderTest { ...@@ -124,6 +130,12 @@ public class PcepUpdateTunnelProviderTest {
124 130
125 tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData); 131 tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData);
126 132
133 + PccId pccId = PccId.pccId(IpAddress.valueOf(0xD010101));
134 + PcepClientAdapter pc = new PcepClientAdapter();
135 + pc.init(pccId, PcepVersion.PCEP_1);
136 + controller.getClient(pccId).setLspAndDelegationInfo(new LspKey(1, (short) 1), true);
137 + controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, true, true));
138 +
127 tunnelProvider.updateTunnel(tunnel, path); 139 tunnelProvider.updateTunnel(tunnel, path);
128 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue())); 140 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
129 } 141 }
...@@ -137,7 +149,7 @@ public class PcepUpdateTunnelProviderTest { ...@@ -137,7 +149,7 @@ public class PcepUpdateTunnelProviderTest {
137 Path path; 149 Path path;
138 ProviderId pid = new ProviderId("pcep", PROVIDER_ID); 150 ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
139 List<Link> links = new ArrayList<>(); 151 List<Link> links = new ArrayList<>();
140 - IpAddress srcIp = IpAddress.valueOf(0xC010103); 152 + IpAddress srcIp = IpAddress.valueOf(0xD010101);
141 IpElementId srcElementId = IpElementId.ipElement(srcIp); 153 IpElementId srcElementId = IpElementId.ipElement(srcIp);
142 154
143 IpAddress dstIp = IpAddress.valueOf(0xD010102); 155 IpAddress dstIp = IpAddress.valueOf(0xD010102);
...@@ -151,7 +163,7 @@ public class PcepUpdateTunnelProviderTest { ...@@ -151,7 +163,7 @@ public class PcepUpdateTunnelProviderTest {
151 163
152 ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023)); 164 ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023));
153 165
154 - ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023)); 166 + ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10024));
155 167
156 Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst) 168 Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
157 .type(Link.Type.DIRECT).build(); 169 .type(Link.Type.DIRECT).build();
...@@ -161,6 +173,8 @@ public class PcepUpdateTunnelProviderTest { ...@@ -161,6 +173,8 @@ public class PcepUpdateTunnelProviderTest {
161 173
162 Annotations annotations = DefaultAnnotations.builder() 174 Annotations annotations = DefaultAnnotations.builder()
163 .set(LSP_SIG_TYPE, WITH_SIGNALLING.name()) 175 .set(LSP_SIG_TYPE, WITH_SIGNALLING.name())
176 + .set(PcepAnnotationKeys.PLSP_ID, "1")
177 + .set(PcepAnnotationKeys.LOCAL_LSP_ID, "1")
164 .build(); 178 .build();
165 179
166 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS, 180 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
...@@ -176,6 +190,12 @@ public class PcepUpdateTunnelProviderTest { ...@@ -176,6 +190,12 @@ public class PcepUpdateTunnelProviderTest {
176 190
177 tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData); 191 tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData);
178 192
193 + PccId pccId = PccId.pccId(IpAddress.valueOf(0xD010101));
194 + PcepClientAdapter pc = new PcepClientAdapter();
195 + pc.init(pccId, PcepVersion.PCEP_1);
196 + controller.getClient(pccId).setLspAndDelegationInfo(new LspKey(1, (short) 1), true);
197 + controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, true, true));
198 +
179 tunnelProvider.updateTunnel(tunnel, path); 199 tunnelProvider.updateTunnel(tunnel, path);
180 assertThat(tunnelProvider.pcepTunnelApiMapper.checkFromTunnelRequestQueue(1), is(false)); 200 assertThat(tunnelProvider.pcepTunnelApiMapper.checkFromTunnelRequestQueue(1), is(false));
181 } 201 }
...@@ -203,7 +223,7 @@ public class PcepUpdateTunnelProviderTest { ...@@ -203,7 +223,7 @@ public class PcepUpdateTunnelProviderTest {
203 223
204 ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023)); 224 ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023));
205 225
206 - ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023)); 226 + ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10024));
207 227
208 Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst) 228 Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
209 .type(Link.Type.DIRECT).build(); 229 .type(Link.Type.DIRECT).build();
...@@ -213,6 +233,8 @@ public class PcepUpdateTunnelProviderTest { ...@@ -213,6 +233,8 @@ public class PcepUpdateTunnelProviderTest {
213 233
214 Annotations annotations = DefaultAnnotations.builder() 234 Annotations annotations = DefaultAnnotations.builder()
215 .set(LSP_SIG_TYPE, SR_WITHOUT_SIGNALLING.name()) 235 .set(LSP_SIG_TYPE, SR_WITHOUT_SIGNALLING.name())
236 + .set(PcepAnnotationKeys.PLSP_ID, "1")
237 + .set(PcepAnnotationKeys.LOCAL_LSP_ID, "1")
216 .build(); 238 .build();
217 239
218 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS, 240 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
...@@ -228,6 +250,12 @@ public class PcepUpdateTunnelProviderTest { ...@@ -228,6 +250,12 @@ public class PcepUpdateTunnelProviderTest {
228 250
229 tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData); 251 tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData);
230 252
253 + PccId pccId = PccId.pccId(IpAddress.valueOf(0xD010101));
254 + PcepClientAdapter pc = new PcepClientAdapter();
255 + pc.init(pccId, PcepVersion.PCEP_1);
256 + controller.getClient(pccId).setLspAndDelegationInfo(new LspKey(1, (short) 1), true);
257 + controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, true, true));
258 +
231 tunnelProvider.updateTunnel(tunnel, path); 259 tunnelProvider.updateTunnel(tunnel, path);
232 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue())); 260 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
233 } 261 }
...@@ -255,7 +283,7 @@ public class PcepUpdateTunnelProviderTest { ...@@ -255,7 +283,7 @@ public class PcepUpdateTunnelProviderTest {
255 283
256 ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023)); 284 ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023));
257 285
258 - ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023)); 286 + ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10024));
259 287
260 Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst) 288 Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
261 .type(Link.Type.DIRECT).build(); 289 .type(Link.Type.DIRECT).build();
...@@ -265,6 +293,8 @@ public class PcepUpdateTunnelProviderTest { ...@@ -265,6 +293,8 @@ public class PcepUpdateTunnelProviderTest {
265 293
266 Annotations annotations = DefaultAnnotations.builder() 294 Annotations annotations = DefaultAnnotations.builder()
267 .set(LSP_SIG_TYPE, WITHOUT_SIGNALLING_AND_WITHOUT_SR.name()) 295 .set(LSP_SIG_TYPE, WITHOUT_SIGNALLING_AND_WITHOUT_SR.name())
296 + .set(PcepAnnotationKeys.PLSP_ID, "1")
297 + .set(PcepAnnotationKeys.LOCAL_LSP_ID, "1")
268 .build(); 298 .build();
269 299
270 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS, 300 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
...@@ -280,6 +310,12 @@ public class PcepUpdateTunnelProviderTest { ...@@ -280,6 +310,12 @@ public class PcepUpdateTunnelProviderTest {
280 310
281 tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData); 311 tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData);
282 312
313 + PccId pccId = PccId.pccId(IpAddress.valueOf(0xD010101));
314 + PcepClientAdapter pc = new PcepClientAdapter();
315 + pc.init(pccId, PcepVersion.PCEP_1);
316 + controller.getClient(pccId).setLspAndDelegationInfo(new LspKey(1, (short) 1), true);
317 + controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, true, true));
318 +
283 tunnelProvider.updateTunnel(tunnel, path); 319 tunnelProvider.updateTunnel(tunnel, path);
284 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue())); 320 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
285 } 321 }
......