@Override public byte[] serialize() { ByteBuffer byteBuffer; byteBuffer = ByteBuffer.allocate(ENTRY_LEN); byteBuffer.putShort(addressFamilyId); byteBuffer.putShort(routeTag); byteBuffer.putInt(ipAddress.toInt()); byteBuffer.putInt(subnetMask.toInt()); byteBuffer.putInt(nextHop.toInt()); byteBuffer.putInt(metric); return byteBuffer.array(); }
@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; } }
@Override public void init(Criterion criterion, int bitWidth) throws ByteSequenceTrimException { ArpPaCriterion c = (ArpPaCriterion) criterion; initAsExactMatch(copyFrom(c.ip().toInt()), bitWidth); } }
@Override public int write(ChannelBuffer cb) { int iLenStartIndex = cb.writerIndex(); cb.writeShort(type); cb.writeShort(LENGTH); cb.writeInt(address.toInt()); return cb.writerIndex() - iLenStartIndex; }
@Override public int write(ChannelBuffer c) { int iLenStartIndex = c.writerIndex(); c.writeShort(TYPE); c.writeShort(LENGTH); c.writeInt(routerID); c.writeInt(drInterface.toInt()); return c.writerIndex() - iLenStartIndex; }
nai = new PcepNaiIpv4NodeId(Ip4Address.valueOf(dstNode.annotations().value(LSRID)).toInt());
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; }
nai = new PcepNaiIpv4NodeId(Ip4Address.valueOf(dstNode.annotations().value(LSRID)).toInt());
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; }
@Override public int write(ChannelBuffer cb) { int iLenStartIndex = cb.writerIndex(); cb.writeByte(FLOW_SPEC_TYPE); cb.writeByte(length); cb.writeInt(ipPrefix.getIp4Prefix().address().toInt()); return cb.writerIndex() - iLenStartIndex; }
@Override public int write(ChannelBuffer cb) { int iLenStartIndex = cb.writerIndex(); cb.writeByte(FLOW_SPEC_TYPE); cb.writeByte(length); cb.writeInt(ipPrefix.getIp4Prefix().address().toInt()); return cb.writerIndex() - iLenStartIndex; }
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);
@Override public int write(ChannelBuffer cb) { int iLenStartIndex = cb.writerIndex(); cb.writeByte(FLAGS); cb.writeByte(getType()); if (!isNextHopSet()) { cb.writeByte(0); } else { cb.writeInt(nextHop.toInt()); } return cb.writerIndex() - iLenStartIndex; }
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; }
/** * Builds link description. * * @param ospfRouter OSPF router instance * @param ospfLinkTed OSPF link TED instance * @return link description instance */ private LinkDescription buildLinkDes(OspfRouter ospfRouter, OspfLinkTed ospfLinkTed) { long srcAddress = 0; long dstAddress = 0; boolean localPseduo = false; //Changing of port numbers srcAddress = Ip4Address.valueOf(ospfRouter.routerIp().toString()).toInt(); dstAddress = Ip4Address.valueOf(ospfRouter.neighborRouterId().toString()).toInt(); DeviceId srcId = DeviceId.deviceId(OspfRouterId.uri(ospfRouter.routerIp())); DeviceId dstId = DeviceId.deviceId(OspfRouterId.uri(ospfRouter.neighborRouterId())); if (ospfRouter.isDr()) { localPseduo = true; } if (localPseduo && srcAddress == 0) { srcAddress = PSEUDO_PORT; } ConnectPoint src = new ConnectPoint(srcId, PortNumber.portNumber(srcAddress)); ConnectPoint dst = new ConnectPoint(dstId, PortNumber.portNumber(dstAddress)); return new DefaultLinkDescription(src, dst, Link.Type.DIRECT, false); }
/** * Prepares BGP OPEN message. * * @param localInfo the BGP Session local information to use * @return the message to transmit (BGP header included) */ static ChannelBuffer prepareBgpOpen(BgpSessionInfo localInfo) { ChannelBuffer message = ChannelBuffers.buffer(BgpConstants.BGP_MESSAGE_MAX_LENGTH); // // Prepare the OPEN message payload // message.writeByte(localInfo.bgpVersion()); message.writeShort((int) localInfo.asNumber()); message.writeShort((int) localInfo.holdtime()); message.writeInt(localInfo.bgpId().toInt()); // Prepare the optional BGP Capabilities ChannelBuffer capabilitiesMessage = prepareBgpOpenCapabilities(localInfo); message.writeByte(capabilitiesMessage.readableBytes()); message.writeBytes(capabilitiesMessage); return BgpMessage.prepareBgpMessage(BgpConstants.BGP_TYPE_OPEN, message); }
arp.setSenderProtocolAddress(srcIp.toInt());