Jonathan Hart
Committed by Gerrit Code Review

Remove old CordFabric app

Change-Id: Id8b22f3ab78adae6f09e94f54ec15bc743459cb2
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2015-2016 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/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>onos-apps</artifactId>
<groupId>org.onosproject</groupId>
<version>1.6.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>onos-app-cordfabric</artifactId>
<packaging>bundle</packaging>
<description>Simple fabric application for CORD</description>
<properties>
<onos.app.name>org.onosproject.cordfabric</onos.app.name>
<onos.app.title>CORD Fabric App</onos.app.title>
<onos.app.category>Traffic Steering</onos.app.category>
<onos.app.url>http://onosproject.org</onos.app.url>
<onos.app.readme>Simple fabric application for CORD.</onos.app.readme>
<web.context>/onos/cordfabric</web.context>
<api.version>1.0.0</api.version>
<api.title>ONOS CORD Fabric REST API</api.title>
<api.description>
APIs for interacting with the CORD Fabric application.
</api.description>
<api.package>org.onosproject.cordfabric</api.package>
</properties>
<dependencies>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-cli</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.karaf.shell</groupId>
<artifactId>org.apache.karaf.shell.console</artifactId>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-rest</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onlab-rest</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<_wab>src/main/webapp/</_wab>
<Include-Resource>
WEB-INF/classes/apidoc/swagger.json=target/swagger.json,
{maven-resources}
</Include-Resource>
<Bundle-SymbolicName>
${project.groupId}.${project.artifactId}
</Bundle-SymbolicName>
<Import-Package>
org.slf4j,
org.osgi.framework,
javax.ws.rs,
javax.ws.rs.core,
org.glassfish.jersey,
org.glassfish.jersey.servlet,
com.fasterxml.jackson.databind,
com.fasterxml.jackson.databind.node,
org.apache.karaf.shell.commands,
com.google.common.*,
org.onlab.packet.*,
org.onosproject.*,
</Import-Package>
<Web-ContextPath>${web.context}</Web-ContextPath>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
</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.cordfabric;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
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.onlab.packet.Ethernet;
import org.onlab.packet.IPv4;
import org.onlab.packet.MacAddress;
import org.onlab.packet.TpPort;
import org.onlab.packet.VlanId;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.PortNumber;
import org.onosproject.net.device.DeviceEvent;
import org.onosproject.net.device.DeviceListener;
import org.onosproject.net.device.DeviceService;
import org.onosproject.net.flow.DefaultTrafficSelector;
import org.onosproject.net.flow.DefaultTrafficTreatment;
import org.onosproject.net.flow.TrafficSelector;
import org.onosproject.net.flow.TrafficTreatment;
import org.onosproject.net.flowobjective.DefaultForwardingObjective;
import org.onosproject.net.flowobjective.FlowObjectiveService;
import org.onosproject.net.flowobjective.ForwardingObjective;
import org.onosproject.net.flowobjective.Objective;
import org.onosproject.net.flowobjective.ObjectiveContext;
import org.onosproject.net.flowobjective.ObjectiveError;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.slf4j.LoggerFactory.getLogger;
/**
* CORD fabric application.
*/
@Service
@Component(immediate = true)
public class CordFabricManager implements FabricService {
private final Logger log = getLogger(getClass());
private ApplicationId appId;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected CoreService coreService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected FlowObjectiveService flowObjectiveService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected DeviceService deviceService;
private InternalDeviceListener deviceListener = new InternalDeviceListener();
private static final int PRIORITY = 50000;
private static final int TESTPRIO = 49999;
private short radiusPort = 1812;
private short ofPort = 6653;
private DeviceId fabricDeviceId = DeviceId.deviceId("of:5e3e486e73000187");
private final Multimap<VlanId, ConnectPoint> vlans = HashMultimap.create();
//TODO make this configurable
private boolean testMode = true;
@Activate
public void activate() {
appId = coreService.registerApplication("org.onosproject.cordfabric");
deviceService.addListener(deviceListener);
if (deviceService.isAvailable(fabricDeviceId)) {
setupDefaultFlows();
}
log.info("Started");
}
@Deactivate
public void deactivate() {
deviceService.removeListener(deviceListener);
log.info("Stopped");
}
private void setupDefaultFlows() {
TrafficSelector ofInBandMatchUp = DefaultTrafficSelector.builder()
.matchEthType(Ethernet.TYPE_IPV4)
.matchIPProtocol(IPv4.PROTOCOL_TCP)
.matchTcpDst(TpPort.tpPort(ofPort))
.matchInPort(PortNumber.portNumber(6))
.build();
TrafficSelector ofInBandMatchDown = DefaultTrafficSelector.builder()
.matchEthType(Ethernet.TYPE_IPV4)
.matchIPProtocol(IPv4.PROTOCOL_TCP)
.matchTcpSrc(TpPort.tpPort(ofPort))
.matchInPort(PortNumber.portNumber(1))
.build();
TrafficSelector oltMgmtUp = DefaultTrafficSelector.builder()
.matchEthSrc(MacAddress.valueOf("00:0c:d5:00:01:01"))
.matchInPort(PortNumber.portNumber(2))
.build();
TrafficSelector oltMgmtDown = DefaultTrafficSelector.builder()
.matchEthDst(MacAddress.valueOf("00:0c:d5:00:01:01"))
.matchInPort(PortNumber.portNumber(9))
.build();
TrafficTreatment up = DefaultTrafficTreatment.builder()
.setOutput(PortNumber.portNumber(1))
.build();
TrafficTreatment down = DefaultTrafficTreatment.builder()
.setOutput(PortNumber.portNumber(6))
.build();
TrafficSelector toRadius = DefaultTrafficSelector.builder()
.matchInPort(PortNumber.portNumber(2))
.matchEthType(Ethernet.TYPE_IPV4)
.matchIPProtocol(IPv4.PROTOCOL_UDP)
.matchUdpDst(TpPort.tpPort(radiusPort))
.build();
TrafficSelector fromRadius = DefaultTrafficSelector.builder()
.matchInPort(PortNumber.portNumber(5))
.matchEthType(Ethernet.TYPE_IPV4)
.matchIPProtocol(IPv4.PROTOCOL_UDP)
.matchUdpDst(TpPort.tpPort(radiusPort))
.build();
TrafficTreatment toOlt = DefaultTrafficTreatment.builder()
.setOutput(PortNumber.portNumber(2))
.build();
TrafficTreatment toVolt = DefaultTrafficTreatment.builder()
.setOutput(PortNumber.portNumber(9))
.build();
TrafficTreatment sentToRadius = DefaultTrafficTreatment.builder()
.setOutput(PortNumber.portNumber(5))
.build();
TrafficTreatment testPort = DefaultTrafficTreatment.builder()
.setOutput(PortNumber.portNumber(8))
.build();
ForwardingObjective ofTestPath = DefaultForwardingObjective.builder()
.fromApp(appId)
.makePermanent()
.withFlag(ForwardingObjective.Flag.VERSATILE)
.withPriority(TESTPRIO)
.withSelector(
DefaultTrafficSelector.builder()
.matchInPort(PortNumber.portNumber(2))
.build())
.withTreatment(testPort)
.add();
ForwardingObjective radiusToServer = DefaultForwardingObjective.builder()
.fromApp(appId)
.makePermanent()
.withFlag(ForwardingObjective.Flag.VERSATILE)
.withPriority(PRIORITY)
.withSelector(toRadius)
.withTreatment(sentToRadius)
.add();
ForwardingObjective serverToRadius = DefaultForwardingObjective.builder()
.fromApp(appId)
.makePermanent()
.withFlag(ForwardingObjective.Flag.VERSATILE)
.withPriority(PRIORITY)
.withSelector(fromRadius)
.withTreatment(toOlt)
.add();
ForwardingObjective upCtrl = DefaultForwardingObjective.builder()
.fromApp(appId)
.makePermanent()
.withFlag(ForwardingObjective.Flag.VERSATILE)
.withPriority(PRIORITY)
.withSelector(ofInBandMatchUp)
.withTreatment(up)
.add();
ForwardingObjective downCtrl = DefaultForwardingObjective.builder()
.fromApp(appId)
.makePermanent()
.withFlag(ForwardingObjective.Flag.VERSATILE)
.withPriority(PRIORITY)
.withSelector(ofInBandMatchDown)
.withTreatment(down)
.add();
ForwardingObjective upOltMgmt = DefaultForwardingObjective.builder()
.fromApp(appId)
.makePermanent()
.withFlag(ForwardingObjective.Flag.VERSATILE)
.withPriority(PRIORITY)
.withSelector(oltMgmtUp)
.withTreatment(toVolt)
.add();
ForwardingObjective downOltMgmt = DefaultForwardingObjective.builder()
.fromApp(appId)
.makePermanent()
.withFlag(ForwardingObjective.Flag.VERSATILE)
.withPriority(PRIORITY)
.withSelector(oltMgmtDown)
.withTreatment(toOlt)
.add();
if (testMode) {
flowObjectiveService.forward(fabricDeviceId, ofTestPath);
}
flowObjectiveService.forward(fabricDeviceId, upCtrl);
flowObjectiveService.forward(fabricDeviceId, downCtrl);
flowObjectiveService.forward(fabricDeviceId, radiusToServer);
flowObjectiveService.forward(fabricDeviceId, serverToRadius);
flowObjectiveService.forward(fabricDeviceId, upOltMgmt);
flowObjectiveService.forward(fabricDeviceId, downOltMgmt);
}
@Override
public void addVlan(FabricVlan vlan) {
checkNotNull(vlan);
checkArgument(vlan.ports().size() > 1);
verifyPorts(vlan.ports());
removeVlan(vlan.vlan());
if (vlan.iptv()) {
provisionIpTv();
}
vlan.ports().forEach(cp -> {
if (vlans.put(vlan.vlan(), cp)) {
addForwarding(vlan.vlan(), cp.deviceId(), cp.port(),
vlan.ports().stream()
.filter(p -> p != cp)
.map(ConnectPoint::port)
.collect(Collectors.toList()));
}
});
}
//FIXME: pass iptv vlan in here.
private void provisionIpTv() {
TrafficSelector ipTvUp = DefaultTrafficSelector.builder()
.matchVlanId(VlanId.vlanId((short) 7))
.matchInPort(PortNumber.portNumber(2))
.build();
TrafficTreatment ipTvActUp = DefaultTrafficTreatment.builder()
.setOutput(PortNumber.portNumber(7)).build();
TrafficSelector ipTvDown = DefaultTrafficSelector.builder()
.matchVlanId(VlanId.vlanId((short) 7))
.matchInPort(PortNumber.portNumber(7))
.build();
TrafficTreatment ipTvActDown = DefaultTrafficTreatment.builder()
.setOutput(PortNumber.portNumber(2)).build();
ForwardingObjective ipTvUpstream = DefaultForwardingObjective.builder()
.fromApp(appId)
.makePermanent()
.withFlag(ForwardingObjective.Flag.VERSATILE)
.withPriority(PRIORITY)
.withSelector(ipTvUp)
.withTreatment(ipTvActUp)
.add();
ForwardingObjective ipTvDownstream = DefaultForwardingObjective.builder()
.fromApp(appId)
.makePermanent()
.withFlag(ForwardingObjective.Flag.VERSATILE)
.withPriority(PRIORITY)
.withSelector(ipTvDown)
.withTreatment(ipTvActDown)
.add();
flowObjectiveService.forward(fabricDeviceId, ipTvUpstream);
flowObjectiveService.forward(fabricDeviceId, ipTvDownstream);
}
@Override
public void removeVlan(VlanId vlanId) {
Collection<ConnectPoint> ports = vlans.removeAll(vlanId);
ports.forEach(cp -> removeForwarding(vlanId, cp.deviceId(), cp.port(),
ports.stream()
.filter(p -> p != cp)
.map(ConnectPoint::port)
.collect(Collectors.toList())));
}
@Override
public List<FabricVlan> getVlans() {
List<FabricVlan> fVlans = new ArrayList<>();
vlans.keySet().forEach(vlan -> fVlans.add(
//FIXME: Very aweful but will fo for now
new FabricVlan(vlan, vlans.get(vlan), vlan.toShort() == 201)));
return fVlans;
}
private static void verifyPorts(List<ConnectPoint> ports) {
DeviceId deviceId = ports.get(0).deviceId();
for (ConnectPoint connectPoint : ports) {
if (!connectPoint.deviceId().equals(deviceId)) {
throw new IllegalArgumentException("Ports must all be on the same device");
}
}
}
private void addForwarding(VlanId vlanId, DeviceId deviceId, PortNumber inPort,
List<PortNumber> outPorts) {
TrafficSelector selector = DefaultTrafficSelector.builder()
.matchVlanId(vlanId)
.matchInPort(inPort)
.build();
TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
outPorts.forEach(p -> treatmentBuilder.setOutput(p));
ForwardingObjective objective = DefaultForwardingObjective.builder()
.fromApp(appId)
.makePermanent()
.withFlag(ForwardingObjective.Flag.VERSATILE)
.withPriority(PRIORITY)
.withSelector(selector)
.withTreatment(treatmentBuilder.build())
.add(new ObjectiveHandler());
flowObjectiveService.forward(deviceId, objective);
}
private void removeForwarding(VlanId vlanId, DeviceId deviceId, PortNumber inPort,
List<PortNumber> outPorts) {
TrafficSelector selector = DefaultTrafficSelector.builder()
.matchVlanId(vlanId)
.matchInPort(inPort)
.build();
TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
outPorts.forEach(p -> treatmentBuilder.setOutput(p));
ForwardingObjective objective = DefaultForwardingObjective.builder()
.fromApp(appId)
.makePermanent()
.withFlag(ForwardingObjective.Flag.VERSATILE)
.withPriority(PRIORITY)
.withSelector(selector)
.withTreatment(treatmentBuilder.build())
.remove(new ObjectiveHandler());
flowObjectiveService.forward(deviceId, objective);
}
private static class ObjectiveHandler implements ObjectiveContext {
private static Logger log = LoggerFactory.getLogger(ObjectiveHandler.class);
@Override
public void onSuccess(Objective objective) {
log.info("Flow objective operation successful: {}", objective);
}
@Override
public void onError(Objective objective, ObjectiveError error) {
log.info("Flow objective operation failed: {}", objective);
}
}
/**
* Internal listener for device service events.
*/
private class InternalDeviceListener implements DeviceListener {
@Override
public void event(DeviceEvent event) {
switch (event.type()) {
case DEVICE_ADDED:
case DEVICE_AVAILABILITY_CHANGED:
if (event.subject().id().equals(fabricDeviceId) &&
deviceService.isAvailable(event.subject().id())) {
setupDefaultFlows();
}
break;
default:
break;
}
}
}
}
/*
* 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.cordfabric;
import org.onlab.packet.VlanId;
import java.util.List;
/**
* Service used to interact with fabric.
*/
public interface FabricService {
/**
* Remaps a vlan to the specified ports. The specified ports will be the
* only ports in this vlan once the operation completes.
*
* @param vlan vlan object to add
*/
void addVlan(FabricVlan vlan);
/**
* Removes a vlan from all ports in the fabric.
*
* @param vlanId ID of vlan to remove
*/
void removeVlan(VlanId vlanId);
/**
* Returns the vlan to port mapping for all vlans/ports configured in the
* fabric.
*
* @return mapping of vlan to port
*/
List<FabricVlan> getVlans();
}
/*
* 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.cordfabric;
import com.google.common.collect.ImmutableList;
import org.onlab.packet.VlanId;
import org.onosproject.net.ConnectPoint;
import java.util.Collection;
import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Vlan which spans multiple fabric ports.
*/
public class FabricVlan {
private final VlanId vlan;
private final List<ConnectPoint> ports;
private final boolean iptv;
public FabricVlan(VlanId vlan, Collection<ConnectPoint> ports, boolean iptv) {
checkNotNull(vlan);
checkNotNull(ports);
this.vlan = vlan;
this.ports = ImmutableList.copyOf(ports);
this.iptv = iptv;
}
public VlanId vlan() {
return vlan;
}
public List<ConnectPoint> ports() {
return ports;
}
public boolean iptv() {
return iptv;
}
}
/*
* 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.cordfabric;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.onlab.packet.VlanId;
import org.onosproject.codec.CodecContext;
import org.onosproject.codec.JsonCodec;
import org.onosproject.net.ConnectPoint;
import java.util.ArrayList;
import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Codec for encoding/decoding a FabricVlan object to/from JSON.
*/
public final class FabricVlanCodec extends JsonCodec<FabricVlan> {
// JSON field names
private static final String VLAN = "vlan";
private static final String PORTS = "ports";
private static final String IPTV = "iptv";
@Override
public ObjectNode encode(FabricVlan vlan, CodecContext context) {
checkNotNull(vlan, "Vlan cannot be null");
final ObjectNode result = context.mapper().createObjectNode()
.put(VLAN, vlan.vlan().toShort());
final ArrayNode jsonPorts = result.putArray(PORTS);
vlan.ports().forEach(cp -> jsonPorts.add(context.codec(ConnectPoint.class).encode(cp, context)));
return result;
}
@Override
public FabricVlan decode(ObjectNode json, CodecContext context) {
short vlan = json.path(VLAN).shortValue();
boolean iptv = json.path(IPTV).booleanValue();
List<ConnectPoint> ports = new ArrayList<>();
ArrayNode portArray = (ArrayNode) json.path(PORTS);
for (JsonNode o : portArray) {
ports.add(context.codec(ConnectPoint.class).decode((ObjectNode) o, context));
}
return new FabricVlan(VlanId.vlanId(vlan), ports, iptv);
}
}
/*
* 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.cordfabric;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.onlab.packet.VlanId;
import org.onosproject.rest.AbstractWebResource;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
/**
* Web resource for interacting with the fabric.
*/
@Path("vlans")
public class FabricWebResource extends AbstractWebResource {
private static final FabricVlanCodec VLAN_CODEC = new FabricVlanCodec();
/**
* Get all CORD fabric VLANs.
*
* @return array of cord VLANs in the system.
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getVlans() {
FabricService fabricService = get(FabricService.class);
List<FabricVlan> vlans = fabricService.getVlans();
ObjectNode result = new ObjectMapper().createObjectNode();
result.set("vlans", new FabricVlanCodec().encode(vlans, this));
return ok(result.toString()).build();
}
/**
* Create a CORD fabric VLAN.
*
* @param input JSON stream describing new VLAN
* @return status of the request - CREATED if the JSON is correct,
* INTERNAL_SERVER_ERROR if the JSON is invalid
* @throws IOException if the JSON is invalid
*/
@POST
@Path("add")
@Consumes(MediaType.APPLICATION_JSON)
public Response addVlan(InputStream input) throws IOException {
ObjectMapper mapper = new ObjectMapper();
ObjectNode vlanJson = (ObjectNode) mapper.readTree(input);
FabricService fabricService = get(FabricService.class);
fabricService.addVlan(VLAN_CODEC.decode(vlanJson, this));
return Response.ok().build();
}
/**
* Delete a CORD fabric VLAN.
*
* @param vlan identifier of the VLAN to remove
* @return status of the request - OK
*/
@DELETE
@Path("{vlan}")
public Response deleteVlan(@PathParam("vlan") String vlan) {
VlanId vlanId = VlanId.vlanId(Short.parseShort(vlan));
FabricService fabricService = get(FabricService.class);
fabricService.removeVlan(vlanId);
return Response.ok().build();
}
}
/*
* 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.cordfabric.cli;
import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
import org.onlab.packet.VlanId;
import org.onosproject.cli.AbstractShellCommand;
import org.onosproject.cordfabric.FabricService;
import org.onosproject.cordfabric.FabricVlan;
import org.onosproject.net.ConnectPoint;
import java.util.ArrayList;
import java.util.List;
/**
* Adds a vlan to the fabric.
*/
@Command(scope = "onos", name = "add-fabric-vlan",
description = "Adds a VLAN to the fabric")
public class FabricAddCommand extends AbstractShellCommand {
@Argument(index = 0, name = "vlanid", description = "VLAN ID",
required = true, multiValued = false)
private String vlanIdString = null;
@Argument(index = 1, name = "ports",
description = "List of ports in the VLAN",
required = true, multiValued = true)
private String[] portStrings = null;
@Override
protected void execute() {
FabricService service = AbstractShellCommand.get(FabricService.class);
VlanId vlan = VlanId.vlanId(Short.parseShort(vlanIdString));
if (portStrings.length < 2) {
throw new IllegalArgumentException("Must have at least 2 ports");
}
List<ConnectPoint> ports = new ArrayList<>(portStrings.length);
for (String portString : portStrings) {
ports.add(ConnectPoint.deviceConnectPoint(portString));
}
service.addVlan(new FabricVlan(vlan, ports, 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.
*/
package org.onosproject.cordfabric.cli;
import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
import org.onlab.packet.VlanId;
import org.onosproject.cli.AbstractShellCommand;
import org.onosproject.cordfabric.FabricService;
/**
* Removes a vlan from the fabric.
*/
@Command(scope = "onos", name = "remove-fabric-vlan",
description = "Removes a VLAN from the fabric")
public class FabricRemoveCommand extends AbstractShellCommand {
@Argument(index = 0, name = "vlanid", description = "VLAN ID",
required = true, multiValued = false)
private String vlanIdString = null;
@Override
protected void execute() {
FabricService service = AbstractShellCommand.get(FabricService.class);
VlanId vlan = VlanId.vlanId(Short.parseShort(vlanIdString));
service.removeVlan(vlan);
}
}
/*
* 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.cordfabric.cli;
import org.apache.karaf.shell.commands.Command;
import org.onosproject.cli.AbstractShellCommand;
import org.onosproject.cordfabric.FabricService;
import org.onosproject.cordfabric.FabricVlan;
import java.util.List;
/**
* Shows the vlans in the fabric.
*/
@Command(scope = "onos", name = "fabric",
description = "Shows the fabric vlans")
public class FabricShowCommand extends AbstractShellCommand {
private static final String VLAN_HEADER_LINE_FORMAT = "VLAN %s";
private static final String PORT_LINE_FORMAT = "\t%s";
@Override
protected void execute() {
FabricService service = AbstractShellCommand.get(FabricService.class);
List<FabricVlan> vlans = service.getVlans();
vlans.forEach(fabricVlan -> {
print(VLAN_HEADER_LINE_FORMAT, fabricVlan.vlan());
fabricVlan.ports().forEach(cp -> print(PORT_LINE_FORMAT, cp));
});
}
}
/*
* 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.
*/
/**
* Console commands for managing fabric of VLANs.
*/
package org.onosproject.cordfabric.cli;
\ 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.
*/
/**
* Service for managing fabric of VLANs.
*/
package org.onosproject.cordfabric;
\ 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.
-->
<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.cordfabric.cli.FabricShowCommand"/>
</command>
<command>
<action class="org.onosproject.cordfabric.cli.FabricAddCommand"/>
<completers>
<ref component-id="placeholderCompleter"/>
<ref component-id="connectPointCompleter"/>
</completers>
</command>
<command>
<action class="org.onosproject.cordfabric.cli.FabricRemoveCommand"/>
</command>
</command-bundle>
<bean id="connectPointCompleter" class="org.onosproject.cli.net.ConnectPointCompleter"/>
<bean id="placeholderCompleter" class="org.onosproject.cli.PlaceholderCompleter"/>
</blueprint>
<?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.
-->
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="ONOS" version="2.5">
<display-name>CORD Fabric REST API v1.0</display-name>
<servlet>
<servlet-name>JAX-RS Service</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.classnames</param-name>
<param-value>
org.onosproject.cordfabric.FabricWebResource
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>JAX-RS Service</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
......@@ -46,7 +46,6 @@
<module>bgprouter</module>
<module>test</module>
<module>segmentrouting</module>
<module>cordfabric</module>
<module>xos-integration</module>
<module>pcep-api</module>
<module>iptopology-api</module>
......