@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; }
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; }
/** * 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)); } }
/** * 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); } }