cheng fan
Committed by Gerrit Code Review

[ONOS-1925]

1.fix javadocs bugs.
2.add pcep tunnel provider;
3.change pcep to pcep app;
4.fix some bugs according to review suggestions.

Change-Id: I4b90d9bf871dee3be70615d66db3d74f2fd85389
Showing 27 changed files with 1963 additions and 0 deletions
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onos-apps</artifactId>
<version>1.2.0-SNAPSHOT</version>
</parent>
<artifactId>onos-app-pcep-api</artifactId>
<packaging>bundle</packaging>
</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.pcep.api;
import org.onosproject.net.DeviceId;
/**
* Abstraction of an PCEP controller. Serves as a one stop shop for obtaining
* PCEP devices and (un)register listeners on PCEP events
*/
public interface PcepController {
/**
* Returns all switches known to this PCEP controller.
*
* @return Iterable of did elements
*/
public Iterable<PcepSwitch> getSwitches();
/**
* Return a switch with a specified did.
*
* @param did of a device
* @return a pcep device
*/
public PcepSwitch getSwitch(PcepDpid did);
/**
* Register a listener for meta events that occur to PCEP devices.
*
* @param listener the listener to notify
*/
public void addListener(PcepSwitchListener listener);
/**
* Unregister a listener.
*
* @param listener the listener to unregister
*/
public void removeListener(PcepSwitchListener listener);
/**
* Register a listener for meta events that occur to PCEP links.
*
* @param listener the listener to notify
*/
public void addLinkListener(PcepLinkListener listener);
/**
* Unregister a link listener.
*
* @param listener the listener to unregister
*/
public void removeLinkListener(PcepLinkListener listener);
/**
* Register a listener for meta events that occur to PCEP tunnel.
*
* @param listener the listener to notify
*/
public void addTunnelListener(PcepTunnelListener listener);
/**
* Unregister a tunnel listener.
*
* @param listener the listener to unregister
*/
public void removeTunnelListener(PcepTunnelListener listener);
/**
* Setup a tunnel through pcep controller.
*
* @param srcDid src deviceId of tunnel
* @param dstDid dst deviceId of tunnel
* @param srcPort src port
* @param dstPort dst port
* @param bandwidth andwidth of tunnel
* @param name tunnel name
* @return pcep tunnel
*/
public PcepTunnel applyTunnel(DeviceId srcDid, DeviceId dstDid,
long srcPort, long dstPort, long bandwidth,
String name);
/**
* Delete tunnel by id.
*
* @param id pcep tunnel id.
* @return true or false
*/
public Boolean deleteTunnel(String id);
/**
* Update tunnel bandwidth by tunnel id.
*
* @param id tunnel id
* @param bandwidth bandwidth of a tunnel
* @return true or false
*/
public Boolean updateTunnelBandwidth(String id, long bandwidth);
}
/*
* Copyright 2014 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.pcep.api;
import java.net.URI;
import java.net.URISyntaxException;
import org.onosproject.pcep.tools.PcepTools;
/**
* The class representing a network switch PCEPDid. This class is immutable.
*/
public final class PcepDpid {
private static final String SCHEME = "pcep";
private static final long UNKNOWN = 0;
private long nodeId;
/**
* Default constructor.
*/
public PcepDpid() {
this.nodeId = PcepDpid.UNKNOWN;
}
/**
* Constructor from a long value.
*
* @param value long value for construct
*/
public PcepDpid(long value) {
this.nodeId = value;
}
/**
* Constructor from a String.
*
* @param value string value for construct
*/
public PcepDpid(String value) {
this.nodeId = Long.parseLong(value, 16);
}
/**
* Produces device URI from the given DPID.
*
* @param dpid device dpid
* @return device URI
*/
public static URI uri(PcepDpid dpid) {
return uri(dpid.nodeId);
}
/**
* Produces device long from the given string which comes from the uri
* method.
*
* @param value string value which produced by uri method.
* @return a long value.
*/
public static long toLong(String value) {
return PcepTools.ipToLong(value.replace(SCHEME, ""));
}
/**
* Produces device URI from the given DPID long.
*
* @param value device dpid as long
* @return device URI
*/
public static URI uri(long value) {
try {
return new URI(SCHEME, PcepTools.longToIp(value), null);
} catch (URISyntaxException e) {
return null;
}
}
/**
* Return a device id with the form of long.
*
* @return long value
*/
public long value() {
return this.nodeId;
}
}
/*
* 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.pcep.api;
/**
* Description of a pcep tunnel hop node.a hop list consists of a number of hop
* node.
*/
public class PcepHopNodeDescription {
private PcepDpid deviceId;
private long portNum;
/**
* Get the pcepdpid of a node.
*
* @return device pcepdpid.
*/
public PcepDpid getDeviceId() {
return deviceId;
}
/**
* Set the pcepdpid of a node.
*
* @param deviceId pcep dpid of a node.
*/
public void setDeviceId(PcepDpid deviceId) {
this.deviceId = deviceId;
}
/**
* Get the port number of a node.
*
* @return port number.
*/
public long getPortNum() {
return portNum;
}
/**
* Set the port number of a node.
*
* @param portNum port number of a node.
*/
public void setPortNum(long portNum) {
this.portNum = portNum;
}
}
/*
* 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.pcep.api;
/**
* Abstraction of a huawei network infrastructure link.
*/
public interface PcepLink extends PcepOperator {
public enum SubType {
/**
* Optical Transmission Section Link.
*/
OTS,
/**
* Optical Physical Section Link.
*/
OPS,
/**
* User-to-Network Interface Link.
*/
UNI,
/**
* Optical channel Data Unit-k link.
*/
ODUk,
/**
* Optical Transport Network link.
*/
OTU,
}
/**
* Get the link endpoint port type.
*
* @return endpoint port type
*/
public String portType();
/**
* Get the link sub type,OTS,OPS,PKT_OPTICAL or ODUK.
*
* @return link subType
*/
public SubType linkSubType();
/**
* Get the link state, up or down.
*
* @return link state
*/
public String linkState();
/**
* Get the distance of a link.
*
* @return distance
*/
public int linkDistance();
/**
* Get the capacity type of a link,1: WAVELENGTHNUM, 2:SLOTNUM, 3,
* BANDWIDTH.
*
* @return capacity type
*/
public String linkCapacityType();
/**
* Get the available capacity value ,such as available bandwidth.
*
* @return availValue
*/
public int linkAvailValue();
/**
* Get the max capacity value ,such as max bandwidth.
*
* @return maxValue
*/
public int linkMaxValue();
/**
* Get the source device did of a link.
*
* @return source did
*/
public PcepDpid linkSrcDeviceID();
/**
* Get the destination device did of a link.
*
* @return destination did
*/
public PcepDpid linkDstDeviceId();
/**
* Get the source port number of a link,the port consists of shelf id, sub
* card id, board id, and port id of a Huawei Device.
*
* @return port number
*/
public long linkSrcPort();
/**
* Get the destination port number of a link,the port consists of shelf id,
* sub card id, board id, and port id of a Huawei Device.
*
* @return port number
*/
public long linkDstPort();
}
/*
* 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.pcep.api;
/**
* Allows for providers interested in Link events to be notified.
*/
public interface PcepLinkListener {
/**
* Notify that get a packet of link from network and need do some
* processing.
*
* @param link pcep link
*/
public void handlePCEPlink(PcepLink link);
}
/*
* 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.pcep.api;
/**
* A interface defined operator type, and provide a method to get the operator
* type.
*
*/
public interface PcepOperator {
public enum OperationType {
ADD, UPDATE, DELETE,
}
/**
* Get operate type of a event,such as device add ,device update.
*
* @return operation type.
*/
public OperationType getOperationType();
}
/*
* 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.pcep.api;
/*
* Represent to provider facing side of a switch
*/
public interface PcepSwitch extends PcepOperator {
public static enum SubDeviceType {
/* optical device */
ROADM,
/* electronic device */
OTN,
/* router */
ROUTER,
/* unkown type */
UNKNOW,
}
/**
* Gets a string version of the ID for this switch.
* @return string version of the ID
*/
public String getStringId();
/**
* Gets the datapathId of the switch.
* @return the switch dpid in long format
*/
public long getId();
public long getNeId();
/**
* Gets the sub type of the device.
* @return the sub type
*/
public SubDeviceType getDeviceSubType();
/**
* fetch the manufacturer description.
* @return the description
*/
public String manufacturerDescription();
/**
* fetch the datapath description.
* @return the description
*/
public String datapathDescription();
/**
* fetch the hardware description.
* @return the description
*/
public String hardwareDescription();
/**
* fetch the software description.
* @return the description
*/
public String softwareDescription();
/**
* fetch the serial number.
* @return the serial
*/
public String serialNumber();
/**
* Indicates if this switch is optical.
* @return true if optical
*/
public boolean isOptical();
}
/*
* 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.pcep.api;
/**
* Notifies providers about switch in events.
*/
public interface PcepSwitchListener {
/**
* Notify that the switch was added.
*
* @param dpid the switch where the event occurred
*/
public void switchAdded(PcepDpid dpid);
/**
* Notify that the switch was removed.
*
* @param dpid the switch where the event occurred.
*/
public void switchRemoved(PcepDpid dpid);
/**
* Notify that the switch has changed in some way.
*
* @param dpid the switch that changed
*/
public void switchChanged(PcepDpid dpid);
}
/*
* 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.pcep.api;
import java.util.List;
/**
* Abstraction of a generalized PCEP Tunnel entity (bandwidth pipe) for
* L2 networks or L1/L0 networks, representation of e.g., VLAN, L1 ODUk
* connection, WDM OCH, etc..
*/
public interface PcepTunnel extends PcepOperator {
/**
* Describe the type of a tunnel.
*/
public static enum Type {
/**
* Signifies that this is a L0 OCH tunnel.
*/
OCH,
/**
* Signifies that this is a L1 OTN tunnel.
*/
OTN,
/**
* Signifies that this is a L2 tunnel.
*/
UNI,
}
/**
* The ability of a tunnel.
*/
public static enum Ability {
/**
* no protected tunnel,if the tunnel is broken ,then the user is out of
* service.
*/
NOPROTECTED,
/**
* tunnel with rerouter ability.if a tunnel is broken, the tunnel will
* try to find another path to provider service.
*/
SILVER,
/**
* tunnel with 1 + 1 rerouter ability.if a tunnel is broken, there'll be
* another tunnel providing service at once.
*/
DIAMOND
}
public static enum PATHTYPE {
/**
* the preferred path.
*/
FIRST,
/**
* the alternate path.
*/
SECOND
}
/**
* Get the type of a tunnel.
*
* @return tunnel type
*/
public Type type();
/**
* Get the name of a tunnel.
*
* @return tunnel name
*/
public String name();
/**
* Get the device id of destination endpoint of a tunnel.
*
* @return device id
*/
public PcepDpid srcDeviceID();
/**
* Get the device id of source endpoint of a tunnel.
*
* @return device id
*/
public PcepDpid dstDeviceId();
/**
* Get source port of a tunnel.
*
* @return port number
*/
public long srcPort();
/**
* Get destination port of a tunnel.
*
* @return port number
*/
public long dstPort();
/**
* Get the bandwidth of a tunnel.
*
* @return bandwidth
*/
public long bandWidth();
/**
* Get the tunnel id.
*
* @return id of the PCEP tunnel
*/
public long id();
/**
* Get the detail hop list of a tunnel.
*
* @return hop list
*/
public List<PcepHopNodeDescription> getHopList();
/**
* Get the instance of a pcep tunnel,a instance is used to mark the times of a tunnel created.
* instance and id identify a tunnel together.
*
* @return the instance of a tunnel.
*/
public int getInstance();
/**
* Get the ability of a tunnel.NOPROTECTED,SILVER,or DIAMOND.
*
* @return ability of the tunenl
*/
public Ability getSla();
/**
* Get the path type of a path if the tunnel's ability is diamond .
*
* @return the type of a path, the preferred or alternate.
*/
public PATHTYPE getPathType();
/**
* Get the under lay tunnel id of VLAN tunnel.
*
* @return the tunnel id of a OCH tunnel under lay of a VLAN tunnel.
*/
public long underLayTunnelId();
}
/*
* 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.pcep.api;
/**
* Allows for providers interested in tunnel events to be notified.
*/
public interface PcepTunnelListener {
/**
* Notify that get a packet of tunnel from network and need do some
* processing.
*
* @param tunnel a pceptunnel.
*/
public void handlePCEPTunnel(PcepTunnel tunnel);
}
/*
* 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.
*/
/**
* PCEP controller API.
*/
package org.onosproject.pcep.api;
\ 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.pcep.tools;
import javax.xml.bind.DatatypeConverter;
/**
* tools fo pcep app.
*/
public abstract class PcepTools {
private PcepTools() {
}
/**
* Converts decimal byte array to a hex string.
*
* @param byteArray byte array
* @return a hex string
*/
public static String toHexString(byte[] byteArray) {
return DatatypeConverter.printHexBinary(byteArray);
}
/**
* Converts a hex string to a decimal byte array.
*
* @param hexString a hex string
* @return byte array
*/
public static byte[] toByteArray(String hexString) {
return DatatypeConverter.parseHexBinary(hexString);
}
/**
* Converts a byte array to a decimal string.
*
* @param bytes a byte array
* @return a decimal string
*/
public static String toDecimalString(byte[] bytes) {
String str = "";
for (int i = 0; i < bytes.length; i++) {
str += String.valueOf(bytes[i]);
}
return str;
}
/**
* convert a string to the form of ip address.
*
* @param str a string
* @return a string with ip format
*/
public static String stringToIp(String str) {
long ipInt = Long.parseLong(str, 16);
return longToIp(ipInt);
}
/**
* convert a long to ip format.
*
* @param ipLong a decimal number.
* @return a ip format string
*/
public static String longToIp(long ipLong) {
StringBuilder sb = new StringBuilder();
sb.append((ipLong >> 24) & 0xFF).append(".");
sb.append((ipLong >> 16) & 0xFF).append(".");
sb.append((ipLong >> 8) & 0xFF).append(".");
sb.append(ipLong & 0xFF);
return sb.toString();
}
/**
* convert a string with ip format to a long.
*
* @param strIp a string with ip format
* @return a long number
*/
public static long ipToLong(String strIp) {
long[] ip = new long[4];
int position1 = strIp.indexOf(".");
int position2 = strIp.indexOf(".", position1 + 1);
int position3 = strIp.indexOf(".", position2 + 1);
ip[0] = Long.parseLong(strIp.substring(0, position1));
ip[1] = Long.parseLong(strIp.substring(position1 + 1, position2));
ip[2] = Long.parseLong(strIp.substring(position2 + 1, position3));
ip[3] = Long.parseLong(strIp.substring(position3 + 1));
return (ip[0] << 24) + (ip[1] << 16) + (ip[2] << 8) + ip[3];
}
/**
* get a integer value from a cut string.
*
* @param str a whole string
* @param base cut the string from this index
* @param offset the offset when execute the cut
* @return a integer value
*/
public static int tranferHexStringToInt(String str, int base, int offset) {
return Integer.parseInt(str.substring(base, offset), 16);
}
}
/*
* 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.
*/
/**
* tools for pcep app.
*/
package org.onosproject.pcep.tools;
\ No newline at end of file
......@@ -49,6 +49,7 @@
<module>segmentrouting</module>
<module>cordfabric</module>
<module>xos-integration</module>
<module>pcep-api</module>
</modules>
<properties>
......
......@@ -387,6 +387,11 @@
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-app-pcep-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onlab-thirdparty</artifactId>
<version>${project.version}</version>
</dependency>
......
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<app name="org.onosproject.pcep" origin="ON.Lab" version="${project.version}"
featuresRepo="mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features"
features="${project.artifactId}">
<description>${project.description}</description>
<artifact>mvn:${project.groupId}/onos-app-pcep-api/${project.version}</artifact>
<artifact>mvn:${project.groupId}/onos-pcep-provider-topology/${project.version}</artifact>
<artifact>mvn:${project.groupId}/onos-pcep-provider-tunnel/${project.version}</artifact>
</app>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!--
~ 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.
-->
<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}">
<repository>mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features</repository>
<feature name="${project.artifactId}" version="${project.version}"
description="${project.description}">
<feature>onos-api</feature>
<bundle>mvn:${project.groupId}/onos-app-pcep-api/${project.version}</bundle>
<bundle>mvn:${project.groupId}/onos-pcep-provider-topology/${project.version}</bundle>
<bundle>mvn:${project.groupId}/onos-pcep-provider-tunnel/${project.version}</bundle>
</feature>
</features>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onos-pcep-providers</artifactId>
<version>1.2.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>onos-pcep</artifactId>
<packaging>pom</packaging>
<dependencies>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-app-pcep-api</artifactId>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-pcep-provider-topology</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-pcep-provider-tunnel</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onos-providers</artifactId>
<version>1.2.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>onos-pcep-providers</artifactId>
<packaging>pom</packaging>
<modules>
<module>topology</module>
<module>tunnel</module>
<module>app</module>
</modules>
</project>
\ No newline at end of file
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onos-pcep-providers</artifactId>
<version>1.2.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>onos-pcep-provider-topology</artifactId>
<packaging>bundle</packaging>
<dependencies>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-app-pcep-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.topology.impl;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onlab.packet.ChassisId;
import org.onosproject.cluster.ClusterService;
import org.onosproject.cluster.NodeId;
import org.onosproject.mastership.MastershipAdminService;
import org.onosproject.mastership.MastershipService;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DefaultAnnotations;
import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Link;
import org.onosproject.net.Link.Type;
import org.onosproject.net.MastershipRole;
import org.onosproject.net.PortNumber;
import org.onosproject.net.device.DefaultDeviceDescription;
import org.onosproject.net.device.DefaultPortDescription;
import org.onosproject.net.device.DeviceDescription;
import org.onosproject.net.device.DeviceProvider;
import org.onosproject.net.device.DeviceProviderRegistry;
import org.onosproject.net.device.DeviceProviderService;
import org.onosproject.net.device.DeviceService;
import org.onosproject.net.device.PortDescription;
import org.onosproject.net.link.DefaultLinkDescription;
import org.onosproject.net.link.LinkDescription;
import org.onosproject.net.link.LinkProvider;
import org.onosproject.net.link.LinkProviderRegistry;
import org.onosproject.net.link.LinkProviderService;
import org.onosproject.net.link.LinkService;
import org.onosproject.net.provider.AbstractProvider;
import org.onosproject.net.provider.ProviderId;
import org.onosproject.pcep.api.PcepController;
import org.onosproject.pcep.api.PcepDpid;
import org.onosproject.pcep.api.PcepLink;
import org.onosproject.pcep.api.PcepLinkListener;
import org.onosproject.pcep.api.PcepOperator.OperationType;
import org.onosproject.pcep.api.PcepSwitch;
import org.onosproject.pcep.api.PcepSwitchListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.onosproject.net.DeviceId.deviceId;
import static org.onosproject.pcep.api.PcepDpid.uri;
/**
* Provider which uses an PCEP controller to detect network infrastructure
* topology.
*/
@Component(immediate = true)
public class PcepTopologyProvider extends AbstractProvider
implements LinkProvider, DeviceProvider {
public PcepTopologyProvider() {
super(new ProviderId("pcep", "org.onosproject.provider.pcep"));
}
private static final Logger log = LoggerFactory
.getLogger(PcepTopologyProvider.class);
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected LinkProviderRegistry linkProviderRegistry;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected DeviceProviderRegistry deviceProviderRegistry;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected PcepController controller;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected DeviceService deviceService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected LinkService linkService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected MastershipAdminService mastershipAdminService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected MastershipService mastershipService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected ClusterService clusterService;
private DeviceProviderService deviceProviderService;
private LinkProviderService linkProviderService;
// List<Long> srcportList = new ArrayList<Long>();
HashSet<Long> portSet = new HashSet<>();
private InternalLinkProvider listener = new InternalLinkProvider();
@Activate
public void activate() {
linkProviderService = linkProviderRegistry.register(this);
deviceProviderService = deviceProviderRegistry.register(this);
controller.addListener(listener);
controller.addLinkListener(listener);
}
@Deactivate
public void deactivate() {
linkProviderRegistry.unregister(this);
linkProviderService = null;
controller.removeListener(listener);
controller.removeLinkListener(listener);
}
private List<PortDescription> buildPortDescriptions(List<Long> ports,
String portType) {
final List<PortDescription> portDescs = new ArrayList<>();
for (long port : ports) {
portDescs.add(buildPortDescription(port, portType));
}
return portDescs;
}
private PortDescription buildPortDescription(long port, String portType) {
final PortNumber portNo = PortNumber.portNumber(port);
final boolean enabled = true;
DefaultAnnotations extendedAttributes = DefaultAnnotations.builder()
.set("portType", portType).build();
return new DefaultPortDescription(portNo, enabled, extendedAttributes);
}
/**
* Build link annotations from pcep link description.the annotations consist
* of lots of property of Huawei device.
*
* @param linkDesc
* @return
*/
private DefaultAnnotations buildLinkAnnotations(PcepLink linkDesc) {
DefaultAnnotations extendedAttributes = DefaultAnnotations
.builder()
.set("subType", String.valueOf(linkDesc.linkSubType()))
.set("workState", linkDesc.linkState())
.set("distance", String.valueOf(linkDesc.linkDistance()))
.set("capType", linkDesc.linkCapacityType().toLowerCase())
.set("avail_" + linkDesc.linkCapacityType().toLowerCase(),
String.valueOf(linkDesc.linkAvailValue()))
.set("max_" + linkDesc.linkCapacityType().toLowerCase(),
String.valueOf(linkDesc.linkMaxValue())).build();
return extendedAttributes;
}
/**
* Build a LinkDescription from a PCEPLink.
*
* @param pceLink
* @return LinkDescription
*/
private LinkDescription buildLinkDescription(PcepLink pceLink) {
LinkDescription ld;
DeviceId srcDeviceID = deviceId(uri(pceLink.linkSrcDeviceID()));
DeviceId dstDeviceID = deviceId(uri(pceLink.linkDstDeviceId()));
if (deviceService.getDevice(srcDeviceID) == null
|| deviceService.getDevice(dstDeviceID) == null) {
log.info("the device of the link is not exited" + srcDeviceID
+ dstDeviceID);
return null;
}
// update port info
long srcPort = pceLink.linkSrcPort();
portSet.add(srcPort);
List<Long> srcportList = new ArrayList<Long>();
srcportList.addAll(portSet);
deviceProviderService
.updatePorts(srcDeviceID,
buildPortDescriptions(srcportList,
pceLink.portType()));
ConnectPoint src = new ConnectPoint(srcDeviceID,
PortNumber.portNumber(pceLink
.linkSrcPort()));
ConnectPoint dst = new ConnectPoint(dstDeviceID,
PortNumber.portNumber(pceLink
.linkDstPort()));
DefaultAnnotations extendedAttributes = buildLinkAnnotations(pceLink);
// construct the link
ld = new DefaultLinkDescription(src, dst, Type.OPTICAL,
extendedAttributes);
return ld;
}
private void processLinkUpdate(LinkDescription linkDescription) {
// dst changed, delete the original link,if the dst device is not in
// other links ,delete it.
if (linkService.getLink(linkDescription.src(), linkDescription.dst()) == null) {
// in face,one src one link
Set<Link> links = linkService
.getIngressLinks(linkDescription.src());
for (Link link : links) {
linkProviderService.linkVanished((LinkDescription) link);
if (linkService.getDeviceLinks(link.dst().deviceId()).size() == 0) {
deviceProviderService.deviceDisconnected(link.dst()
.deviceId());
}
}
}
linkProviderService.linkDetected(linkDescription);
}
private class InternalLinkProvider
implements PcepSwitchListener, PcepLinkListener {
@Override
public void switchAdded(PcepDpid dpid) {
// TODO Auto-generated method stub
if (deviceProviderService == null) {
return;
}
DeviceId devicdId = deviceId(uri(dpid));
PcepSwitch sw = controller.getSwitch(dpid);
checkNotNull(sw, "device should not null.");
// The default device type is switch.
Device.Type deviceType = Device.Type.SWITCH;
ChassisId cId = new ChassisId(dpid.value());
// Device subType: ROADM,OTN,ROUTER.
DefaultAnnotations extendedAttributes = DefaultAnnotations
.builder()
.set("subType", String.valueOf(sw.getDeviceSubType()))
.build();
DeviceDescription description = new DefaultDeviceDescription(
devicdId.uri(),
deviceType,
sw.manufacturerDescription(),
sw.hardwareDescription(),
sw.softwareDescription(),
sw.serialNumber(),
cId,
extendedAttributes);
NodeId localNode = clusterService.getLocalNode().id();
mastershipAdminService.setRole(localNode, devicdId,
MastershipRole.MASTER);
mastershipService.relinquishMastership(devicdId);
deviceProviderService.deviceConnected(devicdId, description);
}
@Override
public void switchRemoved(PcepDpid dpid) {
// TODO Auto-generated method stub
if (deviceProviderService == null || linkProviderService == null) {
return;
}
deviceProviderService.deviceDisconnected(deviceId(uri(dpid)));
linkProviderService.linksVanished(DeviceId.deviceId(uri(dpid)));
}
@Override
public void switchChanged(PcepDpid dpid) {
// TODO Auto-generated method stub
}
@Override
public void handlePCEPlink(PcepLink link) {
OperationType operType = link.getOperationType();
LinkDescription ld = buildLinkDescription(link);
if (ld == null) {
log.error("Invalid link info.");
return;
}
switch (operType) {
case ADD:
linkProviderService.linkDetected(ld);
break;
case UPDATE:
processLinkUpdate(ld);
break;
case DELETE:
linkProviderService.linkVanished(ld);
break;
default:
break;
}
}
}
@Override
public void triggerProbe(DeviceId deviceId) {
// TODO Auto-generated method stub
}
@Override
public void roleChanged(DeviceId deviceId, MastershipRole newRole) {
// NodeId localNode = clusterService.getLocalNode().id();
// mastershipService.setRole(localNode, deviceId, newRole);
}
@Override
public boolean isReachable(DeviceId deviceId) {
// TODO Auto-generated method stub
return false;
}
}
/*
* 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.
*/
/**
*Provider that uses PCEP controller as a means of infrastructure topology discovery.
*/
package org.onosproject.provider.pcep.topology.impl;
\ No newline at end of file
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onos-pcep-providers</artifactId>
<version>1.2.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>onos-pcep-provider-tunnel</artifactId>
<packaging>bundle</packaging>
<dependencies>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-app-pcep-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 static com.google.common.base.Preconditions.checkNotNull;
import static org.onosproject.net.DeviceId.deviceId;
import static org.onosproject.net.PortNumber.portNumber;
import static org.slf4j.LoggerFactory.getLogger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Optional;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.onosproject.core.DefaultGroupId;
import org.onosproject.incubator.net.tunnel.DefaultOpticalTunnelEndPoint;
import org.onosproject.incubator.net.tunnel.DefaultTunnelDescription;
import org.onosproject.incubator.net.tunnel.OpticalLogicId;
import org.onosproject.incubator.net.tunnel.OpticalTunnelEndPoint;
import org.onosproject.incubator.net.tunnel.Tunnel;
import org.onosproject.incubator.net.tunnel.TunnelDescription;
import org.onosproject.incubator.net.tunnel.TunnelEndPoint;
import org.onosproject.incubator.net.tunnel.TunnelId;
import org.onosproject.incubator.net.tunnel.TunnelName;
import org.onosproject.incubator.net.tunnel.TunnelProvider;
import org.onosproject.incubator.net.tunnel.TunnelProviderRegistry;
import org.onosproject.incubator.net.tunnel.TunnelProviderService;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DefaultAnnotations;
import org.onosproject.net.DefaultLink;
import org.onosproject.net.DefaultPath;
import org.onosproject.net.DeviceId;
import org.onosproject.net.ElementId;
import org.onosproject.net.Link;
import org.onosproject.net.Path;
import org.onosproject.net.PortNumber;
import org.onosproject.net.provider.AbstractProvider;
import org.onosproject.net.provider.ProviderId;
import org.onosproject.pcep.api.PcepController;
import org.onosproject.pcep.api.PcepDpid;
import org.onosproject.pcep.api.PcepHopNodeDescription;
import org.onosproject.pcep.api.PcepOperator.OperationType;
import org.onosproject.pcep.api.PcepTunnel;
import org.onosproject.pcep.api.PcepTunnel.PATHTYPE;
import org.onosproject.pcep.api.PcepTunnelListener;
import org.slf4j.Logger;
import static org.onosproject.pcep.api.PcepDpid.*;
/**
* Provider which uses an PCEP controller to detect, update, create network
* tunnels.
*/
@Component(immediate = true)
@Service
public class PcepTunnelProvider extends AbstractProvider
implements TunnelProvider {
private static final Logger log = getLogger(PcepTunnelProvider.class);
private static final long MAX_BANDWIDTH = 99999744;
private static final long MIN_BANDWIDTH = 64;
static final String PROVIDER_ID = "org.onosproject.provider.tunnel.default";
private static final String TUNNLE_NOT_NULL = "Create failed,The given port may be wrong or has been occupied.";
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected TunnelProviderRegistry tunnelProviderRegistry;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected PcepController controller;
TunnelProviderService service;
HashMap<String, TunnelId> tunnelMap = new HashMap<String, TunnelId>();
private InnerTunnerProvider listener = new InnerTunnerProvider();
/**
* Creates a Tunnel provider.
*/
public PcepTunnelProvider() {
super(new ProviderId("default", PROVIDER_ID));
}
@Activate
public void activate() {
service = tunnelProviderRegistry.register(this);
controller.addTunnelListener(listener);
log.info("Started");
}
@Deactivate
public void deactivate() {
tunnelProviderRegistry.unregister(this);
controller.removeTunnelListener(listener);
log.info("Stopped");
}
@Override
public void setupTunnel(Tunnel tunnel, Path path) {
// TODO Auto-generated method stub
}
@Override
public void setupTunnel(ElementId srcElement, Tunnel tunnel, Path path) {
// TODO Auto-generated method stub
}
@Override
public void releaseTunnel(Tunnel tunnel) {
// TODO Auto-generated method stub
}
@Override
public void releaseTunnel(ElementId srcElement, Tunnel tunnel) {
// TODO Auto-generated method stub
}
@Override
public void updateTunnel(Tunnel tunnel, Path path) {
// TODO Auto-generated method stub
}
@Override
public void updateTunnel(ElementId srcElement, Tunnel tunnel, Path path) {
// TODO Auto-generated method stub
}
@Override
public TunnelId tunnelAdded(TunnelDescription tunnel) {
long bandwidth = Long.parseLong(tunnel.annotations().value("bandWith"));
if (bandwidth < MIN_BANDWIDTH || bandwidth > MAX_BANDWIDTH) {
System.out.println("Update failed, invalid bandwidth.");
return null;
}
// endpoints
OpticalTunnelEndPoint src = (org.onosproject.incubator.net.tunnel.OpticalTunnelEndPoint) tunnel
.src();
OpticalTunnelEndPoint dst = (OpticalTunnelEndPoint) tunnel.dst();
// devices
DeviceId srcId = (DeviceId) src.elementId().get();
DeviceId dstId = (DeviceId) dst.elementId().get();
// ports
long srcPort = src.portNumber().get().toLong();
long dstPort = dst.portNumber().get().toLong();
// type
if (tunnel.type() != Tunnel.Type.VLAN) {
System.out
.println("Llegal tunnel type. Only support VLAN tunnel creation.");
return null;
}
PcepTunnel pcepTunnel = controller.applyTunnel(srcId, dstId, srcPort,
dstPort, bandwidth,
tunnel.tunnelName()
.value());
checkNotNull(pcepTunnel, TUNNLE_NOT_NULL);
TunnelDescription tunnelAdded = buildOpticalTunnel(pcepTunnel, null);
TunnelId tunnelId = service.tunnelAdded(tunnelAdded);
tunnelMap.put(String.valueOf(pcepTunnel.id()), tunnelId);
return tunnelId;
}
@Override
public void tunnelRemoved(TunnelDescription tunnel) {
Tunnel tunnelOld = tunnelQueryById(tunnel.id());
checkNotNull(tunnelOld, "The tunnel id is not exsited.");
if (tunnelOld.type() != Tunnel.Type.VLAN) {
System.out
.println("Llegal tunnel type. Only support VLAN tunnel deletion.");
return;
}
String pcepTunnelId = getPCEPTunnelKey(tunnel.id());
checkNotNull(pcepTunnelId, "The tunnel id is not exsited.");
if (controller.deleteTunnel(pcepTunnelId)) {
log.info("delete tunnel:" + pcepTunnelId + "ok.");
}
tunnelMap.remove(pcepTunnelId);
service.tunnelRemoved(tunnel);
}
@Override
public void tunnelUpdated(TunnelDescription tunnel) {
Tunnel tunnelOld = tunnelQueryById(tunnel.id());
if (tunnelOld.type() != Tunnel.Type.VLAN) {
System.out
.println("Llegal tunnel type. Only support VLAN tunnel update.");
return;
}
long bandwidth = Long.parseLong(tunnel.annotations().value("bandWith"));
if (bandwidth < MIN_BANDWIDTH || bandwidth > MAX_BANDWIDTH) {
System.out.println("Update failed, invalid bandwidth.");
return;
}
String pcepTunnelId = getPCEPTunnelKey(tunnel.id());
checkNotNull(pcepTunnelId, "Invalid tunnel id");
if (!controller.updateTunnelBandwidth(pcepTunnelId, bandwidth)) {
System.out.println("Update failed,maybe invalid bandwidth.");
return;
}
service.tunnelUpdated(tunnel);
}
// Short-hand for creating a connection point.
private ConnectPoint connectPoint(PcepDpid id, long port) {
return new ConnectPoint(deviceId(uri(id)), portNumber(port));
}
// Short-hand for creating a link.
private Link link(PcepDpid src, long sp, PcepDpid dst, long dp) {
return new DefaultLink(id(), connectPoint(src, sp), connectPoint(dst,
dp),
Link.Type.TUNNEL);
}
// Creates a path that leads through the given devices.
private Path createPath(List<PcepHopNodeDescription> hopList,
PATHTYPE pathtype) {
if (hopList == null || hopList.size() == 0) {
return null;
}
List<Link> links = new ArrayList<>();
for (int i = 1; i < hopList.size() - 1; i = i + 2) {
links.add(link(hopList.get(i).getDeviceId(), hopList.get(i)
.getPortNum(), hopList.get(i + 1).getDeviceId(), hopList
.get(i + 1).getPortNum()));
}
int hopNum = hopList.size() - 2;
DefaultAnnotations extendAnnotations = DefaultAnnotations.builder()
.set("pathNum", String.valueOf(hopNum))
.set("pathType", String.valueOf(pathtype)).build();
return new DefaultPath(id(), links, hopNum, extendAnnotations);
}
// convert the path description to a string.
public String pathToString(List<Link> links) {
StringBuilder builder = new StringBuilder();
builder.append("{");
for (Link link : links) {
builder.append("(Device:" + link.src().deviceId() + " Port:"
+ link.src().port().toLong());
builder.append(" Device:" + link.dst().deviceId() + " Port:"
+ link.dst().port().toLong());
builder.append(")");
}
builder.append("}");
return builder.toString();
}
// build a TunnelDescription.
private TunnelDescription buildOpticalTunnel(PcepTunnel pcepTunnel,
TunnelId tunnelId) {
TunnelEndPoint srcPoint = null;
TunnelEndPoint dstPoint = null;
Tunnel.Type tunnelType = null;
TunnelName name = TunnelName.tunnelName(pcepTunnel.name());
// add path after codes of tunnel's path merged
Path path = createPath(pcepTunnel.getHopList(),
pcepTunnel.getPathType());
OpticalTunnelEndPoint.Type endPointType = null;
switch (pcepTunnel.type()) {
case OCH:
tunnelType = Tunnel.Type.OCH;
endPointType = OpticalTunnelEndPoint.Type.LAMBDA;
break;
case OTN:
tunnelType = Tunnel.Type.ODUK;
endPointType = OpticalTunnelEndPoint.Type.TIMESLOT;
break;
case UNI:
tunnelType = Tunnel.Type.VLAN;
endPointType = null;
break;
default:
break;
}
DeviceId srcDid = deviceId(uri(pcepTunnel.srcDeviceID()));
DeviceId dstDid = deviceId(uri(pcepTunnel.dstDeviceId()));
PortNumber srcPort = PortNumber.portNumber(pcepTunnel.srcPort());
PortNumber dstPort = PortNumber.portNumber(pcepTunnel.dstPort());
srcPoint = new DefaultOpticalTunnelEndPoint(id(), Optional.of(srcDid),
Optional.of(srcPort), null,
endPointType,
OpticalLogicId.logicId(0),
true);
dstPoint = new DefaultOpticalTunnelEndPoint(id(), Optional.of(dstDid),
Optional.of(dstPort), null,
endPointType,
OpticalLogicId.logicId(0),
true);
// basic annotations
DefaultAnnotations annotations = DefaultAnnotations.builder()
.set("bandWith", String.valueOf(pcepTunnel.bandWidth()))
.set("SLA", String.valueOf(pcepTunnel.getSla()))
.set("index", String.valueOf(pcepTunnel.id())).build();
// if (path != null) {
//
// DefaultAnnotations extendAnnotations = DefaultAnnotations.builder()
// .set("pathNum", String.valueOf(hopNum))
// // .set("path", pathString)
// .set("pathType", String.valueOf(pcepTunnel.getPathType()))
// .build();
// annotations = DefaultAnnotations.merge(annotations,
// extendAnnotations);
// }
// a VLAN tunnel always carry OCH tunnel, this annotation is the index
// of a OCH tunnel.
if (pcepTunnel.underLayTunnelId() != 0) {
DefaultAnnotations extendAnnotations = DefaultAnnotations
.builder()
.set("underLayTunnelIndex",
String.valueOf(pcepTunnel.underLayTunnelId())).build();
annotations = DefaultAnnotations.merge(annotations,
extendAnnotations);
}
TunnelDescription tunnel = new DefaultTunnelDescription(
tunnelId,
srcPoint,
dstPoint,
tunnelType,
new DefaultGroupId(
0),
id(), name,
path,
annotations);
return tunnel;
}
/**
* Get the tunnelID according to the tunnel key.
*
* @param tunnelKey tunnel key
* @return corresponding tunnel id of the a tunnel key.
*/
private TunnelId getTunnelId(String tunnelKey) {
for (String key : tunnelMap.keySet()) {
if (key.equals(tunnelKey)) {
return tunnelMap.get(key);
}
}
return null;
}
/**
* Get the tunnel key according to the tunnelID.
*
* @param tunnelId tunnel id
* @return corresponding a tunnel key of the tunnel id.
*/
private String getPCEPTunnelKey(TunnelId tunnelId) {
for (String key : tunnelMap.keySet()) {
if (tunnelMap.get(key).id() == tunnelId.id()) {
return key;
}
}
return null;
}
private class InnerTunnerProvider implements PcepTunnelListener {
@Override
public void handlePCEPTunnel(PcepTunnel pcepTunnel) {
TunnelDescription tunnel = null;
// instance and id identify a tunnel together
String tunnelKey = String.valueOf(pcepTunnel.getInstance())
+ String.valueOf(pcepTunnel.id());
if (tunnelKey == null || "".equals(tunnelKey)) {
log.error("Invalid PCEP tunnel");
return;
}
TunnelId tunnelId = getTunnelId(tunnelKey);
tunnel = buildOpticalTunnel(pcepTunnel, tunnelId);
OperationType operType = pcepTunnel.getOperationType();
switch (operType) {
case ADD:
tunnelId = service.tunnelAdded(tunnel);
tunnelMap.put(tunnelKey, tunnelId);
break;
case UPDATE:
service.tunnelUpdated(tunnel);
break;
case DELETE:
service.tunnelRemoved(tunnel);
tunnelMap.remove(tunnelKey);
break;
default:
log.error("Invalid tunnel operation");
}
}
}
@Override
public Tunnel tunnelQueryById(TunnelId tunnelId) {
return service.tunnelQueryById(tunnelId);
}
}
/*
* 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.
*/
/**
*Provider that uses PCEP controller as a means of infrastructure tunnel discovery.
*/
package org.onosproject.provider.pcep.tunnel.impl;
\ No newline at end of file
......@@ -38,6 +38,7 @@
<module>netconf</module>
<module>null</module>
<module>tunnel</module>
<module>pcep</module>
</modules>
<dependencies>
......