Srikanth Vavilapalli
Committed by Gerrit Code Review

Segment Routing refactor with flow objectives

Change-Id: I0b87f89bb8b18522b9d38bdf5e96f55485b6f1e3
Showing 22 changed files with 711 additions and 134 deletions
......@@ -24,7 +24,6 @@ import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Link;
import org.onosproject.net.MastershipRole;
import org.onosproject.net.flow.FlowRule;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -38,7 +37,8 @@ import static com.google.common.base.Preconditions.checkNotNull;
public class DefaultRoutingHandler {
private static Logger log = LoggerFactory.getLogger(DefaultRoutingHandler.class);
private static Logger log = LoggerFactory
.getLogger(DefaultRoutingHandler.class);
private SegmentRoutingManager srManager;
private RoutingRulePopulator rulePopulator;
......@@ -56,7 +56,8 @@ public class DefaultRoutingHandler {
// population process started.
STARTED,
// population process was aborted due to errors, mostly for groups not found.
// population process was aborted due to errors, mostly for groups not
// found.
ABORTED,
// population process was finished successfully.
......@@ -89,8 +90,7 @@ public class DefaultRoutingHandler {
log.info("Starts to populate routing rules");
for (Device sw : srManager.deviceService.getDevices()) {
if (srManager.mastershipService.
getLocalRole(sw.id()) != MastershipRole.MASTER) {
if (srManager.mastershipService.getLocalRole(sw.id()) != MastershipRole.MASTER) {
continue;
}
......@@ -323,11 +323,11 @@ public class DefaultRoutingHandler {
private boolean populateEcmpRoutingRules(DeviceId destSw,
ECMPShortestPathGraph ecmpSPG) {
HashMap<Integer, HashMap<DeviceId, ArrayList<ArrayList<DeviceId>>>> switchVia =
ecmpSPG.getAllLearnedSwitchesAndVia();
HashMap<Integer, HashMap<DeviceId, ArrayList<ArrayList<DeviceId>>>> switchVia = ecmpSPG
.getAllLearnedSwitchesAndVia();
for (Integer itrIdx : switchVia.keySet()) {
HashMap<DeviceId, ArrayList<ArrayList<DeviceId>>> swViaMap =
switchVia.get(itrIdx);
HashMap<DeviceId, ArrayList<ArrayList<DeviceId>>> swViaMap = switchVia
.get(itrIdx);
for (DeviceId targetSw : swViaMap.keySet()) {
Set<DeviceId> nextHops = new HashSet<>();
......@@ -347,15 +347,17 @@ public class DefaultRoutingHandler {
return true;
}
private boolean populateEcmpRoutingRulePartial(DeviceId targetSw, DeviceId destSw,
Set<DeviceId> nextHops) {
private boolean populateEcmpRoutingRulePartial(DeviceId targetSw,
DeviceId destSw,
Set<DeviceId> nextHops) {
boolean result;
if (nextHops.isEmpty()) {
nextHops.add(destSw);
}
// If both target switch and dest switch are edge routers, then set IP rule
// If both target switch and dest switch are edge routers, then set IP
// rule
// for both subnet and router IP.
if (config.isEdgeDevice(targetSw) && config.isEdgeDevice(destSw)) {
List<Ip4Prefix> subnets = config.getSubnets(destSw);
......@@ -374,7 +376,7 @@ public class DefaultRoutingHandler {
return false;
}
// If the target switch is an edge router, then set IP rules for the router IP.
// TODO: If the target switch is an edge router, then set IP rules for the router IP.
} else if (config.isEdgeDevice(targetSw)) {
Ip4Address routerIp = config.getRouterIp(destSw);
IpPrefix routerIpPrefix = IpPrefix.valueOf(routerIp, IpPrefix.MAX_INET_MASK_LENGTH);
......@@ -383,7 +385,7 @@ public class DefaultRoutingHandler {
return false;
}
// If the target switch is an transit router, then set MPLS rules only.
// TODO: If the target switch is an transit router, then set MPLS rules only.
} else if (!config.isEdgeDevice(targetSw)) {
result = rulePopulator.populateMplsRule(targetSw, destSw, nextHops);
if (!result) {
......@@ -395,38 +397,25 @@ public class DefaultRoutingHandler {
}
/**
* Populates table miss entries for all tables, and pipeline rules for
* VLAN and TACM tables.
* Populates table miss entries for all tables, and pipeline rules for VLAN
* and TACM tables.
*
* @param deviceId Switch ID to set the rules
*/
public void populateTtpRules(DeviceId deviceId) {
rulePopulator.populateTableMissEntry(deviceId, FlowRule.Type.VLAN,
true, false, false, FlowRule.Type.DEFAULT);
rulePopulator.populateTableMissEntry(deviceId, FlowRule.Type.ETHER,
true, false, false, FlowRule.Type.DEFAULT);
rulePopulator.populateTableMissEntry(deviceId, FlowRule.Type.IP,
false, true, true, FlowRule.Type.ACL);
rulePopulator.populateTableMissEntry(deviceId, FlowRule.Type.MPLS,
false, true, true, FlowRule.Type.ACL);
rulePopulator.populateTableMissEntry(deviceId, FlowRule.Type.ACL,
false, false, false, FlowRule.Type.DEFAULT);
rulePopulator.populateTableVlan(deviceId);
rulePopulator.populateTableTMac(deviceId);
}
/**
* Start the flow rule population process if it was never started.
* The process finishes successfully when all flow rules are set and
* stops with ABORTED status when any groups required for flows is not
* set yet.
* Start the flow rule population process if it was never started. The
* process finishes successfully when all flow rules are set and stops with
* ABORTED status when any groups required for flows is not set yet.
*/
public void startPopulationProcess() {
synchronized (populationStatus) {
if (populationStatus == Status.IDLE ||
populationStatus == Status.SUCCEEDED) {
if (populationStatus == Status.IDLE
|| populationStatus == Status.SUCCEEDED) {
populationStatus = Status.STARTED;
populateAllRoutingRules();
}
......@@ -441,7 +430,8 @@ public class DefaultRoutingHandler {
synchronized (populationStatus) {
if (populationStatus == Status.ABORTED) {
populationStatus = Status.STARTED;
// TODO: we need to restart from the point aborted instead of restarting.
// TODO: we need to restart from the point aborted instead of
// restarting.
populateAllRoutingRules();
}
}
......
/*
* 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.segmentrouting;
import com.google.common.collect.Lists;
import org.onlab.packet.Ip4Address;
import org.onlab.packet.Ip4Prefix;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Link;
import org.onosproject.net.PortNumber;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.Set;
/**
* This class is temporary class and used only for test.
* It will be replaced with "real" Network Config Manager.
*
* TODO: Knock off this wrapper and directly use DeviceConfiguration class
*/
public class NetworkConfigHandler {
private static Logger log = LoggerFactory.getLogger(NetworkConfigHandler.class);
private SegmentRoutingManager srManager;
private DeviceConfiguration deviceConfig;
public NetworkConfigHandler(SegmentRoutingManager srManager,
DeviceConfiguration deviceConfig) {
this.srManager = srManager;
this.deviceConfig = deviceConfig;
}
public List<Ip4Address> getGatewayIpAddress(DeviceId deviceId) {
return this.deviceConfig.getSubnetGatewayIps(deviceId);
}
public IpPrefix getRouterIpAddress(DeviceId deviceId) {
return IpPrefix.valueOf(deviceConfig.getRouterIp(deviceId), 32);
}
public MacAddress getRouterMacAddress(DeviceId deviceId) {
return deviceConfig.getDeviceMac(deviceId);
}
public boolean inSameSubnet(DeviceId deviceId, Ip4Address destIp) {
List<Ip4Prefix> subnets = getSubnetInfo(deviceId);
if (subnets == null) {
return false;
}
return subnets.stream()
.anyMatch((subnet) -> subnet.contains(destIp));
}
public boolean inSameSubnet(Ip4Address address, int sid) {
DeviceId deviceId = deviceConfig.getDeviceId(sid);
if (deviceId == null) {
log.warn("Cannot find a device for SID {}", sid);
return false;
}
return inSameSubnet(deviceId, address);
}
public List<Ip4Prefix> getSubnetInfo(DeviceId deviceId) {
return deviceConfig.getSubnets(deviceId);
}
public int getMplsId(DeviceId deviceId) {
return deviceConfig.getSegmentId(deviceId);
}
public int getMplsId(MacAddress routerMac) {
return deviceConfig.getSegmentId(routerMac);
}
public int getMplsId(Ip4Address routerIpAddress) {
return deviceConfig.getSegmentId(routerIpAddress);
}
public boolean isEcmpNotSupportedInTransit(DeviceId deviceId) {
//TODO: temporarily changing to true to test with Dell
return true;
}
public boolean isTransitRouter(DeviceId deviceId) {
return !(deviceConfig.isEdgeDevice(deviceId));
}
public boolean isEdgeRouter(DeviceId deviceId) {
return deviceConfig.isEdgeDevice(deviceId);
}
private List<PortNumber> getPortsToNeighbors(DeviceId deviceId, List<DeviceId> fwdSws) {
List<PortNumber> portNumbers = Lists.newArrayList();
Set<Link> links = srManager.linkService.getDeviceEgressLinks(deviceId);
for (Link link: links) {
for (DeviceId swId: fwdSws) {
if (link.dst().deviceId().equals(swId)) {
portNumbers.add(link.src().port());
break;
}
}
}
return portNumbers;
}
public List<PortNumber> getPortsToDevice(DeviceId deviceId) {
List<PortNumber> portNumbers = Lists.newArrayList();
Set<Link> links = srManager.linkService.getDeviceEgressLinks(deviceId);
for (Link link: links) {
if (link.dst().deviceId().equals(deviceId)) {
portNumbers.add(link.src().port());
}
}
return portNumbers;
}
public Ip4Address getDestinationRouterAddress(Ip4Address destIpAddress) {
return deviceConfig.getRouterIpAddressForASubnetHost(destIpAddress);
}
public DeviceId getDeviceId(Ip4Address ip4Address) {
return deviceConfig.getDeviceId(ip4Address);
}
public MacAddress getRouterMac(Ip4Address targetAddress) {
return deviceConfig.getRouterMacForAGatewayIp(targetAddress);
}
}
......@@ -15,7 +15,6 @@
*/
package org.onosproject.segmentrouting.grouphandler;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
......@@ -26,10 +25,7 @@ import org.onosproject.net.DeviceId;
import org.onosproject.net.Link;
import org.onosproject.net.flow.DefaultTrafficTreatment;
import org.onosproject.net.flow.TrafficTreatment;
import org.onosproject.net.group.DefaultGroupBucket;
import org.onosproject.net.group.GroupBucket;
import org.onosproject.net.group.GroupBuckets;
import org.onosproject.net.group.GroupService;
import org.onosproject.net.flowobjective.FlowObjectiveService;
import org.onosproject.net.link.LinkService;
/**
......@@ -55,8 +51,8 @@ public class DefaultEdgeGroupHandler extends DefaultGroupHandler {
ApplicationId appId,
DeviceProperties config,
LinkService linkService,
GroupService groupService) {
super(deviceId, appId, config, linkService, groupService);
FlowObjectiveService flowObjService) {
super(deviceId, appId, config, linkService, flowObjService);
}
@Override
......@@ -130,7 +126,7 @@ public class DefaultEdgeGroupHandler extends DefaultGroupHandler {
.setMpls(MplsLabel.
mplsLabel(ns.getEdgeLabel()));
}
GroupBucket updatedBucket = DefaultGroupBucket.
/*GroupBucket updatedBucket = DefaultGroupBucket.
createSelectGroupBucket(tBuilder.build());
GroupBuckets updatedBuckets = new GroupBuckets(
Arrays.asList(updatedBucket));
......@@ -140,7 +136,8 @@ public class DefaultEdgeGroupHandler extends DefaultGroupHandler {
getGroupKey(ns),
updatedBuckets,
getGroupKey(ns),
appId);
appId);*/
//TODO: Use nextObjective APIs to update the next objective
}
}
......
......@@ -15,7 +15,6 @@
*/
package org.onosproject.segmentrouting.grouphandler;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
......@@ -25,10 +24,7 @@ import org.onosproject.net.DeviceId;
import org.onosproject.net.Link;
import org.onosproject.net.flow.DefaultTrafficTreatment;
import org.onosproject.net.flow.TrafficTreatment;
import org.onosproject.net.group.DefaultGroupBucket;
import org.onosproject.net.group.GroupBucket;
import org.onosproject.net.group.GroupBuckets;
import org.onosproject.net.group.GroupService;
import org.onosproject.net.flowobjective.FlowObjectiveService;
import org.onosproject.net.link.LinkService;
/**
......@@ -49,8 +45,8 @@ public class DefaultTransitGroupHandler extends DefaultGroupHandler {
ApplicationId appId,
DeviceProperties config,
LinkService linkService,
GroupService groupService) {
super(deviceId, appId, config, linkService, groupService);
FlowObjectiveService flowObjService) {
super(deviceId, appId, config, linkService, flowObjService);
}
@Override
......@@ -118,7 +114,7 @@ public class DefaultTransitGroupHandler extends DefaultGroupHandler {
.setMpls(MplsLabel.
mplsLabel(ns.getEdgeLabel()));
}
GroupBucket updatedBucket = DefaultGroupBucket.
/*GroupBucket updatedBucket = DefaultGroupBucket.
createSelectGroupBucket(tBuilder.build());
GroupBuckets updatedBuckets = new GroupBuckets(
Arrays.asList(updatedBucket));
......@@ -128,7 +124,8 @@ public class DefaultTransitGroupHandler extends DefaultGroupHandler {
getGroupKey(ns),
updatedBuckets,
getGroupKey(ns),
appId);
appId);*/
//TODO: Use nextObjective APIs to update the next objective
}
}
......
......@@ -25,19 +25,13 @@ import java.util.List;
import org.onlab.packet.MplsLabel;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.GroupId;
import org.onosproject.segmentrouting.grouphandler.GroupBucketIdentifier.BucketOutputType;
import org.onosproject.net.DeviceId;
import org.onosproject.net.PortNumber;
import org.onosproject.net.flow.DefaultTrafficTreatment;
import org.onosproject.net.flow.TrafficTreatment;
import org.onosproject.net.group.DefaultGroupBucket;
import org.onosproject.net.group.DefaultGroupDescription;
import org.onosproject.net.flowobjective.FlowObjectiveService;
import org.onosproject.net.group.GroupBucket;
import org.onosproject.net.group.GroupBuckets;
import org.onosproject.net.group.GroupDescription;
import org.onosproject.net.group.GroupEvent;
import org.onosproject.net.group.GroupService;
import org.onosproject.net.link.LinkService;
import org.slf4j.Logger;
......@@ -58,14 +52,14 @@ public class PolicyGroupHandler extends DefaultGroupHandler {
* @param appId application identifier
* @param config interface to retrieve the device properties
* @param linkService link service object
* @param groupService group service object
* @param flowObjService flow objective service object
*/
public PolicyGroupHandler(DeviceId deviceId,
ApplicationId appId,
DeviceProperties config,
LinkService linkService,
GroupService groupService) {
super(deviceId, appId, config, linkService, groupService);
FlowObjectiveService flowObjService) {
super(deviceId, appId, config, linkService, flowObjService);
}
public PolicyGroupIdentifier createPolicyGroupChain(String id,
......@@ -111,15 +105,16 @@ public class PolicyGroupHandler extends DefaultGroupHandler {
.setEthSrc(nodeMacAddr)
.pushMpls()
.setMpls(MplsLabel.mplsLabel(label));
outBuckets.add(DefaultGroupBucket.
/*outBuckets.add(DefaultGroupBucket.
createSelectGroupBucket(tBuilder.build()));
GroupDescription desc = new
DefaultGroupDescription(deviceId,
GroupDescription.Type.INDIRECT,
new GroupBuckets(outBuckets));
//TODO: BoS
//TODO: BoS*/
previousGroupkey = key;
groupService.addGroup(desc);
//groupService.addGroup(desc);
//TODO: Use nextObjective APIs here
} else {
// Intermediate Groups
GroupBucketIdentifier bucketId =
......@@ -179,20 +174,22 @@ public class PolicyGroupHandler extends DefaultGroupHandler {
.setMpls(MplsLabel.mplsLabel(bucketId.label()));
}
//TODO: BoS
outBuckets.add(DefaultGroupBucket.
createSelectGroupBucket(tBuilder.build()));
/*outBuckets.add(DefaultGroupBucket.
createSelectGroupBucket(tBuilder.build()));*/
}
GroupDescription desc = new
/*GroupDescription desc = new
DefaultGroupDescription(deviceId,
GroupDescription.Type.SELECT,
new GroupBuckets(outBuckets));
groupService.addGroup(desc);
groupService.addGroup(desc);*/
//TODO: Use nextObjective APIs here
}
}
return innermostGroupkey;
}
@Override
//TODO: Use nextObjective APIs to handle the group chains
/*@Override
protected void handleGroupEvent(GroupEvent event) {
if (event.type() == GroupEvent.Type.GROUP_ADDED) {
if (dependentGroups.get(event.subject().appCookie()) != null) {
......@@ -253,7 +250,7 @@ public class PolicyGroupHandler extends DefaultGroupHandler {
}
}
}
}
}*/
public PolicyGroupIdentifier generatePolicyGroupKey(String id,
List<PolicyGroupParams> params) {
......@@ -343,9 +340,10 @@ public class PolicyGroupHandler extends DefaultGroupHandler {
groupsToBeDeleted.add(bucketId.outGroup());
}
}
groupService.removeGroup(deviceId,
/*groupService.removeGroup(deviceId,
getGroupKey(innerMostGroupKey),
appId);
appId);*/
//TODO: Use nextObjective APIs here
it.remove();
}
}
......
......@@ -356,10 +356,14 @@ public final class DefaultTrafficTreatment implements TrafficTreatment {
@Override
public TrafficTreatment build() {
if (deferred.size() == 0 && immediate.size() == 0
&& table == null && !clear) {
drop();
}
//Don't add DROP instruction by default when instruction
//set is empty. This will be handled in DefaultSingleTablePipeline
//driver.
//if (deferred.size() == 0 && immediate.size() == 0
// && table == null && !clear) {
// drop();
//}
return new DefaultTrafficTreatment(deferred, immediate, table, clear);
}
......
......@@ -16,6 +16,7 @@
package org.onosproject.driver.pipeline;
import com.google.common.util.concurrent.SettableFuture;
import org.onlab.osgi.ServiceDirectory;
import org.onosproject.core.DefaultGroupId;
import org.onosproject.net.DeviceId;
......@@ -23,11 +24,14 @@ import org.onosproject.net.behaviour.Pipeliner;
import org.onosproject.net.behaviour.PipelinerContext;
import org.onosproject.net.driver.AbstractHandlerBehaviour;
import org.onosproject.net.flow.DefaultFlowRule;
import org.onosproject.net.flow.DefaultTrafficTreatment;
import org.onosproject.net.flow.FlowRule;
import org.onosproject.net.flow.FlowRuleOperations;
import org.onosproject.net.flow.FlowRuleOperationsContext;
import org.onosproject.net.flow.FlowRuleService;
import org.onosproject.net.flow.TrafficSelector;
import org.onosproject.net.flow.TrafficTreatment;
import org.onosproject.net.flow.instructions.Instructions;
import org.onosproject.net.flowobjective.FilteringObjective;
import org.onosproject.net.flowobjective.ForwardingObjective;
import org.onosproject.net.flowobjective.NextObjective;
......@@ -70,9 +74,18 @@ public class DefaultSingleTablePipeline extends AbstractHandlerBehaviour impleme
}
TrafficSelector selector = fwd.selector();
TrafficTreatment treatment = fwd.treatment();
if ((fwd.treatment().deferred().size() == 0) &&
(fwd.treatment().immediate().size() == 0) &&
(fwd.treatment().tableTransition() == null) &&
(!fwd.treatment().clearedDeferred())) {
TrafficTreatment.Builder flowTreatment = DefaultTrafficTreatment.builder();
flowTreatment.add(Instructions.createDrop());
treatment = flowTreatment.build();
}
FlowRule rule = new DefaultFlowRule(deviceId, selector,
fwd.treatment(),
treatment,
fwd.priority(), fwd.appId(),
new DefaultGroupId(fwd.id()),
fwd.timeout(), fwd.permanent());
......
/*
* 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.driver.pipeline;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.onlab.packet.Ethernet;
import org.onlab.packet.MacAddress;
import org.onosproject.core.ApplicationId;
import org.onosproject.net.behaviour.NextGroup;
import org.onosproject.net.flow.DefaultFlowRule;
import org.onosproject.net.flow.DefaultTrafficSelector;
import org.onosproject.net.flow.DefaultTrafficTreatment;
import org.onosproject.net.flow.FlowRule;
import org.onosproject.net.flow.TrafficSelector;
import org.onosproject.net.flow.TrafficTreatment;
import org.onosproject.net.flow.criteria.Criterion;
import org.onosproject.net.flow.criteria.EthCriterion;
import org.onosproject.net.flow.criteria.EthTypeCriterion;
import org.onosproject.net.flow.criteria.IPCriterion;
import org.onosproject.net.flow.criteria.MplsCriterion;
import org.onosproject.net.flow.instructions.Instruction;
import org.onosproject.net.flowobjective.FilteringObjective;
import org.onosproject.net.flowobjective.ForwardingObjective;
import org.onosproject.net.flowobjective.ObjectiveError;
import org.onosproject.net.group.Group;
import org.onosproject.net.group.GroupKey;
/**
* Spring-open driver implementation for Dell hardware switches.
*/
public class SpringOpenTTPDell extends SpringOpenTTP {
/* Table IDs to be used for Dell Open Segment Routers*/
private static final int DELL_TABLE_VLAN = 17;
private static final int DELL_TABLE_TMAC = 18;
private static final int DELL_TABLE_IPV4_UNICAST = 30;
private static final int DELL_TABLE_MPLS = 25;
private static final int DELL_TABLE_ACL = 40;
//TODO: Store this info in the distributed store.
private MacAddress deviceTMac = null;
public SpringOpenTTPDell() {
super();
vlanTableId = DELL_TABLE_VLAN;
tmacTableId = DELL_TABLE_TMAC;
ipv4UnicastTableId = DELL_TABLE_IPV4_UNICAST;
mplsTableId = DELL_TABLE_MPLS;
aclTableId = DELL_TABLE_ACL;
}
@Override
protected void setTableMissEntries() {
// No need to set table-miss-entries in Dell switches
return;
}
@Override
//Dell switches need ETH_DST based match condition in all IP table entries.
//So this method overrides the default spring-open behavior and adds
//ETH_DST match condition while pushing IP table flow rules
protected Collection<FlowRule> processSpecific(ForwardingObjective fwd) {
log.debug("Processing specific");
TrafficSelector selector = fwd.selector();
EthTypeCriterion ethType = (EthTypeCriterion) selector
.getCriterion(Criterion.Type.ETH_TYPE);
if ((ethType == null) ||
((((short) ethType.ethType()) != Ethernet.TYPE_IPV4) &&
(((short) ethType.ethType()) != Ethernet.MPLS_UNICAST))) {
log.debug("processSpecific: Unsupported "
+ "forwarding objective criteraia");
fail(fwd, ObjectiveError.UNSUPPORTED);
return Collections.emptySet();
}
TrafficSelector.Builder filteredSelectorBuilder =
DefaultTrafficSelector.builder();
int forTableId = -1;
if (((short) ethType.ethType()) == Ethernet.TYPE_IPV4) {
if (deviceTMac == null) {
log.debug("processSpecific: ETH_DST filtering "
+ "objective is not set which is required "
+ "before sending a IPv4 forwarding objective");
//TODO: Map the error to more appropriate error code.
fail(fwd, ObjectiveError.DEVICEMISSING);
return Collections.emptySet();
}
filteredSelectorBuilder = filteredSelectorBuilder
.matchEthType(Ethernet.TYPE_IPV4)
.matchEthDst(deviceTMac)
.matchIPDst(((IPCriterion) selector
.getCriterion(Criterion.Type.IPV4_DST))
.ip());
forTableId = ipv4UnicastTableId;
log.debug("processing IPv4 specific forwarding objective");
} else {
filteredSelectorBuilder = filteredSelectorBuilder
.matchEthType(Ethernet.MPLS_UNICAST)
.matchMplsLabel(((MplsCriterion)
selector.getCriterion(Criterion.Type.MPLS_LABEL)).label());
//TODO: Add Match for BoS
//if (selector.getCriterion(Criterion.Type.MPLS_BOS) != null) {
//}
forTableId = mplsTableId;
log.debug("processing MPLS specific forwarding objective");
}
TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment
.builder();
if (fwd.treatment() != null) {
for (Instruction i : fwd.treatment().allInstructions()) {
treatmentBuilder.add(i);
}
}
if (fwd.nextId() != null) {
NextGroup next = flowObjectiveStore.getNextGroup(fwd.nextId());
if (next != null) {
GroupKey key = appKryo.deserialize(next.data());
Group group = groupService.getGroup(deviceId, key);
if (group == null) {
log.warn("The group left!");
fail(fwd, ObjectiveError.GROUPMISSING);
return Collections.emptySet();
}
treatmentBuilder.group(group.id());
log.debug("Adding OUTGROUP action");
}
}
TrafficSelector filteredSelector = filteredSelectorBuilder.build();
TrafficTreatment treatment = treatmentBuilder.transition(aclTableId)
.build();
FlowRule.Builder ruleBuilder = DefaultFlowRule.builder()
.fromApp(fwd.appId()).withPriority(fwd.priority())
.forDevice(deviceId).withSelector(filteredSelector)
.withTreatment(treatment);
if (fwd.permanent()) {
ruleBuilder.makePermanent();
} else {
ruleBuilder.makeTemporary(fwd.timeout());
}
ruleBuilder.forTable(forTableId);
return Collections.singletonList(ruleBuilder.build());
}
@Override
//Dell switches need ETH_DST based match condition in all IP table entries.
//So while processing the ETH_DST based filtering objective, store
//the device MAC to be used locally to use it while pushing the IP rules.
protected List<FlowRule> processEthDstFilter(Criterion c,
FilteringObjective filt,
ApplicationId applicationId) {
List<FlowRule> rules = new ArrayList<FlowRule>();
EthCriterion e = (EthCriterion) c;
TrafficSelector.Builder selectorIp = DefaultTrafficSelector
.builder();
TrafficTreatment.Builder treatmentIp = DefaultTrafficTreatment
.builder();
// Store device termination Mac to be used in IP flow entries
deviceTMac = e.mac();
selectorIp.matchEthDst(e.mac());
selectorIp.matchEthType(Ethernet.TYPE_IPV4);
treatmentIp.transition(ipv4UnicastTableId);
FlowRule ruleIp = DefaultFlowRule.builder().forDevice(deviceId)
.withSelector(selectorIp.build())
.withTreatment(treatmentIp.build())
.withPriority(filt.priority()).fromApp(applicationId)
.makePermanent().forTable(tmacTableId).build();
log.debug("adding IP ETH rule for MAC: {}", e.mac());
rules.add(ruleIp);
TrafficSelector.Builder selectorMpls = DefaultTrafficSelector
.builder();
TrafficTreatment.Builder treatmentMpls = DefaultTrafficTreatment
.builder();
selectorMpls.matchEthDst(e.mac());
selectorMpls.matchEthType(Ethernet.MPLS_UNICAST);
treatmentMpls.transition(mplsTableId);
FlowRule ruleMpls = DefaultFlowRule.builder()
.forDevice(deviceId).withSelector(selectorMpls.build())
.withTreatment(treatmentMpls.build())
.withPriority(filt.priority()).fromApp(applicationId)
.makePermanent().forTable(tmacTableId).build();
log.debug("adding MPLS ETH rule for MAC: {}", e.mac());
rules.add(ruleMpls);
return rules;
}
}
\ No newline at end of file
......@@ -23,4 +23,12 @@
<behaviour api="org.onosproject.net.behaviour.Pipeliner"
impl="org.onosproject.driver.pipeline.OVSCorsaPipeline"/>
</driver>
</drivers>
\ No newline at end of file
<driver name="spring-open-cpqd" manufacturer="Stanford University, Ericsson Research and CPqD Research" hwVersion="OpenFlow 1.3 Reference Userspace Switch" swVersion="Apr 6 2015 16:10:53">
<behaviour api="org.onosproject.net.behaviour.Pipeliner"
impl="org.onosproject.driver.pipeline.SpringOpenTTP"/>
</driver>
<driver name="spring-open" manufacturer="Dell " hwVersion="OpenFlow switch HW ver. 1.0" swVersion="OpenFlow switch SW ver. 1.0 and 1.3">
<behaviour api="org.onosproject.net.behaviour.Pipeliner"
impl="org.onosproject.driver.pipeline.SpringOpenTTPDell"/>
</driver>
</drivers>
......
......@@ -19,10 +19,11 @@ package org.onosproject.openflow.controller.driver;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.Collections;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import org.jboss.netty.channel.Channel;
import org.onlab.packet.IpAddress;
......@@ -64,7 +65,7 @@ public abstract class AbstractOpenFlowSwitch implements OpenFlowSwitchDriver {
private OFVersion ofVersion;
protected OFPortDescStatsReply ports;
protected List<OFPortDescStatsReply> ports = new ArrayList<>();
protected boolean tableFull;
......@@ -251,7 +252,12 @@ public abstract class AbstractOpenFlowSwitch implements OpenFlowSwitchDriver {
@Override
public void setPortDescReply(OFPortDescStatsReply portDescReply) {
this.ports = portDescReply;
this.ports.add(portDescReply);
}
@Override
public void setPortDescReplies(List<OFPortDescStatsReply> portDescReplies) {
this.ports.addAll(portDescReplies);
}
@Override
......@@ -379,7 +385,10 @@ public abstract class AbstractOpenFlowSwitch implements OpenFlowSwitchDriver {
@Override
public List<OFPortDesc> getPorts() {
return Collections.unmodifiableList(ports.getEntries());
return this.ports.stream()
.flatMap((portReply) -> (portReply.getEntries().stream()))
.collect(Collectors.toList());
//return Collections.unmodifiableList(ports.getEntries());
}
@Override
......
......@@ -137,6 +137,12 @@ public interface OpenFlowSwitchDriver extends OpenFlowSwitch {
public void setPortDescReply(OFPortDescStatsReply portDescReply);
/**
* Sets the ports on this switch.
* @param portDescReplies list of port set and descriptions
*/
public void setPortDescReplies(List<OFPortDescStatsReply> portDescReplies);
/**
* Sets the features reply for this switch.
* @param featuresReply the features to set.
*/
......
......@@ -97,7 +97,8 @@ class OFChannelHandler extends IdleStateAwareChannelHandler {
// Temporary storage for switch-features and port-description
private OFFeaturesReply featuresReply;
private OFPortDescStatsReply portDescReply;
private List<OFPortDescStatsReply> portDescReplies;
//private OFPortDescStatsReply portDescReply;
// a concurrent ArrayList to temporarily store port status messages
// before we are ready to deal with them
private final CopyOnWriteArrayList<OFPortStatus> pendingPortStatusMsg;
......@@ -121,6 +122,7 @@ class OFChannelHandler extends IdleStateAwareChannelHandler {
this.controller = controller;
this.state = ChannelState.INIT;
this.pendingPortStatusMsg = new CopyOnWriteArrayList<OFPortStatus>();
this.portDescReplies = new ArrayList<OFPortDescStatsReply>();
factory13 = controller.getOFMessageFactory13();
factory10 = controller.getOFMessageFactory10();
duplicateDpidFound = Boolean.FALSE;
......@@ -294,10 +296,15 @@ class OFChannelHandler extends IdleStateAwareChannelHandler {
}
if (m.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) {
log.warn("Stats reply indicates more stats from sw {} for "
+ "port description - not currently handled",
+ "port description",
h.getSwitchInfoString());
h.portDescReplies.add((OFPortDescStatsReply)m);
return;
}
else {
h.portDescReplies.add((OFPortDescStatsReply)m);
}
h.portDescReply = (OFPortDescStatsReply) m; // temp store
//h.portDescReply = (OFPortDescStatsReply) m; // temp store
log.info("Received port desc reply for switch at {}",
h.getSwitchInfoString());
try {
......@@ -418,7 +425,8 @@ class OFChannelHandler extends IdleStateAwareChannelHandler {
h.sw.setOFVersion(h.ofVersion);
h.sw.setFeaturesReply(h.featuresReply);
h.sw.setPortDescReply(h.portDescReply);
//h.sw.setPortDescReply(h.portDescReply);
h.sw.setPortDescReplies(h.portDescReplies);
h.sw.setConnected(true);
h.sw.setChannel(h.channel);
// boolean success = h.sw.connectSwitch();
......
......@@ -255,6 +255,10 @@ public class RoleManagerTest {
}
@Override
public void setPortDescReplies(List<OFPortDescStatsReply> portDescReplies) {
}
@Override
public void setFeaturesReply(OFFeaturesReply featuresReply) {
}
......
......@@ -32,6 +32,7 @@ import org.slf4j.LoggerFactory;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
/**
* A simple implementation of a driver manager that differentiates between
......@@ -73,6 +74,14 @@ public final class DriverManager implements OpenFlowSwitchDriverFactory {
return new OFSwitchImplSpringOpenTTP(dpid, desc);
}
//TODO: Temporary work around until the configuration based
// driver manager framework is ready
if (vendor.contains("Dell")
&&
hw.contains("OpenFlow switch HW ver. 1.0")) {
return new OFSwitchImplSpringOpenTTPDellOSR(dpid, desc);
}
if (hw.startsWith("Open vSwitch")) {
if (ofv == OFVersion.OF_10) {
return new OFSwitchImplOVS10(dpid, desc);
......@@ -140,7 +149,9 @@ public final class DriverManager implements OpenFlowSwitchDriverFactory {
if (this.factory().getVersion() == OFVersion.OF_10) {
return Collections.unmodifiableList(features.getPorts());
} else {
return Collections.unmodifiableList(ports.getEntries());
return Collections.unmodifiableList(this.ports.stream()
.flatMap((portReply) -> (portReply.getEntries().stream()))
.collect(Collectors.toList()));
}
}
......
......@@ -183,7 +183,7 @@ public class OFOpticalSwitchImplLINC13 extends AbstractOpenFlowSwitch {
@Override
public List<OFPortDesc> getPorts() {
List<OFPortDesc> portEntries = new ArrayList<>();
portEntries.addAll(ports.getEntries());
portEntries.addAll(super.getPorts());
if (wPorts != null) {
portEntries.addAll(wPorts.getEntries());
}
......
......@@ -34,6 +34,8 @@ import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
//TODO: Knock-off this class as we don't need any switch/app specific
//drivers in the south bound layers.
public class OFSwitchImplSpringOpenTTP extends AbstractOpenFlowSwitch {
private OFFactory factory;
......@@ -48,8 +50,9 @@ public class OFSwitchImplSpringOpenTTP extends AbstractOpenFlowSwitch {
private static final int TABLE_MPLS = 3;
private static final int TABLE_ACL = 5;
/* Set the default values. These variables will get
* overwritten based on the switch vendor type
/*
* Set the default values. These variables will get overwritten based on the
* switch vendor type
*/
protected int vlanTableId = TABLE_VLAN;
protected int tmacTableId = TABLE_TMAC;
......@@ -64,13 +67,13 @@ public class OFSwitchImplSpringOpenTTP extends AbstractOpenFlowSwitch {
setSwitchDescription(desc);
}
@Override
public String toString() {
return "OFSwitchImplSpringOpenTTP [" + ((channel != null)
? channel.getRemoteAddress() : "?")
+ " DPID[" + ((this.getStringId() != null) ?
this.getStringId() : "?") + "]]";
return "OFSwitchImplSpringOpenTTP ["
+ ((channel != null) ? channel.getRemoteAddress() : "?")
+ " DPID["
+ ((this.getStringId() != null) ? this.getStringId() : "?")
+ "]]";
}
@Override
......@@ -78,7 +81,6 @@ public class OFSwitchImplSpringOpenTTP extends AbstractOpenFlowSwitch {
return null;
}
@Override
public void startDriverHandshake() {
log.debug("Starting driver handshake for sw {}", getStringId());
......@@ -101,8 +103,6 @@ public class OFSwitchImplSpringOpenTTP extends AbstractOpenFlowSwitch {
return driverHandshakeComplete.get();
}
@Override
public void processDriverHandshakeMessage(OFMessage m) {
if (!startDriverHandshakeCalled) {
......@@ -113,15 +113,14 @@ public class OFSwitchImplSpringOpenTTP extends AbstractOpenFlowSwitch {
}
}
@Override
public void write(OFMessage msg) {
this.channel.write(Collections.singletonList(msg));
channel.write(Collections.singletonList(msg));
}
@Override
public void write(List<OFMessage> msgs) {
this.channel.write(msgs);
channel.write(msgs);
}
@Override
......@@ -134,10 +133,10 @@ public class OFSwitchImplSpringOpenTTP extends AbstractOpenFlowSwitch {
for (OFInstruction i : instructions) {
if (i instanceof OFInstructionGotoTable) {
OFInstructionGotoTable gotoTable = (OFInstructionGotoTable) i;
TableType tid = TableType.values()[gotoTable.getTableId().getValue()];
newInstructions.add(
gotoTable.createBuilder()
.setTableId(getTableId(tid)).build());
TableType tid = TableType.values()[gotoTable.getTableId()
.getValue()];
newInstructions.add(gotoTable.createBuilder()
.setTableId(getTableId(tid)).build());
} else {
newInstructions.add(i);
}
......@@ -156,38 +155,39 @@ public class OFSwitchImplSpringOpenTTP extends AbstractOpenFlowSwitch {
@Override
public TableType getTableType(TableId tid) {
switch (tid.getValue()) {
case TABLE_IPV4_UNICAST:
return TableType.IP;
case TABLE_MPLS:
return TableType.MPLS;
case TABLE_ACL:
return TableType.ACL;
case TABLE_VLAN:
return TableType.VLAN;
case TABLE_TMAC:
return TableType.ETHER;
default:
log.error("Table type for Table id {} is not supported in the driver", tid);
return TableType.NONE;
case TABLE_IPV4_UNICAST:
return TableType.IP;
case TABLE_MPLS:
return TableType.MPLS;
case TABLE_ACL:
return TableType.ACL;
case TABLE_VLAN:
return TableType.VLAN;
case TABLE_TMAC:
return TableType.ETHER;
default:
log.error("Table type for Table id {} is not supported in the driver",
tid);
return TableType.NONE;
}
}
private TableId getTableId(TableType tableType) {
switch (tableType) {
case IP:
return TableId.of(ipv4UnicastTableId);
case MPLS:
return TableId.of(mplsTableId);
case ACL:
return TableId.of(aclTableId);
case VLAN:
return TableId.of(vlanTableId);
case ETHER:
return TableId.of(tmacTableId);
default: {
log.error("Table type {} is not supported in the driver", tableType);
return TableId.NONE;
}
case IP:
return TableId.of(ipv4UnicastTableId);
case MPLS:
return TableId.of(mplsTableId);
case ACL:
return TableId.of(aclTableId);
case VLAN:
return TableId.of(vlanTableId);
case ETHER:
return TableId.of(tmacTableId);
default: {
log.error("Table type {} is not supported in the driver", tableType);
return TableId.NONE;
}
}
}
......
/*
* 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.openflow.drivers;
import org.onosproject.openflow.controller.Dpid;
import org.projectfloodlight.openflow.protocol.OFDescStatsReply;
import org.projectfloodlight.openflow.types.TableId;
/**
* OFDescriptionStatistics Vendor (Manufacturer Desc.): Dell Make (Hardware
* Desc.) : OpenFlow 1.3 Reference Userspace Switch Model (Datapath Desc.) :
* None Software : Serial : None.
*/
//TODO: Knock-off this class as we don't need any switch/app specific
//drivers in the south bound layers.
public class OFSwitchImplSpringOpenTTPDellOSR extends OFSwitchImplSpringOpenTTP {
/* Table IDs to be used for Dell Open Segment Routers*/
private static final int DELL_TABLE_VLAN = 17;
private static final int DELL_TABLE_TMAC = 18;
private static final int DELL_TABLE_IPV4_UNICAST = 30;
private static final int DELL_TABLE_MPLS = 25;
private static final int DELL_TABLE_ACL = 40;
public OFSwitchImplSpringOpenTTPDellOSR(Dpid dpid, OFDescStatsReply desc) {
super(dpid, desc);
vlanTableId = DELL_TABLE_VLAN;
tmacTableId = DELL_TABLE_TMAC;
ipv4UnicastTableId = DELL_TABLE_IPV4_UNICAST;
mplsTableId = DELL_TABLE_MPLS;
aclTableId = DELL_TABLE_ACL;
}
@Override
public TableType getTableType(TableId tid) {
switch (tid.getValue()) {
case DELL_TABLE_IPV4_UNICAST:
return TableType.IP;
case DELL_TABLE_MPLS:
return TableType.MPLS;
case DELL_TABLE_ACL:
return TableType.ACL;
case DELL_TABLE_VLAN:
return TableType.VLAN;
case DELL_TABLE_TMAC:
return TableType.ETHER;
default:
log.error("Table type for Table id {} is not supported in the driver", tid);
return TableType.NONE;
}
}
}
\ No newline at end of file
{
"comment": " Multilayer topology description and configuration",
"restrictSwitches": true,
"restrictLinks": true,
"switchConfig":
[
{ "nodeDpid" : "of:00010001e88b9368", "name": "Dell-R1", "type": "Router_SR", "allowed": true,
"latitude": 80.80, "longitude": 90.10,
"params": { "routerIp": "192.168.0.1/32",
"routerMac": "00:01:e8:8b:93:6b",
"nodeSid": 101,
"isEdgeRouter" : true,
"subnets": [
{ "portNo": 46, "subnetIp": "10.200.1.1/24" }
]
}
},
{ "nodeDpid": "of:00010001e88b939b", "name": "Dell-R2", "type": "Router_SR", "allowed": true,
"latitude": 80.80, "longitude": 90.10,
"params": { "routerIp": "192.168.0.2/32",
"routerMac": "00:01:e8:8b:93:9e",
"nodeSid": 102,
"isEdgeRouter" : true,
"subnets": [
{ "portNo": 46, "subnetIp": "10.200.2.1/24" }
]
}
},
{ "nodeDpid": "of:00010001e88b938c", "name": "Dell-R3", "type": "Router_SR", "allowed": true,
"latitude": 80.80, "longitude": 90.10,
"params": { "routerIp": "192.168.0.3/32",
"routerMac": "00:01:e8:8b:93:8f",
"nodeSid": 103,
"isEdgeRouter" : true,
"subnets": [
{ "portNo": 46, "subnetIp": "10.200.3.1/24" }
]
}
},
{ "nodeDpid": "of:00010001e88b93ad", "name": "Dell-R4", "type": "Router_SR", "allowed": true,
"latitude": 80.80, "longitude": 90.10,
"params": { "routerIp": "192.168.0.4/32",
"routerMac": "00:01:e8:8b:93:b0",
"nodeSid": 104,
"isEdgeRouter" : true,
"subnets": [
{ "portNo": 46, "subnetIp": "10.200.4.1/24" }
]
}
},
{ "nodeDpid": "of:00010001e88b93bc", "name": "Dell-R5", "type": "Router_SR", "allowed": true,
"latitude": 80.80, "longitude": 90.10,
"params": { "routerIp": "192.168.0.5/32",
"routerMac": "00:01:e8:8b:93:bf",
"nodeSid": 105,
"isEdgeRouter" : false
}
},
{ "nodeDpid": "of:00010001e88b93c2", "name": "Dell-R6", "type": "Router_SR", "allowed": true,
"latitude": 80.80, "longitude": 90.10,
"params": { "routerIp": "192.168.0.6/32",
"routerMac": "00:01:e8:8b:93:c5",
"nodeSid": 106,
"isEdgeRouter" : false
}
},
{ "nodeDpid": "of:00010001e88b9398", "name": "Dell-R7", "type": "Router_SR", "allowed": true,
"latitude": 80.80, "longitude": 90.10,
"params": { "routerIp": "192.168.0.7/32",
"routerMac": "00:01:e8:8b:93:9b",
"nodeSid": 107,
"isEdgeRouter": false
}
},
{ "nodeDpid": "of:00010001e88b27e3", "name": "Dell-R8", "type": "Router_SR", "allowed": true,
"latitude": 80.80, "longitude": 90.10,
"params": { "routerIp": "192.168.0.8/32",
"routerMac": "00:01:e8:8b:27:e6",
"nodeSid": 108,
"isEdgeRouter": false
}
}
]
}