Praseed Balakrishnan

Merge branch 'optical-integration' of ssh://gerrit.onlab.us:29418/onos-next into optical-integration

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.onlab.onos.cli.net;
import static org.onlab.onos.net.DeviceId.deviceId;
import static org.onlab.onos.net.PortNumber.portNumber;
import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.PortNumber;
import org.onlab.onos.net.intent.Intent;
import org.onlab.onos.net.intent.IntentService;
import org.onlab.onos.net.intent.OpticalConnectivityIntent;
/**
* Installs optical connectivity intents.
*/
@Command(scope = "onos", name = "add-optical-intent",
description = "Installs optical connectivity intent")
public class AddOpticalIntentCommand extends ConnectivityIntentCommand {
@Argument(index = 0, name = "ingressDevice",
description = "Ingress Device/Port Description",
required = true, multiValued = false)
String ingressDeviceString = null;
@Argument(index = 1, name = "egressDevice",
description = "Egress Device/Port Description",
required = true, multiValued = false)
String egressDeviceString = null;
@Override
protected void execute() {
IntentService service = get(IntentService.class);
DeviceId ingressDeviceId = deviceId(getDeviceId(ingressDeviceString));
PortNumber ingressPortNumber = portNumber(getPortNumber(ingressDeviceString));
ConnectPoint ingress = new ConnectPoint(ingressDeviceId, ingressPortNumber);
DeviceId egressDeviceId = deviceId(getDeviceId(egressDeviceString));
PortNumber egressPortNumber = portNumber(getPortNumber(egressDeviceString));
ConnectPoint egress = new ConnectPoint(egressDeviceId, egressPortNumber);
Intent intent = new OpticalConnectivityIntent(appId(), ingress, egress);
service.submit(intent);
}
/**
* Extracts the port number portion of the ConnectPoint.
*
* @param deviceString string representing the device/port
* @return port number as a string, empty string if the port is not found
*/
private String getPortNumber(String deviceString) {
int slash = deviceString.indexOf('/');
if (slash <= 0) {
return "";
}
return deviceString.substring(slash + 1, deviceString.length());
}
/**
* Extracts the device ID portion of the ConnectPoint.
*
* @param deviceString string representing the device/port
* @return device ID string
*/
private String getDeviceId(String deviceString) {
int slash = deviceString.indexOf('/');
if (slash <= 0) {
return "";
}
return deviceString.substring(0, slash);
}
}
......@@ -119,6 +119,14 @@
</optional-completers>
</command>
<command>
<action class="org.onlab.onos.cli.net.AddOpticalIntentCommand"/>
<completers>
<ref component-id="connectPointCompleter"/>
<ref component-id="connectPointCompleter"/>
<null/>
</completers>
</command>
<command>
<action class="org.onlab.onos.cli.net.GetStatistics"/>
<completers>
<ref component-id="connectPointCompleter"/>
......
......@@ -6,46 +6,45 @@ import org.onlab.onos.ApplicationId;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.Link;
import org.onlab.onos.net.Path;
import org.onlab.onos.net.flow.TrafficSelector;
import org.onlab.onos.net.flow.TrafficTreatment;
import com.google.common.base.MoreObjects;
public class OpticalPathIntent extends OpticalConnectivityIntent {
public class OpticalPathIntent extends ConnectivityIntent {
private final ConnectPoint src;
private final ConnectPoint dst;
private final Path path;
// private final TrafficSelector opticalMatch;
// private final TrafficTreatment opticalAction;
public OpticalPathIntent(ApplicationId appId,
ConnectPoint src,
ConnectPoint dst,
TrafficSelector match,
TrafficTreatment action,
Path path) {
super(appId, src, dst);
// this.opticalMatch = match;
// this.opticalAction = action;
super(id(OpticalPathIntent.class, src, dst),
appId, resources(path.links()), null, null);
this.src = src;
this.dst = dst;
this.path = path;
}
protected OpticalPathIntent() {
// this.opticalMatch = null;
// this.opticalAction = null;
this.src = null;
this.dst = null;
this.path = null;
}
public Path path() {
return path;
public ConnectPoint src() {
return src;
}
/*
public TrafficSelector selector() {
// return opticalMatch;
public ConnectPoint dst() {
return dst;
}
public TrafficTreatment treatment() {
// return opticalAction;
public Path path() {
return path;
}
*/
@Override
public boolean isInstallable() {
return true;
......@@ -55,10 +54,8 @@ public class OpticalPathIntent extends OpticalConnectivityIntent {
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("id", id())
//.add("match", opticalMatch)
//.add("action", opticalAction)
.add("ingressPort", this.getSrcConnectPoint())
.add("egressPort", this.getDst())
.add("ingressPort", src)
.add("egressPort", dst)
.add("path", path)
.toString();
}
......
......@@ -36,7 +36,7 @@ public interface LinkResourceService {
* @param intentId the target Intent's id
* @return allocated resources for Intent
*/
LinkResourceAllocations getAllocation(IntentId intentId);
LinkResourceAllocations getAllocations(IntentId intentId);
/**
* Returns all allocated resources to given link.
......
......@@ -5,10 +5,4 @@ package org.onlab.onos.net.resource;
*/
public interface ResourceAllocation extends ResourceRequest {
/**
* Returns the type of the allocated resource.
*
* @return the type of the allocated resource
*/
ResourceType type();
}
......
......@@ -14,16 +14,11 @@ import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onlab.onos.CoreService;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.Link;
import org.onlab.onos.net.Path;
import org.onlab.onos.net.flow.TrafficSelector;
import org.onlab.onos.net.flow.TrafficTreatment;
import org.onlab.onos.net.intent.Intent;
import org.onlab.onos.net.intent.IntentCompiler;
import org.onlab.onos.net.intent.IntentExtensionService;
import org.onlab.onos.net.intent.OpticalConnectivityIntent;
import org.onlab.onos.net.intent.OpticalPathIntent;
import org.onlab.onos.net.provider.ProviderId;
......@@ -32,7 +27,6 @@ import org.onlab.onos.net.topology.LinkWeight;
import org.onlab.onos.net.topology.PathService;
import org.onlab.onos.net.topology.Topology;
import org.onlab.onos.net.topology.TopologyEdge;
import org.onlab.onos.net.topology.TopologyService;
import org.slf4j.Logger;
......@@ -88,15 +82,10 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical
links.addAll(path.links());
//links.add(DefaultEdgeLink.createEdgeLink(intent.getDst(), false));
TrafficSelector opticalSelector = null;
TrafficTreatment opticalTreatment = null;
// create a new opticalPathIntent
Intent newIntent = new OpticalPathIntent(intent.appId(),
path.src(),
path.dst(),
opticalSelector,
opticalTreatment,
path);
retList.add(newIntent);
......
......@@ -3,7 +3,6 @@ package org.onlab.onos.net.intent.impl;
import static org.onlab.onos.net.flow.DefaultTrafficTreatment.builder;
import static org.slf4j.LoggerFactory.getLogger;
import java.util.List;
import org.apache.felix.scr.annotations.Activate;
......@@ -20,11 +19,11 @@ import org.onlab.onos.net.flow.DefaultTrafficSelector;
import org.onlab.onos.net.flow.DefaultTrafficTreatment;
import org.onlab.onos.net.flow.FlowRule;
import org.onlab.onos.net.flow.FlowRuleBatchEntry;
import org.onlab.onos.net.flow.FlowRuleBatchEntry.FlowRuleOperation;
import org.onlab.onos.net.flow.FlowRuleBatchOperation;
import org.onlab.onos.net.flow.FlowRuleService;
import org.onlab.onos.net.flow.TrafficSelector;
import org.onlab.onos.net.flow.TrafficTreatment;
import org.onlab.onos.net.flow.FlowRuleBatchEntry.FlowRuleOperation;
import org.onlab.onos.net.intent.IntentExtensionService;
import org.onlab.onos.net.intent.IntentInstaller;
import org.onlab.onos.net.intent.OpticalPathIntent;
......@@ -86,12 +85,12 @@ public class OpticalPathIntentInstaller implements IntentInstaller<OpticalPathIn
LinkResourceAllocations allocations = assignWavelength(intent);
TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
selectorBuilder.matchInport(intent.getSrcConnectPoint().port());
selectorBuilder.matchInport(intent.src().port());
TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
List<FlowRuleBatchEntry> rules = Lists.newLinkedList();
ConnectPoint prev = intent.getSrcConnectPoint();
ConnectPoint prev = intent.src();
//TODO throw exception if the lambda was not assigned successfully
for (Link link : intent.path().links()) {
......@@ -109,7 +108,7 @@ public class OpticalPathIntentInstaller implements IntentInstaller<OpticalPathIn
}
treatmentBuilder.setOutput(link.src().port());
//treatmentBuilder.setLambda(la.toInt());
treatmentBuilder.setLambda((short) la.toInt());
FlowRule rule = new DefaultFlowRule(prev.deviceId(),
selectorBuilder.build(),
......@@ -122,13 +121,13 @@ public class OpticalPathIntentInstaller implements IntentInstaller<OpticalPathIn
prev = link.dst();
selectorBuilder.matchInport(link.dst().port());
//selectorBuilder.setLambda(la.toInt());
selectorBuilder.matchLambda((short) la.toInt());
}
// build the last T port rule
TrafficTreatment treatmentLast = builder()
.setOutput(intent.getDst().port()).build();
FlowRule rule = new DefaultFlowRule(intent.getDst().deviceId(),
.setOutput(intent.dst().port()).build();
FlowRule rule = new DefaultFlowRule(intent.dst().deviceId(),
selectorBuilder.build(),
treatmentLast,
100,
......@@ -187,15 +186,15 @@ public class OpticalPathIntentInstaller implements IntentInstaller<OpticalPathIn
@Override
public List<FlowRuleBatchOperation> uninstall(OpticalPathIntent intent) {
LinkResourceAllocations allocations = resourceService.getAllocation(intent.id());
LinkResourceAllocations allocations = resourceService.getAllocations(intent.id());
TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
selectorBuilder.matchInport(intent.getSrcConnectPoint().port());
selectorBuilder.matchInport(intent.src().port());
TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
List<FlowRuleBatchEntry> rules = Lists.newLinkedList();
ConnectPoint prev = intent.getSrcConnectPoint();
ConnectPoint prev = intent.src();
//TODO throw exception if the lambda was not retrieved successfully
for (Link link : intent.path().links()) {
......@@ -213,7 +212,7 @@ public class OpticalPathIntentInstaller implements IntentInstaller<OpticalPathIn
}
treatmentBuilder.setOutput(link.src().port());
//treatmentBuilder.setLambda(la.toInt());
treatmentBuilder.setLambda((short) la.toInt());
FlowRule rule = new DefaultFlowRule(prev.deviceId(),
selectorBuilder.build(),
......@@ -226,13 +225,13 @@ public class OpticalPathIntentInstaller implements IntentInstaller<OpticalPathIn
prev = link.dst();
selectorBuilder.matchInport(link.dst().port());
//selectorBuilder.setLambda(la.toInt());
selectorBuilder.matchLambda((short) la.toInt());
}
// build the last T port rule
TrafficTreatment treatmentLast = builder()
.setOutput(intent.getDst().port()).build();
FlowRule rule = new DefaultFlowRule(intent.getDst().deviceId(),
.setOutput(intent.dst().port()).build();
FlowRule rule = new DefaultFlowRule(intent.dst().deviceId(),
selectorBuilder.build(),
treatmentLast,
100,
......
package org.onlab.onos.net.resource;
package org.onlab.onos.net.resource.impl;
import java.util.Collection;
import java.util.Collections;
......@@ -7,6 +7,11 @@ import java.util.Set;
import org.onlab.onos.net.Link;
import org.onlab.onos.net.intent.IntentId;
import org.onlab.onos.net.resource.LinkResourceAllocations;
import org.onlab.onos.net.resource.LinkResourceRequest;
import org.onlab.onos.net.resource.ResourceAllocation;
import org.onlab.onos.net.resource.ResourceRequest;
import org.onlab.onos.net.resource.ResourceType;
/**
* Implementation of {@link LinkResourceAllocations}.
......
package org.onlab.onos.net.resource;
package org.onlab.onos.net.resource.impl;
import static org.slf4j.LoggerFactory.getLogger;
......@@ -12,6 +12,15 @@ import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Service;
import org.onlab.onos.net.Link;
import org.onlab.onos.net.intent.IntentId;
import org.onlab.onos.net.resource.BandwidthResourceAllocation;
import org.onlab.onos.net.resource.BandwidthResourceRequest;
import org.onlab.onos.net.resource.Lambda;
import org.onlab.onos.net.resource.LambdaResourceAllocation;
import org.onlab.onos.net.resource.LinkResourceAllocations;
import org.onlab.onos.net.resource.LinkResourceRequest;
import org.onlab.onos.net.resource.LinkResourceService;
import org.onlab.onos.net.resource.ResourceAllocation;
import org.onlab.onos.net.resource.ResourceRequest;
import org.slf4j.Logger;
import com.google.common.collect.Sets;
......@@ -76,7 +85,7 @@ public class LinkResourceManager implements LinkResourceService {
}
@Override
public LinkResourceAllocations getAllocation(IntentId intentId) {
public LinkResourceAllocations getAllocations(IntentId intentId) {
// TODO Auto-generated method stub
return null;
}
......
/**
* Services for reserving network resources, e.g.&nbsp;bandwidth, lambdas.
*/
package org.onlab.onos.net.resource;
package org.onlab.onos.net.resource.impl;
......