use of org.onlab.packet.IPv4 in project onos by opennetworkinglab.
the class PimInterface method sendJoinPrune.
private void sendJoinPrune(McastRoute route, RouteData data, boolean join) {
PIMJoinPrune jp = new PIMJoinPrune();
jp.addJoinPrune(route.source().toIpPrefix(), route.group().toIpPrefix(), join);
jp.setHoldTime(join ? (short) Math.floor(JOIN_PERIOD * HOLD_TIME_MULTIPLIER) : 0);
jp.setUpstreamAddr(new PIMAddrUnicast(data.ipAddress.toString()));
PIM pim = new PIM();
pim.setPIMType(PIM.TYPE_JOIN_PRUNE_REQUEST);
pim.setPayload(jp);
IPv4 ipv4 = new IPv4();
ipv4.setDestinationAddress(PIM.PIM_ADDRESS.getIp4Address().toInt());
ipv4.setSourceAddress(getIpAddress().getIp4Address().toInt());
ipv4.setProtocol(IPv4.PROTOCOL_PIM);
ipv4.setTtl((byte) 1);
ipv4.setDiffServ((byte) 0xc0);
ipv4.setPayload(pim);
Ethernet eth = new Ethernet();
eth.setSourceMACAddress(onosInterface.mac());
eth.setDestinationMACAddress(MacAddress.valueOf("01:00:5E:00:00:0d"));
eth.setEtherType(Ethernet.TYPE_IPV4);
eth.setPayload(ipv4);
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(onosInterface.connectPoint().port()).build();
packetService.emit(new DefaultOutboundPacket(onosInterface.connectPoint().deviceId(), treatment, ByteBuffer.wrap(eth.serialize())));
data.timestamp = System.currentTimeMillis();
}
use of org.onlab.packet.IPv4 in project onos by opennetworkinglab.
the class PimInterface method processJoinPrune.
/**
* Process an incoming PIM JoinPrune message.
*
* @param ethPkt the Ethernet packet header.
*/
public void processJoinPrune(Ethernet ethPkt) {
IPv4 ip = (IPv4) ethPkt.getPayload();
checkNotNull(ip);
PIM pim = (PIM) ip.getPayload();
checkNotNull(pim);
PIMJoinPrune jpHdr = (PIMJoinPrune) pim.getPayload();
checkNotNull(jpHdr);
/*
* The Join/Prune messages are grouped by Group address. We'll walk each group address
* where we will possibly have to walk a list of source address for the joins and prunes.
*/
Collection<PIMJoinPruneGroup> jpgs = jpHdr.getJoinPrunes();
for (PIMJoinPruneGroup jpg : jpgs) {
IpPrefix gpfx = jpg.getGroup();
// Walk the joins first.
for (IpPrefix spfx : jpg.getJoins().values()) {
// We may need
}
for (IpPrefix spfx : jpg.getPrunes().values()) {
// TODO: this is where we many need to remove multi-cast state and possibly intents.
}
}
}
use of org.onlab.packet.IPv4 in project onos by opennetworkinglab.
the class DirectHostManager method transformAndSend.
private void transformAndSend(IP ip, short ethType, Interface egressInterface, MacAddress macAddress) {
// Base processing for IPv4
if (ethType == Ethernet.TYPE_IPV4) {
IPv4 ipv4 = (IPv4) ip;
ipv4.setTtl((byte) (ipv4.getTtl() - 1));
ipv4.setChecksum((short) 0);
// Base processing for IPv6.
} else {
IPv6 ipv6 = (IPv6) ip;
ipv6.setHopLimit((byte) (ipv6.getHopLimit() - 1));
ipv6.resetChecksum();
}
// Sends and serializes.
Ethernet eth = new Ethernet();
eth.setDestinationMACAddress(macAddress);
eth.setSourceMACAddress(egressInterface.mac());
eth.setEtherType(ethType);
eth.setPayload(ip);
if (!egressInterface.vlan().equals(VlanId.NONE)) {
eth.setVlanID(egressInterface.vlan().toShort());
}
send(eth, egressInterface.connectPoint());
}
use of org.onlab.packet.IPv4 in project onos by opennetworkinglab.
the class SimpleFabricRouting method checkVirtualGatewayIpPacket.
/**
* handle Packet with dstIp=virtualGatewayIpAddresses.
* returns true(handled) or false(not for virtual gateway)
*/
private boolean checkVirtualGatewayIpPacket(InboundPacket pkt, IpAddress srcIp, IpAddress dstIp) {
// assume valid
Ethernet ethPkt = pkt.parsed();
MacAddress mac = simpleFabric.vMacForIp(dstIp);
if (mac == null || !simpleFabric.isVirtualGatewayMac(ethPkt.getDestinationMAC())) {
/* Destination MAC should be any of virtual gateway macs */
return false;
} else if (dstIp.isIp4()) {
IPv4 ipv4Packet = (IPv4) ethPkt.getPayload();
if (ipv4Packet.getProtocol() == IPv4.PROTOCOL_ICMP) {
ICMP icmpPacket = (ICMP) ipv4Packet.getPayload();
if (icmpPacket.getIcmpType() == ICMP.TYPE_ECHO_REQUEST) {
log.info("IPV4 ICMP ECHO request to virtual gateway: " + "srcIp={} dstIp={} proto={}", srcIp, dstIp, ipv4Packet.getProtocol());
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(pkt.receivedFrom().port()).build();
OutboundPacket packet = new DefaultOutboundPacket(pkt.receivedFrom().deviceId(), treatment, ByteBuffer.wrap(icmpPacket.buildIcmpReply(pkt.parsed()).serialize()));
packetService.emit(packet);
return true;
}
}
log.warn("IPV4 packet to virtual gateway dropped: " + "srcIp={} dstIp={} proto={}", srcIp, dstIp, ipv4Packet.getProtocol());
return true;
} else if (dstIp.isIp6()) {
// TODO: not tested yet (2017-07-20)
IPv6 ipv6Packet = (IPv6) ethPkt.getPayload();
if (ipv6Packet.getNextHeader() == IPv6.PROTOCOL_ICMP6) {
ICMP6 icmp6Packet = (ICMP6) ipv6Packet.getPayload();
if (icmp6Packet.getIcmpType() == ICMP6.ECHO_REQUEST) {
log.info("IPV6 ICMP6 ECHO request to virtual gateway: srcIp={} dstIp={} nextHeader={}", srcIp, dstIp, ipv6Packet.getNextHeader());
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(pkt.receivedFrom().port()).build();
OutboundPacket packet = new DefaultOutboundPacket(pkt.receivedFrom().deviceId(), treatment, ByteBuffer.wrap(icmp6Packet.buildIcmp6Reply(pkt.parsed()).serialize()));
packetService.emit(packet);
return true;
}
}
log.warn("IPV6 packet to virtual gateway dropped: srcIp={} dstIp={} nextHeader={}", srcIp, dstIp, ipv6Packet.getNextHeader());
return true;
}
// unknown traffic
return false;
}
use of org.onlab.packet.IPv4 in project onos by opennetworkinglab.
the class TunnellingConnectivityManager method forward.
/**
* Forwards a BGP packet to another connect point.
*
* @param context the packet context of the incoming packet
*/
private void forward(PacketContext context) {
ConnectPoint outputPort = null;
IPv4 ipv4 = (IPv4) context.inPacket().parsed().getPayload();
IpAddress dstAddress = IpAddress.valueOf(ipv4.getDestinationAddress());
if (context.inPacket().receivedFrom().equals(bgpSpeaker.connectPoint())) {
if (bgpSpeaker.peers().contains(dstAddress)) {
Interface intf = interfaceService.getMatchingInterface(dstAddress);
if (intf != null) {
outputPort = intf.connectPoint();
}
}
} else {
Set<Interface> interfaces = interfaceService.getInterfacesByPort(context.inPacket().receivedFrom());
if (interfaces.stream().flatMap(intf -> intf.ipAddressesList().stream()).anyMatch(ia -> ia.ipAddress().equals(dstAddress))) {
outputPort = bgpSpeaker.connectPoint();
}
}
if (outputPort != null) {
TrafficTreatment t = DefaultTrafficTreatment.builder().setOutput(outputPort.port()).build();
OutboundPacket o = new DefaultOutboundPacket(outputPort.deviceId(), t, context.inPacket().unparsed());
packetService.emit(o);
}
}
Aggregations