Phanendra Manda
Committed by Gerrit Code Review

[ONOS-2287,ONOS-2288]Pcep TunnelProvider implementation

Change-Id: I4184336c200f1060e93be5dc28076ba35f6b98f4
......@@ -85,6 +85,23 @@ public class ConnectPoint {
}
/**
* Returns the identifier of the infrastructure device if the connection
* point belongs to a network element which is indeed an ip of pcc
* client identifier.
*
* @return network element identifier as a pcc client identifier
* @throws java.lang.IllegalStateException if connection point is not
* associated with a pcc client
*/
public IpElementId ipElementId() {
if (elementId instanceof IpElementId) {
return (IpElementId) elementId;
}
throw new IllegalStateException("Connection point not associated " +
"with an pcc client");
}
/**
* Returns the connection port number.
*
* @return port number
......
package org.onosproject.net;
import java.util.Objects;
import org.onlab.packet.IpAddress;
import com.google.common.base.MoreObjects;
/**
* Represent for a Element ID using ip address.
*/
public final class IpElementId extends ElementId {
private final IpAddress ipAddress;
/**
* Public construction is prohibited.
* @param ipAddress ip address
*/
private IpElementId(IpAddress ipAddress) {
this.ipAddress = ipAddress;
}
/**
* Create a IP Element ID.
* @param ipAddress IP address
* @return IpElementId
*/
public static IpElementId ipElement(IpAddress ipAddress) {
return new IpElementId(ipAddress);
}
/**
* Returns the ip address.
*
* @return ipAddress
*/
public IpAddress ipAddress() {
return ipAddress;
}
@Override
public int hashCode() {
return Objects.hash(ipAddress);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof IpElementId) {
final IpElementId other = (IpElementId) obj;
return Objects.equals(this.ipAddress, other.ipAddress);
}
return false;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass()).add("ipAddress", ipAddress).toString();
}
}
......@@ -220,5 +220,4 @@ public class PcepFactoryVer1 implements PcepFactory {
public PcepLabelRangeResvMsg.Builder buildPcepLabelRangeResvMsg() {
return new PcepLabelRangeResvMsgVer1.Builder();
}
}
......
......@@ -15,5 +15,9 @@
<groupId>org.onosproject</groupId>
<artifactId>onos-app-pcep-api</artifactId>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-pcep-controller-api</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.provider.pcep.tunnel.impl;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.collections.map.MultiKeyMap;
import org.onosproject.incubator.net.tunnel.TunnelId;
import org.onosproject.incubator.net.tunnel.TunnelProviderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Entity to provide tunnel DB and mapping for request/response between CORE to PCEP
* and PCEP to PCC.
*/
public class PcepTunnelApiMapper {
protected static final Logger log = LoggerFactory.getLogger(PcepTunnelApiMapper.class);
static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep";
// Map to store all the tunnel requests.
private Map<Integer, PcepTunnelData> tunnelRequestQueue;
//Map to store all core related tunnel requests.
private Map<TunnelId, PcepTunnelData> coreTunnelRequestQueue;
//Map to store all the created tunnels.
private Map<Integer, PcepTunnelData> tunnelDB;
// Map to store the tunnel ids, given by core and given by pcc.
private Map<TunnelId, Integer> tunnelIdMap;
//Map to store all the learnt tunnels.
private MultiKeyMap pccTunnelDB = new MultiKeyMap();
TunnelProviderService tunnelApiMapperservice;
/**
* Default constructor.
*/
public PcepTunnelApiMapper() {
//TODO check if the map need to initialize
tunnelRequestQueue = new HashMap<Integer, PcepTunnelData>();
coreTunnelRequestQueue = new HashMap<TunnelId, PcepTunnelData>();
tunnelDB = new HashMap<Integer, PcepTunnelData>();
tunnelIdMap = new HashMap<TunnelId, Integer>();
}
/**
* Add tunnels to tunnel Request queues.
*
* @param srpId srp id
* @param pcepTunnelData pcep tunnel data
*/
public void addToTunnelRequestQueue(int srpId, PcepTunnelData pcepTunnelData) {
tunnelRequestQueue.put(new Integer(srpId), pcepTunnelData);
log.debug("Tunnel Added to TunnelRequestQueue");
}
/**
* Map between Tunnel ID and pcc provided Tunnel ID.
*
* @param pcepTunnelData pcep tunnel data
*/
public void addToTunnelIdMap(PcepTunnelData pcepTunnelData) {
int value = pcepTunnelData.statefulIpv4IndentifierTlv().getTunnelId() & 0xFFFF;
tunnelIdMap.put(pcepTunnelData.tunnel().tunnelId(), (new Integer(value)));
log.debug("Tunnel ID Added to tunnelIdMap");
}
/**
* Add tunnels to core tunnel request queue.
*
* @param pcepTunnelData pcep tunnel data
*/
public void addToCoreTunnelRequestQueue(PcepTunnelData pcepTunnelData) {
coreTunnelRequestQueue.put(pcepTunnelData.tunnel().tunnelId(), pcepTunnelData);
log.debug("Tunnel Added to CoreTunnelRequestQueue");
}
/**
* Removes tunnels from the core tunnel request queue.
*
* @param tunnelId tunnel id
*/
public void removeFromCoreTunnelRequestQueue(TunnelId tunnelId) {
coreTunnelRequestQueue.remove(tunnelId);
log.debug("Tunnnel create response sent to core and removed from CoreTunnelRequestQueue");
}
/**
* Handle the report which comes after initiate message.
*
* @param srpId srp id
* @param pcepTunnelData pcep tunnel data
*/
public void handleCreateTunnelRequestQueue(int srpId, PcepTunnelData pcepTunnelData) {
int value = tunnelIdMap.get(pcepTunnelData.tunnel().tunnelId());
tunnelDB.put(new Integer(value), pcepTunnelData);
tunnelRequestQueue.remove(new Integer(srpId), pcepTunnelData);
log.debug("Tunnel Added to TunnelDBQueue and removed from TunnelRequestQueue. tunnel id {}"
+ (new Integer(value)).toString());
}
/**
* Handle report which comes for update message.
*
* @param srpId srp id
* @param pcepTunnelData pcep tunnel data
*/
public void handleUpdateTunnelRequestQueue(int srpId, PcepTunnelData pcepTunnelData) {
if (pcepTunnelData.rptFlag()) {
pcepTunnelData.setRptFlag(false);
int value = tunnelIdMap.get(pcepTunnelData.tunnel().tunnelId());
tunnelDB.put(new Integer(value), pcepTunnelData);
tunnelRequestQueue.remove(new Integer(srpId), pcepTunnelData);
log.debug("Tunnel Added to TunnelDBQueue and removed from TunnelRequestQueue. tunnel id {}" ,
(new Integer(value)).toString());
} else {
pcepTunnelData.setRptFlag(true);
tunnelRequestQueue.put(new Integer(srpId), pcepTunnelData);
log.debug("Tunnel updated in TunnelRequestQueue");
}
}
/**
* Handle report for tunnel Release request.
*
* @param srpId srp id
* @param pcepTunnelData pcep tunnel data
*/
public void handleRemoveFromTunnelRequestQueue(int srpId, PcepTunnelData pcepTunnelData) {
int value = tunnelIdMap.get(pcepTunnelData.tunnel().tunnelId());
tunnelIdMap.remove(pcepTunnelData.tunnel().tunnelId());
tunnelDB.remove(new Integer(value));
tunnelRequestQueue.remove(srpId);
log.debug("Tunnel removed from TunnelDBQueue and TunnelRequestQueue");
}
/**
* Returns PcepTunnelData from the tunnel request queue.
*
* @param srpId srp id
* @return PcepTunnelData pcep tunnel data
*/
public PcepTunnelData getDataFromTunnelRequestQueue(int srpId) {
return tunnelRequestQueue.get(new Integer(srpId));
}
/**
* Returns PcepTunnelData from the tunnel DB.
*
* @param tunnelId tunnel id
* @return PcepTunnelData pcep tunnel data
*/
public PcepTunnelData getDataFromTunnelDBQueue(TunnelId tunnelId) {
int value = tunnelIdMap.get(tunnelId);
return tunnelDB.get((new Integer(value)));
}
/**
* Checks whether the tunnel exist in tunnel request queue.
*
* @param srpId srp id
* @return true if tunnel exist in reuest queue, false otherwise
*/
public boolean checkFromTunnelRequestQueue(int srpId) {
boolean retValue = tunnelRequestQueue.containsKey(srpId);
return retValue;
}
/**
* Returns whether tunnel exist in tunnel db.
*
* @param tunnelId
* @return true/false
*/
public boolean checkFromTunnelDBQueue(TunnelId tunnelId) {
int value = tunnelIdMap.get(tunnelId);
boolean retValue = tunnelDB.containsKey((new Integer(value)));
return retValue;
}
/**
* Add Learnt tunnels to pcc tunnel DB.
*
* @param pcepTunnelData pcep tunnel data
*/
public void addPccTunnelDB(PcepTunnelData pcepTunnelData) {
pccTunnelDB.put(pcepTunnelData.statefulIpv4IndentifierTlv().getTunnelId() & 0xFFFFL,
pcepTunnelData.statefulIpv4IndentifierTlv().getIpv4IngressAddress(), pcepTunnelData);
}
}
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.provider.pcep.tunnel.impl;
import java.util.Objects;
import org.onosproject.incubator.net.tunnel.Tunnel;
import org.onosproject.net.ElementId;
import org.onosproject.net.Path;
import org.onosproject.pcepio.types.StatefulIPv4LspIdentidiersTlv;
import com.google.common.base.MoreObjects;
/**
* To store all tunnel related information from Core and Path computation client.
*/
public class PcepTunnelData {
private Tunnel tunnel;
private Path path;
private int plspId;
private ElementId elementId;
private RequestType requestType;
private boolean rptFlag;
// data need to store from LSP object
private boolean lspAFlag;
private boolean lspDFlag;
private byte lspOFlag;
private short tunnelId;
private int extTunnelId;
private short lspId;
private StatefulIPv4LspIdentidiersTlv statefulIpv4IndentifierTlv;
/**
* Default constructor.
*/
public PcepTunnelData() {
this.elementId = null;
this.tunnel = null;
this.path = null;
this.requestType = null;
this.rptFlag = false;
this.plspId = 0;
}
/**
* Constructor to initialize Tunnel, Path and Request type.
*
* @param tunnel mpls tunnel
* @param path Path in network
* @param requestType request type for tunnel
*/
public PcepTunnelData(Tunnel tunnel, Path path, RequestType requestType) {
this.tunnel = tunnel;
this.path = path;
this.requestType = requestType;
}
/**
* Constructor to initialize ElemendId, Tunnel, Path and Request type.
*
* @param elementId Ip element id
* @param tunnel mpls tunnel
* @param path Path in network
* @param requestType request type for tunnel
*/
public PcepTunnelData(ElementId elementId, Tunnel tunnel, Path path, RequestType requestType) {
this.elementId = elementId;
this.tunnel = tunnel;
this.path = path;
this.requestType = requestType;
}
/**
* Constructor to initialize Tunnel and Request type.
*
* @param tunnel Tunnel from core
* @param requestType request type for tunnel
*/
public PcepTunnelData(Tunnel tunnel, RequestType requestType) {
this.tunnel = tunnel;
this.requestType = requestType;
}
/**
* Constructor to initialize ElementId, Tunnel and Request type.
*
* @param elementId Ip element id
* @param tunnel mpls tunnel
* @param requestType request type for tunnel
*/
public PcepTunnelData(ElementId elementId, Tunnel tunnel, RequestType requestType) {
this.elementId = elementId;
this.tunnel = tunnel;
this.requestType = requestType;
}
/**
* Sets ip element id.
*
* @param elementId Ip element id
*/
public void setElementId(ElementId elementId) {
this.elementId = elementId;
}
/**
* Sets tunnel.
*
* @param tunnel mpls tunnel
*/
public void setTunnel(Tunnel tunnel) {
this.tunnel = tunnel;
}
/**
* Sets Path.
*
* @param path Path in network
*/
public void setPath(Path path) {
this.path = path;
}
/**
* Request type for tunnel.
*
* @param requestType request type for tunnel
*/
public void setRequestType(RequestType requestType) {
this.requestType = requestType;
}
/**
* Sets plspid generated from pcc.
*
* @param plspId plsp identifier
*/
public void setPlspId(int plspId) {
this.plspId = plspId;
}
/**
* Sets A flag from lsp object.
*
* @param value A flag value
*/
public void setLspAFlag(boolean value) {
this.lspAFlag = value;
}
/**
* Sets OF flag from lsp object.
*
* @param value OF flag value
*/
public void setLspOFlag(byte value) {
this.lspOFlag = value;
}
/**
* Sets tunnel id from PCC.
*
* @param value tunnel id value
*/
public void setTunnelId(short value) {
this.tunnelId = value;
}
/**
* Sets extended tunnel id from PCC.
*
* @param value extended tunnel id value
*/
public void setExtTunnelId(int value) {
this.extTunnelId = value;
}
/**
* Sets lsp id from pcc.
*
* @param value lsp id
*/
public void setLspId(short value) {
this.lspId = value;
}
/**
* Sets statefulIpv4Identifiers tlv.
* @param value statefulIpv4Identifiers tlv
*/
public void setStatefulIpv4IndentifierTlv(StatefulIPv4LspIdentidiersTlv value) {
this.statefulIpv4IndentifierTlv = value;
}
/**
* Sets report flag.
*
* @param rptFlag report flag
*/
public void setRptFlag(boolean rptFlag) {
this.rptFlag = rptFlag;
}
/**
* Sets D flag from lsp object.
*
* @param value D flag value
*/
public void setLspDFlag(boolean value) {
this.lspDFlag = value;
}
/**
* To get Ip element id.
*
* @return Ip elemend id
*/
public ElementId elementId() {
return this.elementId;
}
/**
* To get Tunnel.
*
* @return tunnel
*/
public Tunnel tunnel() {
return this.tunnel;
}
/**
* To get Path.
*
* @return path
*/
public Path path() {
return this.path;
}
/**
* To get request type.
*
* @return request type
*/
public RequestType requestType() {
return this.requestType;
}
/**
* To get pLspId.
*
* @return pLspId
*/
public int plspId() {
return this.plspId;
}
/**
* To get A flag.
*
* @return A flag
*/
public boolean lspAFlag() {
return this.lspAFlag;
}
/**
* To get OF flag.
*
* @return OF flag
*/
public byte lspOFlag() {
return this.lspOFlag;
}
/**
* To get tunnel id.
*
* @return tunnel id
*/
public short tunnelId() {
return this.tunnelId;
}
/**
* To get extended tunnel id.
*
* @return extended tunnel id
*/
public int extTunnelId() {
return this.extTunnelId;
}
/**
* To get pLspId.
*
* @return pLspId
*/
public short lspId() {
return this.lspId;
}
/**
* To get D Flag.
*
* @return d flag
*/
public boolean lspDFlag() {
return this.lspDFlag;
}
/**
* To get statefulIpv4Indentifier tlv.
*
* @return statefulIpv4Indentifier tlv
*/
public StatefulIPv4LspIdentidiersTlv statefulIpv4IndentifierTlv() {
return this.statefulIpv4IndentifierTlv;
}
/**
* To get report flag.
*
* @return report flag
*/
public boolean rptFlag() {
return this.rptFlag;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof PcepTunnelData) {
PcepTunnelData other = (PcepTunnelData) obj;
return Objects.equals(tunnel, other.tunnel)
&& Objects.equals(path, other.path)
&& Objects.equals(plspId, other.plspId)
&& Objects.equals(elementId, other.elementId)
&& Objects.equals(requestType, other.requestType)
&& Objects.equals(rptFlag, other.rptFlag)
&& Objects.equals(lspAFlag, other.lspAFlag)
&& Objects.equals(lspDFlag, other.lspDFlag)
&& Objects.equals(lspOFlag, other.lspOFlag)
&& Objects.equals(tunnelId, other.tunnelId)
&& Objects.equals(extTunnelId, other.extTunnelId)
&& Objects.equals(lspId, other.lspId)
&& Objects.equals(statefulIpv4IndentifierTlv, other.statefulIpv4IndentifierTlv);
}
return false;
}
@Override
public int hashCode() {
return Objects.hash(tunnel, path, plspId, elementId, requestType, rptFlag, lspAFlag,
lspDFlag, lspOFlag, tunnelId, extTunnelId, lspId, statefulIpv4IndentifierTlv);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass()).add("Tunnel", tunnel)
.add("Path", path).add("PlspId", plspId).add("ElementId", elementId)
.add("RequestType", requestType).add("RptFlag", rptFlag).add("LspAFlag", lspAFlag)
.add("LspDFlag", lspDFlag).add("LspOFlag", lspOFlag).add("TunnelId", tunnelId)
.add("ExtTunnelid", extTunnelId).add("LspId", lspId)
.add("StatefulIpv4IndentifierTlv", statefulIpv4IndentifierTlv).toString();
}
}
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.provider.pcep.tunnel.impl;
/**
* Enum of request types between pcc and pcep.
*/
public enum RequestType {
/**
* Specifies the request type for PCC is to create new tunnel.
*/
CREATE,
/**
* Specifies the request type for PCC is to update existing tunnel.
*/
UPDATE,
/**
* Specifies the request type for PCC is to delete existing tunnel.
*/
DELETE,
/**
* Specifies the request type for PCC to report existing tunnel.
*/
LSP_STATE_RPT;
}
\ No newline at end of file
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.provider.pcep.tunnel.impl;
import static org.slf4j.LoggerFactory.getLogger;
import java.util.concurrent.atomic.AtomicInteger;
import org.slf4j.Logger;
/**
* Unique Srp Id generator for pcep messages.
*/
public final class SrpIdGenerators {
private static final Logger log = getLogger(SrpIdGenerators.class);
private static final AtomicInteger SRP_ID_GEN = new AtomicInteger();
private static final int MAX_SRP_ID = 0x7FFFFFFF;
private static int srpId;
/**
* Default constructor.
*/
private SrpIdGenerators() {
}
/**
* Get the next srp id.
*
* @return srp id
*/
public static int create() {
do {
if (srpId >= MAX_SRP_ID) {
if (SRP_ID_GEN.get() >= MAX_SRP_ID) {
SRP_ID_GEN.set(0);
}
}
srpId = SRP_ID_GEN.incrementAndGet();
} while (srpId > MAX_SRP_ID);
return srpId;
}
}