use of org.opencord.dhcpl2relay.impl.packet.DhcpOption82Data in project dhcpl2relay by opencord.
the class DhcpL2RelayTest method compareClientPackets.
public void compareClientPackets(Ethernet sent, Ethernet relayed, VlanId expectedQinQ, VlanId expectedVlan, short expectedPcp, String expectedCircuitId, String expectedRemoteId) {
// convert the sent packet to the expected relayed packet
// due to netconfig test in setup
sent.setSourceMACAddress(OLT_MAC_ADDRESS);
sent.setQinQVID(expectedQinQ.toShort());
sent.setQinQTPID((short) 0x8100);
sent.setVlanID(expectedVlan.toShort());
sent.setPriorityCode((byte) expectedPcp);
IPv4 ipv4Packet = (IPv4) sent.getPayload();
UDP udpPacket = (UDP) ipv4Packet.getPayload();
DHCP dhcpPacket = (DHCP) udpPacket.getPayload();
List<DhcpOption> options = Lists.newArrayList(dhcpPacket.getOptions());
DhcpOption82Data option82 = new DhcpOption82Data();
option82.setAgentCircuitId(expectedCircuitId);
option82.setAgentRemoteId(expectedRemoteId);
DhcpOption option = new DhcpOption().setCode(DHCP.DHCPOptionCode.OptionCode_CircuitID.getValue()).setData(option82.toByteArray()).setLength(option82.length());
options.add(options.size() - 1, option);
dhcpPacket.setOptions(options);
byte[] sb = sent.serialize();
Ethernet expectedPacket = null;
try {
expectedPacket = Ethernet.deserializer().deserialize(sb, 0, sb.length);
} catch (DeserializationException e) {
log.error("exeption: {}", e.getMessage());
fail();
}
verifyDhcpOptions(expectedPacket, relayed);
assertEquals(expectedPacket, relayed);
}
use of org.opencord.dhcpl2relay.impl.packet.DhcpOption82Data in project dhcpl2relay by opencord.
the class DhcpL2RelayTestBase method constructDhcpOptions.
/**
* Constructs DHCP Discover Options.
*
* @return Ethernet packet
*/
private List<DhcpOption> constructDhcpOptions(DHCP.MsgType packetType) {
// DHCP Options.
DhcpOption option = new DhcpOption();
List<DhcpOption> optionList = new ArrayList<>();
// DHCP Message Type.
option.setCode(DHCP.DHCPOptionCode.OptionCode_MessageType.getValue());
option.setLength((byte) 1);
byte[] optionData = { (byte) packetType.getValue() };
option.setData(optionData);
optionList.add(option);
// DHCP Requested IP.
option = new DhcpOption();
option.setCode(DHCP.DHCPOptionCode.OptionCode_RequestedIP.getValue());
option.setLength((byte) 4);
optionData = Ip4Address.valueOf(EXPECTED_IP).toOctets();
option.setData(optionData);
optionList.add(option);
// Tests app defined Option82
if (packetType.equals(DHCP.MsgType.DHCPOFFER)) {
option = new DhcpOption();
option.setCode(DHCP.DHCPOptionCode.OptionCode_CircuitID.getValue());
DhcpOption82Data option82 = new DhcpOption82Data();
option82.setAgentCircuitId(OLT_DEV_ID + "/" + CLIENT_PORT + ":vlan" + CLIENT_C_TAG + ":pcp" + CLIENT_C_PBIT);
option82.setAgentRemoteId("bababababa");
option.setData(option82.toByteArray());
option.setLength(option82.length());
log.info("Added option82 {}", option);
optionList.add(option);
}
// Tests operator configured Option82, resulting in host lookup
if (packetType.equals(DHCP.MsgType.DHCPACK)) {
option = new DhcpOption();
option.setCode(DHCP.DHCPOptionCode.OptionCode_CircuitID.getValue());
DhcpOption82Data option82 = new DhcpOption82Data();
option82.setAgentCircuitId(CLIENT_CIRCUIT_ID);
option82.setAgentRemoteId(CLIENT_REMOTE_ID);
option.setData(option82.toByteArray());
option.setLength(option82.length());
log.info("Added option82 {}", option);
optionList.add(option);
}
// Finally remoteId is missing
if (packetType.equals(DHCP.MsgType.DHCPNAK)) {
option = new DhcpOption();
option.setCode(DHCP.DHCPOptionCode.OptionCode_CircuitID.getValue());
DhcpOption82Data option82 = new DhcpOption82Data();
option82.setAgentCircuitId("of:0000b86a974385f7/32" + ":vlan" + VlanId.vlanId((short) 111) + ":pcp-1");
option.setData(option82.toByteArray());
option.setLength(option82.length());
log.info("Added option82 {}", option);
optionList.add(option);
}
// End Option.
option = new DhcpOption();
option.setCode(DHCP.DHCPOptionCode.OptionCode_END.getValue());
option.setLength((byte) 1);
optionList.add(option);
return optionList;
}
Aggregations