use of org.onosproject.segmentrouting.config.DeviceConfigNotFoundException in project trellis-control by opennetworkinglab.
the class DefaultRoutingHandler method populateEcmpRoutingRulePartial.
/**
* Populate ECMP rules for subnets from target to destination via nexthops.
*
* @param targetSw Device ID of target switch in which rules will be programmed
* @param destSw1 Device ID of final destination switch to which the rules will forward
* @param destSw2 Device ID of paired destination switch to which the rules will forward
* A null deviceId indicates packets should only be sent to destSw1
* @param nextHops Map of a set of next hops per destSw
* @param subnets Subnets to be populated. If empty, populate all configured subnets.
* @return true if it succeeds in populating rules
*/
// refactor
private boolean populateEcmpRoutingRulePartial(DeviceId targetSw, DeviceId destSw1, DeviceId destSw2, Map<DeviceId, Set<DeviceId>> nextHops, Set<IpPrefix> subnets) {
boolean result;
// If both target switch and dest switch are edge routers, then set IP
// rule for both subnet and router IP.
boolean targetIsEdge;
boolean dest1IsEdge;
Ip4Address dest1RouterIpv4, dest2RouterIpv4 = null;
Ip6Address dest1RouterIpv6, dest2RouterIpv6 = null;
try {
targetIsEdge = config.isEdgeDevice(targetSw);
dest1IsEdge = config.isEdgeDevice(destSw1);
dest1RouterIpv4 = config.getRouterIpv4(destSw1);
dest1RouterIpv6 = config.getRouterIpv6(destSw1);
if (destSw2 != null) {
dest2RouterIpv4 = config.getRouterIpv4(destSw2);
dest2RouterIpv6 = config.getRouterIpv6(destSw2);
}
} catch (DeviceConfigNotFoundException e) {
log.warn(e.getMessage() + " Aborting populateEcmpRoutingRulePartial.");
return false;
}
if (targetIsEdge && dest1IsEdge) {
List<Set<IpPrefix>> batchedSubnets;
if (subnets != null && !subnets.isEmpty()) {
batchedSubnets = Lists.<Set<IpPrefix>>newArrayList(Sets.newHashSet(subnets));
} else {
batchedSubnets = config.getBatchedSubnets(destSw1);
}
// XXX - Rethink this - ignoring routerIPs in all other switches
// even edge to edge switches
/*subnets.add(dest1RouterIpv4.toIpPrefix());
if (dest1RouterIpv6 != null) {
subnets.add(dest1RouterIpv6.toIpPrefix());
}
if (destSw2 != null && dest2RouterIpv4 != null) {
subnets.add(dest2RouterIpv4.toIpPrefix());
if (dest2RouterIpv6 != null) {
subnets.add(dest2RouterIpv6.toIpPrefix());
}
}*/
log.trace("getSubnets on {}: {}", destSw1, batchedSubnets);
for (Set<IpPrefix> prefixes : batchedSubnets) {
log.debug(". populateEcmpRoutingRulePartial in device {} towards {} {} " + "for subnets {}", targetSw, destSw1, (destSw2 != null) ? ("& " + destSw2) : "", prefixes);
if (!rulePopulator.populateIpRuleForSubnet(targetSw, prefixes, destSw1, destSw2, nextHops)) {
return false;
}
}
}
if (!targetIsEdge && dest1IsEdge) {
// MPLS rules in all non-edge target devices. These rules are for
// individual destinations, even if the dsts are part of edge-pairs.
log.debug(". populateEcmpRoutingRulePartial in device{} towards {} for " + "all MPLS rules", targetSw, destSw1);
result = rulePopulator.populateMplsRule(targetSw, destSw1, nextHops.get(destSw1), dest1RouterIpv4);
if (!result) {
return false;
}
if (dest1RouterIpv6 != null) {
int v4sid = 0, v6sid = 0;
try {
v4sid = config.getIPv4SegmentId(destSw1);
v6sid = config.getIPv6SegmentId(destSw1);
} catch (DeviceConfigNotFoundException e) {
log.warn(e.getMessage());
}
if (v4sid != v6sid) {
result = rulePopulator.populateMplsRule(targetSw, destSw1, nextHops.get(destSw1), dest1RouterIpv6);
if (!result) {
return false;
}
}
}
}
if (!targetIsEdge && !dest1IsEdge) {
// MPLS rules for inter-connected spines
// can be merged with above if, left it here for clarity
log.debug(". populateEcmpRoutingRulePartial in device{} towards {} for " + "all MPLS rules", targetSw, destSw1);
result = rulePopulator.populateMplsRule(targetSw, destSw1, nextHops.get(destSw1), dest1RouterIpv4);
if (!result) {
return false;
}
if (dest1RouterIpv6 != null) {
int v4sid = 0, v6sid = 0;
try {
v4sid = config.getIPv4SegmentId(destSw1);
v6sid = config.getIPv6SegmentId(destSw1);
} catch (DeviceConfigNotFoundException e) {
log.warn(e.getMessage());
}
if (v4sid != v6sid) {
result = rulePopulator.populateMplsRule(targetSw, destSw1, nextHops.get(destSw1), dest1RouterIpv6);
if (!result) {
return false;
}
}
}
}
// avoid loopback IP rules in edge-devices to non-edge-devices
return true;
}
use of org.onosproject.segmentrouting.config.DeviceConfigNotFoundException in project trellis-control by opennetworkinglab.
the class IcmpHandler method processIcmpv6.
// /////////////////////////////////////////
// ICMPv6 Echo/Reply Protocol //
// /////////////////////////////////////////
/**
* Process incoming ICMPv6 packet.
* If it is an ICMPv6 request to router, then sends an ICMPv6 response.
* Otherwise ignore the packet.
*
* @param eth the incoming ICMPv6 packet
* @param inPort the input port
*/
public void processIcmpv6(Ethernet eth, ConnectPoint inPort) {
DeviceId deviceId = inPort.deviceId();
IPv6 ipv6Packet = (IPv6) eth.getPayload();
ICMP6 icmp6 = (ICMP6) ipv6Packet.getPayload();
Ip6Address destinationAddress = Ip6Address.valueOf(ipv6Packet.getDestinationAddress());
Set<IpAddress> gatewayIpAddresses = config.getPortIPs(deviceId);
IpAddress routerIp;
// Only proceed with echo request
if (icmp6.getIcmpType() != ICMP6.ECHO_REQUEST) {
return;
}
try {
routerIp = config.getRouterIpv6(deviceId);
} catch (DeviceConfigNotFoundException e) {
log.warn(e.getMessage() + " Aborting processPacketIn.");
return;
}
// Get pair ip - if it exists
IpAddress pairRouterIp;
try {
DeviceId pairDeviceId = config.getPairDeviceId(deviceId);
pairRouterIp = pairDeviceId != null ? config.getRouterIpv6(pairDeviceId) : null;
} catch (DeviceConfigNotFoundException e) {
pairRouterIp = null;
}
Optional<Ip6Address> linkLocalIp = getLinkLocalIp(inPort);
// Ensure ICMP to the router IP, EUI-64 link-local IP, or gateway IP
if (destinationAddress.equals(routerIp.getIp6Address()) || (linkLocalIp.isPresent() && destinationAddress.equals(linkLocalIp.get())) || (pairRouterIp != null && destinationAddress.equals(pairRouterIp.getIp6Address())) || gatewayIpAddresses.contains(destinationAddress)) {
sendIcmpv6Response(eth, inPort);
} else {
log.trace("Ignore ICMPv6 that targets for {}", destinationAddress);
}
}
use of org.onosproject.segmentrouting.config.DeviceConfigNotFoundException in project trellis-control by opennetworkinglab.
the class IcmpHandler method processIcmp.
// ////////////////////////////////////
// ICMP Echo/Reply Protocol //
// ////////////////////////////////////
/**
* Process incoming ICMP packet.
* If it is an ICMP request to router, then sends an ICMP response.
* Otherwise ignore the packet.
*
* @param eth inbound ICMP packet
* @param inPort the input port
*/
public void processIcmp(Ethernet eth, ConnectPoint inPort) {
DeviceId deviceId = inPort.deviceId();
IPv4 ipv4Packet = (IPv4) eth.getPayload();
ICMP icmp = (ICMP) ipv4Packet.getPayload();
Ip4Address destinationAddress = Ip4Address.valueOf(ipv4Packet.getDestinationAddress());
Set<IpAddress> gatewayIpAddresses = config.getPortIPs(deviceId);
IpAddress routerIp;
// Only proceed with echo request
if (icmp.getIcmpType() != ICMP.TYPE_ECHO_REQUEST) {
return;
}
try {
routerIp = config.getRouterIpv4(deviceId);
} catch (DeviceConfigNotFoundException e) {
log.warn(e.getMessage() + " Aborting processPacketIn.");
return;
}
// Get pair ip - if it exists
IpAddress pairRouterIp;
try {
DeviceId pairDeviceId = config.getPairDeviceId(deviceId);
pairRouterIp = pairDeviceId != null ? config.getRouterIpv4(pairDeviceId) : null;
} catch (DeviceConfigNotFoundException e) {
pairRouterIp = null;
}
// ICMP to the router IP or gateway IP
if (destinationAddress.equals(routerIp.getIp4Address()) || (pairRouterIp != null && destinationAddress.equals(pairRouterIp.getIp4Address())) || gatewayIpAddresses.contains(destinationAddress)) {
sendIcmpResponse(eth, inPort);
} else {
log.trace("Ignore ICMP that targets for {}", destinationAddress);
}
}
use of org.onosproject.segmentrouting.config.DeviceConfigNotFoundException in project trellis-control by opennetworkinglab.
the class IcmpHandler method sendPacketOut.
/**
* Utility function to send packet out.
*
* @param outport the output port
* @param payload the packet to send
* @param destSid the segment id of the dest device
* @param destIpAddress the destination ip address
* @param allowedHops the hop limit/ttl
*/
private void sendPacketOut(ConnectPoint outport, Ethernet payload, int destSid, IpAddress destIpAddress, byte allowedHops) {
int origSid;
try {
if (destIpAddress.isIp4()) {
origSid = config.getIPv4SegmentId(outport.deviceId());
} else {
origSid = config.getIPv6SegmentId(outport.deviceId());
}
} catch (DeviceConfigNotFoundException e) {
log.warn(e.getMessage() + " Aborting sendPacketOut");
return;
}
if (destSid == -1 || origSid == destSid || srManager.interfaceService.isConfigured(outport)) {
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(outport.port()).build();
OutboundPacket packet = new DefaultOutboundPacket(outport.deviceId(), treatment, ByteBuffer.wrap(payload.serialize()));
log.trace("Sending packet {} to {}", payload, outport);
srManager.packetService.emit(packet);
} else {
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(outport.port()).build();
payload.setEtherType(Ethernet.MPLS_UNICAST);
MPLS mplsPkt = new MPLS();
mplsPkt.setLabel(destSid);
mplsPkt.setTtl(allowedHops);
mplsPkt.setPayload(payload.getPayload());
payload.setPayload(mplsPkt);
OutboundPacket packet = new DefaultOutboundPacket(outport.deviceId(), treatment, ByteBuffer.wrap(payload.serialize()));
log.trace("Sending packet {} to {}", payload, outport);
srManager.packetService.emit(packet);
}
}
use of org.onosproject.segmentrouting.config.DeviceConfigNotFoundException in project trellis-control by opennetworkinglab.
the class RoutingRulePopulator method updateDefaultRouteBlackhole.
private void updateDefaultRouteBlackhole(DeviceId deviceId, IpPrefix address, boolean install) {
try {
if (srManager.deviceConfiguration.isEdgeDevice(deviceId)) {
TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder();
if (address.isIp4()) {
sbuilder.matchIPDst(address);
sbuilder.matchEthType(EthType.EtherType.IPV4.ethType().toShort());
} else {
sbuilder.matchIPv6Dst(address);
sbuilder.matchEthType(EthType.EtherType.IPV6.ethType().toShort());
}
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
tBuilder.wipeDeferred();
ForwardingObjective.Builder fob = DefaultForwardingObjective.builder();
fob.withFlag(Flag.SPECIFIC).withSelector(sbuilder.build()).withTreatment(tBuilder.build()).withPriority(getPriorityFromPrefix(address)).fromApp(srManager.appId).makePermanent();
log.debug("{} blackhole forwarding objectives for dev: {}", install ? "Installing" : "Removing", deviceId);
ObjectiveContext context = new DefaultObjectiveContext((objective) -> log.debug("Forward for {} {}", deviceId, install ? "installed" : "removed"), (objective, error) -> log.warn("Failed to {} forward for {}: {}", install ? "install" : "remove", deviceId, error));
if (install) {
srManager.flowObjectiveService.forward(deviceId, fob.add(context));
} else {
srManager.flowObjectiveService.forward(deviceId, fob.remove(context));
}
}
} catch (DeviceConfigNotFoundException e) {
log.info("Not populating blackhole for un-configured device {}", deviceId);
}
}
Aggregations