cheng fan
Committed by Gerrit Code Review

1. move tunnel 3 commands to onos-cli

2. add OCH ODU OMS port type;
3. fix some bugs in pcep tunnel provider and topology provider
4. Optimization of the command line tools of tunnel

Change-Id: I323ede971795c8fe6ecddc40e1061f42a8243867

fix tunnel provider bugs.

Change-Id: I323ede971795c8fe6ecddc40e1061f42a8243867
......@@ -48,13 +48,16 @@ public interface PcepLink extends PcepOperator {
}
public enum PortType {
ODU_PORT, OCH_PORT, OMS_PORT
}
/**
* Get the link endpoint port type.
*
* @return endpoint port type
*/
public String portType();
public PortType portType();
/**
* Get the link sub type,OTS,OPS,PKT_OPTICAL or ODUK.
......
......@@ -20,7 +20,7 @@ package org.onosproject.pcep.api;
*/
public interface PcepSwitch extends PcepOperator {
public static enum SubDeviceType {
public static enum DeviceType {
/* optical device */
ROADM,
......@@ -52,7 +52,7 @@ public interface PcepSwitch extends PcepOperator {
* Gets the sub type of the device.
* @return the sub type
*/
public SubDeviceType getDeviceSubType();
public DeviceType getDeviceType();
/**
* fetch the manufacturer description.
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.provider.tunnel.cli;
package org.onosproject.cli.net;
import java.util.Optional;
......@@ -64,11 +64,11 @@ public class TunnelCreateCommand extends AbstractShellCommand {
String type = null;
@Option(name = "-g", aliases = "--groupId",
description = "Group flow table id which a tunnel match up", required = false, multiValued = false)
String groupId = null;
String groupId = "0";
@Option(name = "-n", aliases = "--tunnelName",
description = "The name of tunnels", required = false, multiValued = false)
String tunnelName = null;
String tunnelName = "onos";
@Option(name = "-b", aliases = "--bandwidth",
description = "The bandwidth attribute of tunnel", required = false, multiValued = false)
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.provider.tunnel.cli;
package org.onosproject.cli.net;
import java.util.Optional;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.provider.tunnel.cli;
package org.onosproject.cli.net;
import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
......
......@@ -380,6 +380,15 @@
<command>
<action class="org.onosproject.cli.net.TunnelQuerySubscriptionCommand"/>
</command>
<command>
<action class="org.onosproject.cli.net.TunnelCreateCommand"/>
</command>
<command>
<action class="org.onosproject.cli.net.TunnelRemoveCommand"/>
</command>
<command>
<action class="org.onosproject.cli.net.TunnelUpdateCommand"/>
</command>
</command-bundle>
<bean id="permAppNameCompleter" class="org.onosproject.cli.security.PermissionApplicationNameCompleter"/>
......
......@@ -15,6 +15,10 @@
*/
package org.onosproject.provider.pcep.topology.impl;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.onosproject.net.DeviceId.deviceId;
import static org.onosproject.pcep.api.PcepDpid.uri;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
......@@ -27,7 +31,6 @@ 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;
......@@ -57,6 +60,7 @@ 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.PcepLink.PortType;
import org.onosproject.pcep.api.PcepLinkListener;
import org.onosproject.pcep.api.PcepOperator.OperationType;
import org.onosproject.pcep.api.PcepSwitch;
......@@ -64,10 +68,6 @@ 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.
......@@ -130,7 +130,7 @@ public class PcepTopologyProvider extends AbstractProvider
}
private List<PortDescription> buildPortDescriptions(List<Long> ports,
String portType) {
PortType portType) {
final List<PortDescription> portDescs = new ArrayList<>();
for (long port : ports) {
portDescs.add(buildPortDescription(port, portType));
......@@ -138,11 +138,11 @@ public class PcepTopologyProvider extends AbstractProvider
return portDescs;
}
private PortDescription buildPortDescription(long port, String portType) {
private PortDescription buildPortDescription(long port, PortType portType) {
final PortNumber portNo = PortNumber.portNumber(port);
final boolean enabled = true;
DefaultAnnotations extendedAttributes = DefaultAnnotations.builder()
.set("portType", portType).build();
.set("portType", String.valueOf(portType)).build();
return new DefaultPortDescription(portNo, enabled, extendedAttributes);
}
......@@ -246,14 +246,22 @@ public class PcepTopologyProvider extends AbstractProvider
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.Type deviceType = null;
// Device subType: ROADM,OTN,ROUTER.
DefaultAnnotations extendedAttributes = DefaultAnnotations
.builder()
.set("subType", String.valueOf(sw.getDeviceSubType()))
.build();
switch (sw.getDeviceType()) {
case ROADM:
deviceType = Device.Type.ROADM;
break;
case OTN:
deviceType = Device.Type.SWITCH;
break;
case ROUTER:
deviceType = Device.Type.ROUTER;
break;
default:
deviceType = Device.Type.OTHER;
}
DeviceDescription description = new DefaultDeviceDescription(
devicdId.uri(),
......@@ -262,12 +270,7 @@ public class PcepTopologyProvider extends AbstractProvider
sw.hardwareDescription(),
sw.softwareDescription(),
sw.serialNumber(),
cId,
extendedAttributes);
NodeId localNode = clusterService.getLocalNode().id();
mastershipAdminService.setRole(localNode, devicdId,
MastershipRole.MASTER);
mastershipService.relinquishMastership(devicdId);
cId);
deviceProviderService.deviceConnected(devicdId, description);
}
......@@ -322,19 +325,15 @@ public class PcepTopologyProvider extends AbstractProvider
@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;
return true;
}
}
......
......@@ -78,6 +78,7 @@ public class PcepTunnelProvider extends AbstractProvider
private static final Logger log = getLogger(PcepTunnelProvider.class);
private static final long MAX_BANDWIDTH = 99999744;
private static final long MIN_BANDWIDTH = 64;
private static final String BANDWIDTH_UINT = "kbps";
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.";
......@@ -154,10 +155,11 @@ public class PcepTunnelProvider extends AbstractProvider
@Override
public TunnelId tunnelAdded(TunnelDescription tunnel) {
long bandwidth = Long.parseLong(tunnel.annotations().value("bandWith"));
long bandwidth = Long
.parseLong(tunnel.annotations().value("bandwidth"));
if (bandwidth < MIN_BANDWIDTH || bandwidth > MAX_BANDWIDTH) {
System.out.println("Update failed, invalid bandwidth.");
error("Update failed, invalid bandwidth.");
return null;
}
......@@ -175,8 +177,7 @@ public class PcepTunnelProvider extends AbstractProvider
// type
if (tunnel.type() != Tunnel.Type.VLAN) {
System.out
.println("Llegal tunnel type. Only support VLAN tunnel creation.");
error("Illegal tunnel type. Only support VLAN tunnel creation.");
return null;
}
......@@ -198,18 +199,17 @@ public class PcepTunnelProvider extends AbstractProvider
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.");
error("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.");
if (!controller.deleteTunnel(pcepTunnelId)) {
error("Delete tunnel failed, Maybe some devices have been disconnected.");
return;
}
tunnelMap.remove(pcepTunnelId);
service.tunnelRemoved(tunnel);
}
@Override
......@@ -217,13 +217,13 @@ public class PcepTunnelProvider extends AbstractProvider
Tunnel tunnelOld = tunnelQueryById(tunnel.id());
if (tunnelOld.type() != Tunnel.Type.VLAN) {
System.out
.println("Llegal tunnel type. Only support VLAN tunnel update.");
error("Llegal tunnel type. Only support VLAN tunnel update.");
return;
}
long bandwidth = Long.parseLong(tunnel.annotations().value("bandWith"));
long bandwidth = Long
.parseLong(tunnel.annotations().value("bandwidth"));
if (bandwidth < MIN_BANDWIDTH || bandwidth > MAX_BANDWIDTH) {
System.out.println("Update failed, invalid bandwidth.");
error("Update failed, invalid bandwidth.");
return;
}
String pcepTunnelId = getPCEPTunnelKey(tunnel.id());
......@@ -231,13 +231,17 @@ public class PcepTunnelProvider extends AbstractProvider
checkNotNull(pcepTunnelId, "Invalid tunnel id");
if (!controller.updateTunnelBandwidth(pcepTunnelId, bandwidth)) {
System.out.println("Update failed,maybe invalid bandwidth.");
error("Update failed,maybe invalid bandwidth.");
return;
}
service.tunnelUpdated(tunnel);
}
private void error(String info) {
System.err.println(info);
}
// Short-hand for creating a connection point.
private ConnectPoint connectPoint(PcepDpid id, long port) {
return new ConnectPoint(deviceId(uri(id)), portNumber(port));
......@@ -334,22 +338,13 @@ public class PcepTunnelProvider extends AbstractProvider
true);
// basic annotations
DefaultAnnotations annotations = DefaultAnnotations.builder()
.set("bandWith", String.valueOf(pcepTunnel.bandWidth()))
DefaultAnnotations annotations = DefaultAnnotations
.builder()
.set("SLA", String.valueOf(pcepTunnel.getSla()))
.set("bandwidth",
String.valueOf(pcepTunnel.bandWidth()) + BANDWIDTH_UINT)
.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) {
......
......@@ -37,7 +37,6 @@
<module>host</module>
<module>netconf</module>
<module>null</module>
<module>tunnel</module>
<module>pcep</module>
</modules>
......
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<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/maven-v4_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-tunnel-provider</artifactId>
<packaging>bundle</packaging>
<description>tunnel southbound providers</description>
<properties>
<onos.app.name>org.onosproject.tunnel</onos.app.name>
</properties>
<dependencies>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
</dependency>
<dependency>
<groupId>org.apache.karaf.shell</groupId>
<artifactId>org.apache.karaf.shell.console</artifactId>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-cli</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-api</artifactId>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
</dependencies>
</project>
/*
* 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.tunnel;
import static org.slf4j.LoggerFactory.getLogger;
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.cfg.ComponentConfigService;
import org.onosproject.net.ElementId;
import org.onosproject.net.Path;
import org.onosproject.net.provider.AbstractProvider;
import org.onosproject.net.provider.ProviderId;
import org.onosproject.incubator.net.tunnel.Tunnel;
import org.onosproject.incubator.net.tunnel.TunnelDescription;
import org.onosproject.incubator.net.tunnel.TunnelId;
import org.onosproject.incubator.net.tunnel.TunnelProvider;
import org.onosproject.incubator.net.tunnel.TunnelProviderRegistry;
import org.onosproject.incubator.net.tunnel.TunnelProviderService;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
/**
* Provider of a fake network environment, i.e. devices, links, hosts, etc. To
* be used for benchmarking only.
*/
@Component(immediate = true)
@Service
public class DefaultTunnelProvider extends AbstractProvider
implements TunnelProvider {
private static final Logger log = getLogger(DefaultTunnelProvider.class);
static final String PROVIDER_ID = "org.onosproject.provider.tunnel.default";
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected ComponentConfigService cfgService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected TunnelProviderRegistry tunnelProviderRegistry;
TunnelProviderService service;
/**
* Creates a Tunnel provider.
*/
public DefaultTunnelProvider() {
super(new ProviderId("default", PROVIDER_ID));
}
@Activate
public void activate(ComponentContext context) {
service = tunnelProviderRegistry.register(this);
log.info("Started");
}
@Deactivate
public void deactivate(ComponentContext context) {
tunnelProviderRegistry.unregister(this);
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) {
return service.tunnelAdded(tunnel);
}
@Override
public void tunnelRemoved(TunnelDescription tunnel) {
service.tunnelRemoved(tunnel);
}
@Override
public void tunnelUpdated(TunnelDescription tunnel) {
service.tunnelUpdated(tunnel);
}
@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.
*/
/**
* Null provider CLI commands and completers.
*/
package org.onosproject.provider.tunnel.cli;
/*
* 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.
*/
/**
* Set of null south-bound providers which permit simulating a network
* topology using fake devices, links, hosts, etc.
*/
package org.onosproject.provider.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.
-->
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
<command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
<command>
<action class="org.onosproject.provider.tunnel.cli.TunnelCreateCommand"/>
</command>
<command>
<action class="org.onosproject.provider.tunnel.cli.TunnelRemoveCommand"/>
</command>
<command>
<action class="org.onosproject.provider.tunnel.cli.TunnelUpdateCommand"/>
</command>
</command-bundle>
</blueprint>