@Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; ARP other = (ARP) obj; if (hardwareAddressLength != other.hardwareAddressLength) return false; if (hardwareType != other.hardwareType) return false; if (opCode == null) { if (other.opCode != null) return false; } else if (!opCode.equals(other.opCode)) return false; if (protocolAddressLength != other.protocolAddressLength) return false; if (protocolType != other.protocolType) return false; if (senderHardwareAddress == null) { if (other.senderHardwareAddress != null) return false; } else if (!senderHardwareAddress.equals(other.senderHardwareAddress)) return false; if (senderProtocolAddress == null) { if (other.senderProtocolAddress != null) return false; } else if (!senderProtocolAddress.equals(other.senderProtocolAddress)) return false; if (targetHardwareAddress == null) { if (other.targetHardwareAddress != null) return false; } else if (!targetHardwareAddress.equals(other.targetHardwareAddress)) return false; if (targetProtocolAddress == null) { if (other.targetProtocolAddress != null) return false; } else if (!targetProtocolAddress.equals(other.targetProtocolAddress)) return false; return true; }
@Override public IPacket deserialize(byte[] data, int offset, int length) throws PacketParsingException { ByteBuffer bb = ByteBuffer.wrap(data, offset, length); this.hardwareType = bb.getShort(); this.protocolType = bb.getShort(); this.hardwareAddressLength = bb.get(); this.protocolAddressLength = bb.get(); if (this.hardwareAddressLength != 6) { String msg = "Incorrect ARP hardware address length: " + hardwareAddressLength; throw new PacketParsingException(msg); } if (this.protocolAddressLength != 4) { String msg = "Incorrect ARP protocol address length: " + protocolAddressLength; throw new PacketParsingException(msg); } this.opCode = ArpOpcode.of(bb.getShort()); byte[] tmpMac = new byte[0xff & this.hardwareAddressLength]; byte[] tmpIp = new byte[0xff & this.protocolAddressLength]; bb.get(tmpMac, 0, this.hardwareAddressLength); this.senderHardwareAddress = MacAddress.of(tmpMac); bb.get(tmpIp, 0, this.protocolAddressLength); this.senderProtocolAddress = IPv4Address.of(tmpIp); bb.get(tmpMac, 0, this.hardwareAddressLength); this.targetHardwareAddress = MacAddress.of(tmpMac); bb.get(tmpIp, 0, this.protocolAddressLength); this.targetProtocolAddress = IPv4Address.of(tmpIp); return this; }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((value == null) ? 0 : value.hashCode()); result = prime * result + ((mask == null) ? 0 : mask.hashCode()); return result; }
/** * Constructor for a DHCPPool of DHCPBinding's. Each DHCPBinding object is initialized with a null * MAC address and the lease is set to inactive (i.e. false). * * @param {@code byte[]} startingIPv4Address: The lowest IP address to lease. * @param {@code integer} size: (startingIPv4Address + size) is the highest IP address to lease. * @return none */ public DHCPPool(IPv4Address startingIPv4Address, int size, Logger log) { this.log = log; int IPv4AsInt = startingIPv4Address.getInt(); this.setPoolSize(size); this.setPoolAvailability(size); STARTING_ADDRESS = startingIPv4Address; for (int i = 0; i < size; i++) { DHCP_POOL.add(new DHCPBinding(IPv4Address.of(IPv4AsInt + i), UNASSIGNED_MAC)); } }
@Override public OFOxmArpTpaMasked readFrom(ChannelBuffer bb) throws OFParseError { // fixed value property typeLen == 0x80002f08L int typeLen = bb.readInt(); if (typeLen != (int) 0x80002f08) throw new OFParseError("Wrong typeLen: Expected=0x80002f08L(0x80002f08L), got=" + typeLen); IPv4Address value = IPv4Address.read4Bytes(bb); IPv4Address mask = IPv4Address.read4Bytes(bb); OFOxmArpTpaMaskedVer12 oxmArpTpaMaskedVer12 = new OFOxmArpTpaMaskedVer12(value, mask); if (logger.isTraceEnabled()) logger.trace("readFrom - read={}", oxmArpTpaMaskedVer12); return oxmArpTpaMaskedVer12; }
/** * Adds an IP address to the DHCPPool if the address is not already present. If present, nothing * is added to the DHCPPool. * * @param {@code byte[]} ip: The IP address to attempt to add to the DHCPPool * @return {@code DHCPBinding}: Reference to the DHCPBinding object if successful, null if * unsuccessful */ public DHCPBinding addIPv4ToDHCPPool(IPv4Address ip) { DHCPBinding binding = null; if (this.getDHCPbindingFromIPv4(ip) == null) { if (ip.getInt() < STARTING_ADDRESS.getInt()) { STARTING_ADDRESS = ip; } binding = new DHCPBinding(ip, null); DHCP_POOL.add(binding); this.setPoolSize(this.getPoolSize() + 1); this.setPoolFull(false); } return binding; }
@Override public OFOxmTunnelIpv4SrcMasked readFrom(ByteBuf bb) throws OFParseError { // fixed value property typeLen == 0x13f08L int typeLen = bb.readInt(); if (typeLen != 0x13f08) throw new OFParseError("Wrong typeLen: Expected=0x13f08L(0x13f08L), got=" + typeLen); IPv4Address value = IPv4Address.read4Bytes(bb); IPv4Address mask = IPv4Address.read4Bytes(bb); OFOxmTunnelIpv4SrcMaskedVer13 oxmTunnelIpv4SrcMaskedVer13 = new OFOxmTunnelIpv4SrcMaskedVer13(value, mask); if (logger.isTraceEnabled()) logger.trace("readFrom - read={}", oxmTunnelIpv4SrcMaskedVer13); return oxmTunnelIpv4SrcMaskedVer13; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; OFOxmArpTpaMaskedVer12 other = (OFOxmArpTpaMaskedVer12) obj; if (value == null) { if (other.value != null) return false; } else if (!value.equals(other.value)) return false; if (mask == null) { if (other.mask != null) return false; } else if (!mask.equals(other.mask)) return false; return true; }
private OFAction buildL3Modification(Instruction i) { L3ModificationInstruction l3m = (L3ModificationInstruction) i; ModIPInstruction ip; Ip4Address ip4; Ip6Address ip6; OFOxm<?> oxm = null; switch (l3m.subtype()) { 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 IPV6_SRC: ip = (ModIPInstruction) i; ip6 = ip.ip().getIp6Address(); oxm = factory().oxms().ipv6Src(IPv6Address.of(ip6.toOctets())); break; case IPV6_DST: ip = (ModIPInstruction) i; ip6 = ip.ip().getIp6Address(); oxm = factory().oxms().ipv6Dst(IPv6Address.of(ip6.toOctets())); break; case IPV6_FLABEL: ModIPv6FlowLabelInstruction flowLabelInstruction = (ModIPv6FlowLabelInstruction) i; int flowLabel = flowLabelInstruction.flowLabel(); oxm = factory().oxms().ipv6Flabel(IPv6FlowLabel.of(flowLabel)); break; case DEC_TTL: return factory().actions().decNwTtl(); case TTL_IN: return factory().actions().copyTtlIn(); case TTL_OUT: return factory().actions().copyTtlOut(); default: log.warn("Unimplemented action type {}.", l3m.subtype()); break; } if (oxm != null) { return factory().actions().buildSetField().setField(oxm).build(); } return null; }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((nwAddr == null) ? 0 : nwAddr.hashCode()); return result; }
@Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + hardwareAddressLength; result = prime * result + hardwareType; result = prime * result + ((opCode == null) ? 0 : opCode.hashCode()); result = prime * result + protocolAddressLength; result = prime * result + protocolType; result = prime * result + ((senderHardwareAddress == null) ? 0 : senderHardwareAddress.hashCode()); result = prime * result + ((senderProtocolAddress == null) ? 0 : senderProtocolAddress.hashCode()); result = prime * result + ((targetHardwareAddress == null) ? 0 : targetHardwareAddress.hashCode()); result = prime * result + ((targetProtocolAddress == null) ? 0 : targetProtocolAddress.hashCode()); return result; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; OFActionSetNwDstVer11 other = (OFActionSetNwDstVer11) obj; if (nwAddr == null) { if (other.nwAddr != null) return false; } else if (!nwAddr.equals(other.nwAddr)) return false; return true; }
/** * Completely removes the DHCPBinding object with IP address {@code byte[]} ip from the DHCPPool * * @param {@code byte[]} ip: The IP address to remove from the pool. This address will not be * available for lease after removal. * @return none */ public void removeIPv4FromDHCPPool(IPv4Address ip) { if (ip == null || getDHCPbindingFromIPv4(ip) == null) return; if (ip.equals(STARTING_ADDRESS)) { DHCPBinding lowest = null; // Locate the lowest address (other than ip), which will be the new starting address for (DHCPBinding binding : DHCP_POOL) { if (lowest == null) { lowest = binding; } else if (binding.getIPv4Address().getInt() < lowest.getIPv4Address().getInt() && !binding.getIPv4Address().equals(ip)) { lowest = binding; } } // lowest is new starting address STARTING_ADDRESS = lowest.getIPv4Address(); } DHCP_POOL.remove(this.getDHCPbindingFromIPv4(ip)); this.setPoolSize(this.getPoolSize() - 1); this.setPoolAvailability(this.getPoolAvailability() - 1); if (this.getPoolAvailability() == 0) this.setPoolFull(true); }
@Override public OFActionSetNwDst readFrom(ChannelBuffer bb) throws OFParseError { int start = bb.readerIndex(); // fixed value property type == 6 short type = bb.readShort(); if (type != (short) 0x6) throw new OFParseError("Wrong type: Expected=OFActionType.SET_NW_DST(6), got=" + type); int length = U16.f(bb.readShort()); if (length != 8) throw new OFParseError("Wrong length: Expected=8(8), got=" + length); if (bb.readableBytes() + (bb.readerIndex() - start) < length) { // Buffer does not have all data yet bb.readerIndex(start); return null; } if (logger.isTraceEnabled()) logger.trace("readFrom - length={}", length); IPv4Address nwAddr = IPv4Address.read4Bytes(bb); OFActionSetNwDstVer11 actionSetNwDstVer11 = new OFActionSetNwDstVer11(nwAddr); if (logger.isTraceEnabled()) logger.trace("readFrom - read={}", actionSetNwDstVer11); return actionSetNwDstVer11; }
/** * Auxiliary method obtain the JSON fields and their values * * @param fmJson * @param sv */ public static void jsonConverter(String fmJson, IStatsService sv) { MappingJsonFactory f = new MappingJsonFactory(); JsonParser jp; try { try { jp = f.createJsonParser(fmJson); } catch (JsonParseException e) { throw new IOException(e); } jp.nextToken(); if (jp.getCurrentToken() != JsonToken.START_OBJECT) { throw new IOException("Expected START_OBJECT"); } while (jp.nextToken() != JsonToken.END_OBJECT) { if (jp.getCurrentToken() != JsonToken.FIELD_NAME) { throw new IOException("Expected FIELD_NAME"); } String n = jp.getCurrentName(); jp.nextToken(); if (jp.getText().equals("")) { continue; } // This assumes user having dpid info for involved switches else if (n.equalsIgnoreCase("srcDpid")) { try { srcId = DatapathId.of(jp.getText()); } catch (NumberFormatException e) { log.error("Unable to parse switch DPID: {}", jp.getText()); // TODO should return some error message via HTTP message } } else if (n.equalsIgnoreCase("dstDpid")) { try { dstId = DatapathId.of(jp.getText()); } catch (NumberFormatException e) { log.error("Unable to parse switch DPID: {}", jp.getText()); // TODO should return some error message via HTTP message } } else if (n.equalsIgnoreCase("srcIp")) { try { srcIp = IPv4Address.of(jp.getText()); } catch (NumberFormatException e) { log.error("Unable to parse IP srcIp: {}", jp.getText()); // TODO should return some error message via HTTP message } } else if (n.equalsIgnoreCase("dstIp")) { try { dstIp = IPv4Address.of(jp.getText()); } catch (NumberFormatException e) { log.error("Unable to parse IP dstIp: {}", jp.getText()); // TODO should return some error message via HTTP message } } else if (n.equalsIgnoreCase("loss")) { try { loss = Integer.parseInt(jp.getText()); } catch (NumberFormatException e) { log.error("Unable to parse loss: {}", jp.getText()); // TODO should return some error message via HTTP message } } } } catch (IOException e) { log.error("Unable to parse JSON string: {}", e); } }
/** @return True if gratuitous ARP (SPA = TPA), false otherwise */ public boolean isGratuitous() { assert (senderProtocolAddress.getLength() == targetProtocolAddress.getLength()); return senderProtocolAddress.equals(targetProtocolAddress); }