use of org.onlab.packet.Ip4Address in project trellis-control by opennetworkinglab.
the class RoutingRulePopulator method manageIpPunts.
/**
* Creates or removes forwarding objectives ( packet-requests ) to punt all IP packets, destined to the
* router's port IP addresses, to the controller. Note that the input
* port should not be matched on, as these packets can come from any input.
* Furthermore, these are applied only by the master instance.
*
* @param deviceId the switch dpid for the router
* @param request true to create a packet request, false to remove
*/
void manageIpPunts(DeviceId deviceId, boolean request) {
Ip4Address routerIpv4, pairRouterIpv4 = null;
Ip6Address routerIpv6, routerLinkLocalIpv6, pairRouterIpv6 = null;
try {
routerIpv4 = config.getRouterIpv4(deviceId);
routerIpv6 = config.getRouterIpv6(deviceId);
routerLinkLocalIpv6 = Ip6Address.valueOf(IPv6.getLinkLocalAddress(config.getDeviceMac(deviceId).toBytes()));
if (config.isPairedEdge(deviceId)) {
pairRouterIpv4 = config.getRouterIpv4(config.getPairDeviceId(deviceId));
pairRouterIpv6 = config.getRouterIpv6(config.getPairDeviceId(deviceId));
}
} catch (DeviceConfigNotFoundException e) {
log.warn(e.getMessage() + " Aborting manageIpPunts.");
return;
}
if (request && !srManager.shouldProgram(deviceId)) {
log.debug("Not installing port-IP punts - not handling programming for dev:{} ", deviceId);
return;
}
Set<IpAddress> allIps = new HashSet<>(config.getPortIPs(deviceId));
allIps.add(routerIpv4);
if (routerIpv6 != null) {
allIps.add(routerIpv6);
allIps.add(routerLinkLocalIpv6);
}
if (pairRouterIpv4 != null) {
allIps.add(pairRouterIpv4);
}
if (pairRouterIpv6 != null) {
allIps.add(pairRouterIpv6);
}
for (IpAddress ipaddr : allIps) {
manageSingleIpPunts(deviceId, ipaddr, request);
}
}
use of org.onlab.packet.Ip4Address in project trellis-control by opennetworkinglab.
the class IcmpHandler method sendIcmpResponse.
/**
* Sends an ICMP reply message.
*
* @param icmpRequest the original ICMP request
* @param outport the output port where the ICMP reply should be sent to
*/
private void sendIcmpResponse(Ethernet icmpRequest, ConnectPoint outport) {
Ethernet icmpReplyEth = ICMP.buildIcmpReply(icmpRequest);
IPv4 icmpRequestIpv4 = (IPv4) icmpRequest.getPayload();
IPv4 icmpReplyIpv4 = (IPv4) icmpReplyEth.getPayload();
Ip4Address destIpAddress = Ip4Address.valueOf(icmpRequestIpv4.getSourceAddress());
// Get the available connect points
Set<ConnectPoint> destConnectPoints = config.getConnectPointsForASubnetHost(destIpAddress);
// Select a router
Ip4Address destRouterAddress = selectRouterIp4Address(destIpAddress, outport, destConnectPoints);
// Lookup the route store for the nexthop instead.
if (destRouterAddress == null) {
Optional<DeviceId> deviceId = srManager.routeService.longestPrefixLookup(destIpAddress).map(srManager::nextHopLocations).flatMap(locations -> locations.stream().findFirst()).map(ConnectPoint::deviceId);
if (deviceId.isPresent()) {
try {
destRouterAddress = config.getRouterIpv4(deviceId.get());
} catch (DeviceConfigNotFoundException e) {
log.warn("Device config for {} not found. Abort ICMP processing", deviceId);
return;
}
}
}
int destSid = config.getIPv4SegmentId(destRouterAddress);
if (destSid < 0) {
log.warn("Failed to lookup SID of the switch that {} attaches to. " + "Unable to process ICMP request.", destIpAddress);
return;
}
sendPacketOut(outport, icmpReplyEth, destSid, destIpAddress, icmpReplyIpv4.getTtl());
}
use of org.onlab.packet.Ip4Address in project trellis-control by opennetworkinglab.
the class IpHandler method forwardPackets.
/**
* Forwards IP packets in the buffer to the destination IP address.
* It is called when the controller finds the destination MAC address
* via ARP responses.
*
* @param deviceId switch device ID
* @param destIpAddress destination IP address
*/
public void forwardPackets(DeviceId deviceId, Ip4Address destIpAddress) {
if (ipPacketQueue.get(destIpAddress) == null) {
return;
}
for (IP ipPacket : ipPacketQueue.get(destIpAddress)) {
if (ipPacket.getVersion() == ((byte) 4)) {
IPv4 ipv4Packet = (IPv4) ipPacket;
Ip4Address destAddress = Ip4Address.valueOf(ipv4Packet.getDestinationAddress());
if (config.inSameSubnet(deviceId, destAddress)) {
ipv4Packet.setTtl((byte) (ipv4Packet.getTtl() - 1));
ipv4Packet.setChecksum((short) 0);
for (Host dest : srManager.hostService.getHostsByIp(destIpAddress)) {
Ethernet eth = new Ethernet();
eth.setDestinationMACAddress(dest.mac());
try {
eth.setSourceMACAddress(config.getDeviceMac(deviceId));
} catch (DeviceConfigNotFoundException e) {
log.warn(e.getMessage() + " Skipping forwardPackets for this destination.");
continue;
}
eth.setEtherType(Ethernet.TYPE_IPV4);
eth.setPayload(ipv4Packet);
forwardToHost(deviceId, eth, dest);
ipPacketQueue.get(destIpAddress).remove(ipPacket);
}
ipPacketQueue.get(destIpAddress).remove(ipPacket);
}
}
}
}
use of org.onlab.packet.Ip4Address in project trellis-control by opennetworkinglab.
the class ArpHandler method isArpForRouter.
private boolean isArpForRouter(NeighbourMessageContext pkt) {
Ip4Address targetProtocolAddress = pkt.target().getIp4Address();
Set<IpAddress> gatewayIpAddresses = null;
try {
if (targetProtocolAddress.equals(config.getRouterIpv4(pkt.inPort().deviceId()))) {
return true;
}
gatewayIpAddresses = config.getPortIPs(pkt.inPort().deviceId());
} catch (DeviceConfigNotFoundException e) {
log.warn(e.getMessage() + " Aborting check for router IP in processing arp");
}
if (gatewayIpAddresses != null && gatewayIpAddresses.contains(targetProtocolAddress)) {
return true;
}
return false;
}
use of org.onlab.packet.Ip4Address in project aaa by opencord.
the class PortBasedRadiusCommunicator method handleArpPacketFromServer.
/**
* Handles ARP packets from RADIUS server.
*
* @param context Context for the packet
*/
private void handleArpPacketFromServer(PacketContext context) {
// Extract the original Ethernet frame from the packet information
InboundPacket pkt = context.inPacket();
Ethernet ethPkt = pkt.parsed();
if (ethPkt == null) {
return;
}
ARP arpPacket = (ARP) ethPkt.getPayload();
Ip4Address targetAddress = Ip4Address.valueOf(arpPacket.getTargetProtocolAddress());
String serialNo = ipToSnMap.get(targetAddress);
if (serialNo == null) {
log.info("No mapping found for ARP reply, target address {}", targetAddress);
return;
}
if (subsService == null) {
log.warn(SADIS_NOT_RUNNING);
return;
}
MacAddress senderMac = subsService.get(serialNo).hardwareIdentifier();
if (senderMac == null) {
log.warn("ARP resolution, MAC address not found for SN {}", serialNo);
return;
}
ARP arpReply = (ARP) arpPacket.clone();
arpReply.setOpCode(ARP.OP_REPLY);
arpReply.setTargetProtocolAddress(arpPacket.getSenderProtocolAddress());
arpReply.setTargetHardwareAddress(arpPacket.getSenderHardwareAddress());
arpReply.setSenderProtocolAddress(arpPacket.getTargetProtocolAddress());
arpReply.setSenderHardwareAddress(senderMac.toBytes());
log.debug("AAA Manager: Query for ARP of IP : {}", arpPacket.getTargetProtocolAddress());
// Ethernet Frame.
Ethernet ethReply = new Ethernet();
ethReply.setSourceMACAddress(senderMac);
ethReply.setDestinationMACAddress(ethPkt.getSourceMAC());
ethReply.setEtherType(Ethernet.TYPE_ARP);
ethReply.setVlanID(radiusVlanID);
ethReply.setPriorityCode(ethPkt.getPriorityCode());
ethReply.setPayload(arpReply);
sendFromRadiusServerPort(ethReply);
}
Aggregations