protected Ip4Address getIp(Host host) { return host.ipAddresses().stream().findFirst().get().getIp4Address(); }
@Override public void writeTo(ByteBuf byteBuf, LispIpv4Address address) throws LispWriterException { byte[] ipByte = address.getAddress().getIp4Address().toOctets(); byteBuf.writeBytes(ipByte); } }
@Override protected boolean validChecksum() { int accumulation = (((int) this.igmpType) & 0xff) << 8; accumulation += ((int) this.resField) & 0xff; if (!groups.isEmpty()) { int ipaddr = groups.get(0).getGaddr().getIp4Address().toInt(); accumulation += (ipaddr >> 16) & 0xffff; accumulation += ipaddr & 0xffff; } accumulation = (accumulation >> 16 & 0xffff) + (accumulation & 0xffff); short checksum = (short) (~accumulation & 0xffff); return checksum == this.checksum; } }
/** * Gets the {@link Ip4Prefix} view of the IP prefix. * * @return the {@link Ip4Prefix} view of the IP prefix if it is IPv4, * otherwise null */ public Ip4Prefix getIp4Prefix() { if (!isIp4()) { return null; } // Return this object itself if it is already instance of Ip4Prefix if (this instanceof Ip4Prefix) { return (Ip4Prefix) this; } return Ip4Prefix.valueOf(address.getIp4Address(), prefixLength); }
bb.putInt(0); } else { bb.putInt(groups.get(0).getGaddr().getIp4Address().toInt());
/** * Check if this IP address is a link-local address. * * @return true if this address is a link-local address */ public boolean isLinkLocal() { return isIp4() ? Ip4Prefix.IPV4_LINK_LOCAL_PREFIX.contains(this.getIp4Address()) : Ip6Prefix.IPV6_LINK_LOCAL_PREFIX.contains(this.getIp6Address()); }
/** * Check if this IP address is a multicast address. * * @return true if this address is a multicast address */ public boolean isMulticast() { return isIp4() ? Ip4Prefix.IPV4_MULTICAST_PREFIX.contains(this.getIp4Address()) : Ip6Prefix.IPV6_MULTICAST_PREFIX.contains(this.getIp6Address()); }
pushGlobalNodeLabel(getPcepClient(otherDevId), labelId, IpAddress.valueOf(specificLsrId).getIp4Address().toInt(), PcepLabelOp.REMOVE, false);
private LinkedList<PcepValueType> createEroSubObj(Path path) { LinkedList<PcepValueType> subObjects = new LinkedList<>(); List<Link> links = path.links(); ConnectPoint source = null; ConnectPoint destination = null; IpAddress ipDstAddress = null; IpAddress ipSrcAddress = null; PcepValueType subObj = null; long portNo; for (Link link : links) { source = link.src(); if (!(source.equals(destination))) { //set IPv4SubObject for ERO object portNo = source.port().toLong(); portNo = ((portNo & IDENTIFIER_SET) == IDENTIFIER_SET) ? portNo & SET : portNo; ipSrcAddress = Ip4Address.valueOf((int) portNo); subObj = new IPv4SubObject(ipSrcAddress.getIp4Address().toInt()); subObjects.add(subObj); } destination = link.dst(); portNo = destination.port().toLong(); portNo = ((portNo & IDENTIFIER_SET) == IDENTIFIER_SET) ? portNo & SET : portNo; ipDstAddress = Ip4Address.valueOf((int) portNo); subObj = new IPv4SubObject(ipDstAddress.getIp4Address().toInt()); subObjects.add(subObj); } return subObjects; }
private OFAction buildL3Modification(Instruction i) { L3ModificationInstruction l3m = (L3ModificationInstruction) i; ModIPInstruction ip; Ip4Address ip4; switch (l3m.subtype()) { case IPV4_SRC: ip = (ModIPInstruction) i; ip4 = ip.ip().getIp4Address(); return factory().actions().setNwSrc(IPv4Address.of(ip4.toInt())); case IPV4_DST: ip = (ModIPInstruction) i; ip4 = ip.ip().getIp4Address(); return factory().actions().setNwDst(IPv4Address.of(ip4.toInt())); default: log.warn("Unimplemented action type {}.", l3m.subtype()); break; } return null; }
portNo = ((portNo & IDENTIFIER_SET) == IDENTIFIER_SET) ? portNo & SET : portNo; ipSrcAddress = Ip4Address.valueOf((int) portNo); subObj = new IPv4SubObject(ipSrcAddress.getIp4Address().toInt()); llSubObjects.add(subObj); portNo = ((portNo & IDENTIFIER_SET) == IDENTIFIER_SET) ? portNo & SET : portNo; ipDstAddress = Ip4Address.valueOf((int) portNo); subObj = new IPv4SubObject(ipDstAddress.getIp4Address().toInt()); llSubObjects.add(subObj);
IpAddress.valueOf(srcLsrId).getIp4Address().toInt(), PcepLabelOp.ADD, false);
.ip().getIp4Address().toInt()), localLspId, pccTunnelId, 0, (((IpTunnelEndPoint) tunnel.dst()).ip() .getIp4Address().toInt())); llOptionalTlv.add(tlv);
private Ethernet buildArpRequest(IpAddress targetIp, IpAddress sourceIp, MacAddress sourceMac) { ARP arp = new ARP(); arp.setHardwareType(ARP.HW_TYPE_ETHERNET) .setHardwareAddressLength((byte) Ethernet.DATALAYER_ADDRESS_LENGTH) .setProtocolType(ARP.PROTO_TYPE_IP) .setProtocolAddressLength((byte) Ip4Address.BYTE_LENGTH) .setOpCode(ARP.OP_REQUEST); arp.setSenderHardwareAddress(sourceMac.toBytes()) .setSenderProtocolAddress(sourceIp.getIp4Address().toInt()) .setTargetHardwareAddress(ZERO_MAC_ADDRESS) .setTargetProtocolAddress(targetIp.getIp4Address().toInt()); Ethernet ethernet = new Ethernet(); ethernet.setEtherType(Ethernet.TYPE_ARP) .setDestinationMACAddress(MacAddress.BROADCAST) .setSourceMACAddress(sourceMac) .setPayload(arp); ethernet.setPad(true); return ethernet; }
private Ethernet buildArpResponse(IpAddress targetIp, MacAddress targetMac, IpAddress sourceIp, MacAddress sourceMac) { ARP arp = new ARP(); arp.setHardwareType(ARP.HW_TYPE_ETHERNET) .setHardwareAddressLength((byte) Ethernet.DATALAYER_ADDRESS_LENGTH) .setProtocolType(ARP.PROTO_TYPE_IP) .setProtocolAddressLength((byte) Ip4Address.BYTE_LENGTH) .setOpCode(ARP.OP_REPLY); arp.setSenderHardwareAddress(sourceMac.toBytes()) .setSenderProtocolAddress(sourceIp.getIp4Address().toInt()) .setTargetHardwareAddress(targetMac.toBytes()) .setTargetProtocolAddress(targetIp.getIp4Address().toInt()); Ethernet ethernet = new Ethernet(); ethernet.setEtherType(Ethernet.TYPE_ARP) .setDestinationMACAddress(targetMac) .setSourceMACAddress(sourceMac) .setPayload(arp); ethernet.setPad(true); return ethernet; }
Ethernet ethReply = ARP.buildArpReply(targetIp.getIp4Address(), dstMac, ethRequest);
tlv = new StatefulIPv4LspIdentifiersTlv((((IpTunnelEndPoint) tunnel.src()).ip().getIp4Address().toInt()), localLspId, (short) 0, 0, (((IpTunnelEndPoint) tunnel.dst()).ip() .getIp4Address().toInt())); llOptionalTlv.add(tlv); .setSourceIpAddress(((IpTunnelEndPoint) tunnel.src()).ip().getIp4Address().toInt()) .setDestIpAddress(((IpTunnelEndPoint) tunnel.dst()).ip().getIp4Address().toInt()) .setPFlag(true).build();
case IPV4_SRC: ip = (L3ModificationInstruction.ModIPInstruction) i; ip4 = ip.ip().getIp4Address(); oxm = factory.oxms().ipv4Src(IPv4Address.of(ip4.toInt())); break; case IPV4_DST: ip = (L3ModificationInstruction.ModIPInstruction) i; ip4 = ip.ip().getIp4Address(); oxm = factory.oxms().ipv4Dst(IPv4Address.of(ip4.toInt())); break;
case IPV4_SRC: ip = (ModIPInstruction) i; ip4 = ip.ip().getIp4Address(); oxm = factory().oxms().ipv4Src(IPv4Address.of(ip4.toInt())); break; case IPV4_DST: ip = (ModIPInstruction) i; ip4 = ip.ip().getIp4Address(); oxm = factory().oxms().ipv4Dst(IPv4Address.of(ip4.toInt())); break; case ARP_SPA: ModArpIPInstruction aip = (ModArpIPInstruction) i; ip4 = aip.ip().getIp4Address(); oxm = factory().oxms().arpSpa(IPv4Address.of(ip4.toInt())); break;
.matchVlanId(intf.vlan()) .matchEthType(EthType.EtherType.ARP.ethType().toShort()) .matchArpSpa(ip.ipAddress().getIp4Address()) .build();