use of org.onosproject.segmentrouting.config.DeviceConfigNotFoundException in project trellis-control by opennetworkinglab.
the class LinkHandler method updateHostPorts.
/**
* Administratively enables or disables edge ports if the link that was
* added or removed was the only uplink port from an edge device. Edge ports
* that belong to dual-homed hosts are always processed. In addition,
* single-homed host ports are optionally processed depending on the
* singleHomedDown property.
*
* @param link the link to be processed
* @param added true if link was added, false if link was removed
*/
private void updateHostPorts(Link link, boolean added) {
// Topology has only a single pair of leaves
if (srManager.getInfraDeviceIds().isEmpty()) {
log.debug("No spine configured. Not updating edge port for {} {}", link, added ? "add" : "remove");
return;
}
DeviceConfiguration devConfig = srManager.deviceConfiguration;
if (added) {
try {
if (!devConfig.isEdgeDevice(link.src().deviceId()) || devConfig.isEdgeDevice(link.dst().deviceId())) {
return;
}
} catch (DeviceConfigNotFoundException e) {
log.warn("Unable to determine if link is a valid uplink" + e.getMessage());
}
// re-enable previously disabled ports on this edge-device if any
Set<PortNumber> p = downedPortStore.remove(link.src().deviceId());
if (p != null) {
log.warn("Link src {} --> dst {} added is an edge-device uplink, " + "enabling dual homed ports if any: {}", link.src().deviceId(), link.dst().deviceId(), (p.isEmpty()) ? "no ports" : p);
p.forEach(pnum -> srManager.deviceAdminService.changePortState(link.src().deviceId(), pnum, true));
}
} else {
// If the device does not have a pair device - skip
DeviceId dev = link.src().deviceId();
if (getPairDeviceIdOrNull(dev) == null) {
log.info("Device {} does not have pair device " + "not disabling access port", dev);
return;
}
// Verify if last uplink
if (!lastUplink(link)) {
return;
}
// find dual homed hosts on this dev to disable
Set<PortNumber> dp = srManager.hostHandler.getDualHomedHostPorts(dev);
log.warn("Link src {} --> dst {} removed was the last uplink, " + "disabling dual homed ports: {}", dev, link.dst().deviceId(), (dp.isEmpty()) ? "no ports" : dp);
dp.forEach(pnum -> srManager.deviceAdminService.changePortState(dev, pnum, false));
if (srManager.singleHomedDown) {
// get all configured ports and down them if they haven't already
// been downed
srManager.deviceService.getPorts(dev).stream().filter(p -> p.isEnabled() && !dp.contains(p.number())).filter(p -> srManager.interfaceService.isConfigured(new ConnectPoint(dev, p.number()))).filter(p -> !srManager.deviceConfiguration.isPairLocalPort(dev, p.number())).forEach(p -> {
log.warn("Last uplink gone src {} -> dst {} .. removing " + "configured port {}", p.number());
srManager.deviceAdminService.changePortState(dev, p.number(), false);
dp.add(p.number());
});
}
if (!dp.isEmpty()) {
// update global store
Set<PortNumber> p = downedPortStore.get(dev);
if (p == null) {
p = dp;
} else {
p.addAll(dp);
}
downedPortStore.put(link.src().deviceId(), p);
}
}
}
use of org.onosproject.segmentrouting.config.DeviceConfigNotFoundException in project trellis-control by opennetworkinglab.
the class LinkHandler method avoidLink.
/**
* Determines if the given link should be avoided in routing calculations by
* policy or design.
*
* @param link the infrastructure link being queried
* @return true if link should be avoided
*/
boolean avoidLink(Link link) {
// XXX currently only avoids all pair-links. In the future can be
// extended to avoid any generic link
DeviceId src = link.src().deviceId();
PortNumber srcPort = link.src().port();
DeviceConfiguration devConfig = srManager.deviceConfiguration;
if (devConfig == null || !devConfig.isConfigured(src)) {
log.warn("Device {} not configured..cannot avoid link {}", src, link);
return false;
}
DeviceId pairDev;
PortNumber pairLocalPort, pairRemotePort = null;
try {
pairDev = devConfig.getPairDeviceId(src);
pairLocalPort = devConfig.getPairLocalPort(src);
if (pairDev != null) {
pairRemotePort = devConfig.getPairLocalPort(pairDev);
}
} catch (DeviceConfigNotFoundException e) {
log.warn("Pair dev for dev {} not configured..cannot avoid link {}", src, link);
return false;
}
return srcPort.equals(pairLocalPort) && link.dst().deviceId().equals(pairDev) && link.dst().port().equals(pairRemotePort);
}
use of org.onosproject.segmentrouting.config.DeviceConfigNotFoundException in project trellis-control by opennetworkinglab.
the class RouteHandler method processSingleLeafPairIfNeeded.
protected boolean processSingleLeafPairIfNeeded(Set<ConnectPoint> locations, ConnectPoint location, IpPrefix prefix, VlanId nextHopVlan) {
// Special handling for single leaf pair
if (!srManager.getInfraDeviceIds().isEmpty()) {
log.debug("Spine found. Skip single leaf pair handling");
return false;
}
Optional<DeviceId> pairDeviceId = srManager.getPairDeviceId(location.deviceId());
if (pairDeviceId.isEmpty()) {
log.debug("Pair device of {} not found", location.deviceId());
return false;
}
if (locations.stream().anyMatch(l -> l.deviceId().equals(pairDeviceId.get()))) {
log.debug("Pair device has a next hop available. Leave it as is.");
return false;
}
Optional<PortNumber> pairRemotePort = srManager.getPairLocalPort(pairDeviceId.get());
if (pairRemotePort.isEmpty()) {
log.debug("Pair remote port of {} not found", pairDeviceId.get());
return false;
}
// Use routerMac of the pair device as the next hop
MacAddress effectiveMac;
try {
effectiveMac = srManager.getDeviceMacAddress(location.deviceId());
} catch (DeviceConfigNotFoundException e) {
log.warn("Abort populateRoute on pair device {}. routerMac not found", pairDeviceId);
return false;
}
// Since the pairLocalPort is trunk port, use assigned vlan of original port
// when the host is untagged
VlanId effectiveVlan = Optional.ofNullable(srManager.getInternalVlanId(location)).orElse(nextHopVlan);
log.debug("Single leaf pair. populateRoute {}/{}, {}, {}, {}", pairDeviceId, pairRemotePort, prefix, effectiveMac, effectiveVlan);
srManager.defaultRoutingHandler.populateRoute(pairDeviceId.get(), prefix, effectiveMac, effectiveVlan, pairRemotePort.get(), false);
return true;
}
use of org.onosproject.segmentrouting.config.DeviceConfigNotFoundException in project trellis-control by opennetworkinglab.
the class McastUtils method getRouterMac.
/**
* Get router mac using application config and the connect point.
*
* @param deviceId the device id
* @param port the port number
* @return the router mac if the port is configured, otherwise null
*/
private MacAddress getRouterMac(DeviceId deviceId, PortNumber port) {
// Do nothing if the port is configured as suppressed
ConnectPoint connectPoint = new ConnectPoint(deviceId, port);
SegmentRoutingAppConfig appConfig = srManager.cfgService.getConfig(srManager.appId(), SegmentRoutingAppConfig.class);
if (appConfig != null && appConfig.suppressSubnet().contains(connectPoint)) {
log.info("Ignore suppressed port {}", connectPoint);
return MacAddress.NONE;
}
// Get the router mac using the device configuration
MacAddress routerMac;
try {
routerMac = srManager.deviceConfiguration().getDeviceMac(deviceId);
} catch (DeviceConfigNotFoundException dcnfe) {
log.warn("Failed to get device MAC since the device {} is not configured", deviceId);
return null;
}
return routerMac;
}
use of org.onosproject.segmentrouting.config.DeviceConfigNotFoundException in project trellis-control by opennetworkinglab.
the class PolicyManager method redirectPolicyNextObjective.
private NextObjective.Builder redirectPolicyNextObjective(DeviceId srcDevice, RedirectPolicy redirectPolicy) {
Set<Link> egressLinks = linkService.getDeviceEgressLinks(srcDevice);
Map<ConnectPoint, DeviceId> egressPortsToEnforce = Maps.newHashMap();
List<DeviceId> edgeDevices = getEdgeDeviceIds();
egressLinks.stream().filter(link -> redirectPolicy.spinesToEnforce().contains(link.dst().deviceId()) && !edgeDevices.contains(link.dst().deviceId())).forEach(link -> egressPortsToEnforce.put(link.src(), link.dst().deviceId()));
// No ports no friend
if (egressPortsToEnforce.isEmpty()) {
log.warn("There are no port available for the REDIRECT policy {}", redirectPolicy.policyId());
return null;
}
// We need to add a treatment for each valid egress port. The treatment
// requires to set src and dst mac address and set the egress port. We are
// deliberately not providing the metadata to prevent the programming of
// some tables which are already controlled by SegmentRouting or are unnecessary
int nextId = flowObjectiveService.allocateNextId();
DefaultNextObjective.Builder builder = DefaultNextObjective.builder().withId(nextId).withType(NextObjective.Type.HASHED).fromApp(appId);
MacAddress srcDeviceMac;
try {
srcDeviceMac = getDeviceMacAddress(srcDevice);
} catch (DeviceConfigNotFoundException e) {
log.warn(e.getMessage() + " Aborting installation REDIRECT policy {}", redirectPolicy.policyId());
return null;
}
MacAddress neigborDeviceMac;
TrafficTreatment.Builder tBuilder;
for (Map.Entry<ConnectPoint, DeviceId> entry : egressPortsToEnforce.entrySet()) {
try {
neigborDeviceMac = getDeviceMacAddress(entry.getValue());
} catch (DeviceConfigNotFoundException e) {
log.warn(e.getMessage() + " Aborting installation REDIRECT policy {}", redirectPolicy.policyId());
return null;
}
tBuilder = DefaultTrafficTreatment.builder().setEthSrc(srcDeviceMac).setEthDst(neigborDeviceMac).setOutput(entry.getKey().port());
builder.addTreatment(tBuilder.build());
}
return builder;
}
Aggregations