Java Code Examples for org.onlab.packet.MacAddress#MAC_ADDRESS_LENGTH

The following examples show how to use org.onlab.packet.MacAddress#MAC_ADDRESS_LENGTH . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ArpHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Sends an APR request for the target IP address to all ports except in-port.
 *
 * @param deviceId Switch device ID
 * @param targetAddress target IP address for ARP
 * @param inPort in-port
 */
public void sendArpRequest(DeviceId deviceId, IpAddress targetAddress, ConnectPoint inPort) {
    byte[] senderMacAddress = new byte[MacAddress.MAC_ADDRESS_LENGTH];
    byte[] senderIpAddress = new byte[Ip4Address.BYTE_LENGTH];
    /*
     * Retrieves device info.
     */
    if (!getSenderInfo(senderMacAddress, senderIpAddress, deviceId, targetAddress)) {
        log.warn("Aborting sendArpRequest, we cannot get all the information needed");
        return;
    }
    /*
     * Creates the request.
     */
    Ethernet arpRequest = ARP.buildArpRequest(
            senderMacAddress,
            senderIpAddress,
            targetAddress.toOctets(),
            VlanId.NO_VID
    );
    flood(arpRequest, inPort, targetAddress);
}
 
Example 2
Source File: IcmpHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Sends a NDP request for the target IP address to all ports except in-port.
 *
 * @param deviceId Switch device ID
 * @param targetAddress target IP address for ARP
 * @param inPort in-port
 */
public void sendNdpRequest(DeviceId deviceId, IpAddress targetAddress, ConnectPoint inPort) {
    byte[] senderMacAddress = new byte[MacAddress.MAC_ADDRESS_LENGTH];
    byte[] senderIpAddress = new byte[Ip6Address.BYTE_LENGTH];
    // Retrieves device info.
    if (!getSenderInfo(senderMacAddress, senderIpAddress, deviceId, targetAddress)) {
        log.warn("Aborting sendNdpRequest, we cannot get all the information needed");
        return;
    }
    // We have to compute the dst mac address and dst ip address.
    byte[] dstIp = IPv6.getSolicitNodeAddress(targetAddress.toOctets());
    byte[] dstMac = IPv6.getMCastMacAddress(dstIp);
    // Creates the request.
    Ethernet ndpRequest = NeighborSolicitation.buildNdpSolicit(
            targetAddress.getIp6Address(),
            Ip6Address.valueOf(senderIpAddress),
            Ip6Address.valueOf(dstIp),
            MacAddress.valueOf(senderMacAddress),
            MacAddress.valueOf(dstMac),
            VlanId.NONE
    );
    flood(ndpRequest, inPort, targetAddress);
}
 
Example 3
Source File: Dhcp6InterfaceIdOption.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Gets deserializer for DHCPv6 relay option.
 *
 * @return the deserializer
 */
public static Deserializer<Dhcp6Option> deserializer() {
    return (data, offset, len) -> {
        Dhcp6Option dhcp6Option = Dhcp6Option.deserializer().deserialize(data, offset, len);
        if (dhcp6Option.getLength() < DEFAULT_LEN) {
            throw new DeserializationException("Invalid InterfaceIoption data");
        }
        Dhcp6InterfaceIdOption interfaceIdOption = new Dhcp6InterfaceIdOption(dhcp6Option);
        byte[] optionData = interfaceIdOption.getData();
        if (optionData.length >= 31) {
            ByteBuffer bb = ByteBuffer.wrap(optionData);

            byte[] macAddr = new byte[MacAddress.MAC_ADDRESS_LENGTH];
            byte[] port = new byte[optionData.length - MacAddress.MAC_ADDRESS_LENGTH -
                                                    VLAN_LEN - SEPARATOR_LEN * 2];
            short vlan;
            bb.get(macAddr);
            bb.get();  // separator "-"
            bb.get(port);
            bb.get(); // separator ":"
            vlan = bb.getShort();
            interfaceIdOption.setMacAddress(MacAddress.valueOf(macAddr));
            interfaceIdOption.setInPort(port);
            interfaceIdOption.setVlanId(vlan > VlanId.MAX_VLAN ? VlanId.UNTAGGED : vlan);
        }
        return interfaceIdOption;
    };
}
 
Example 4
Source File: DhcpRelayManagerTest.java    From onos with Apache License 2.0 4 votes vote down vote up
private void buildRelayMsg(DHCP6 dhcp6Relay, byte msgType, Ip6Address linkAddr,
                           Ip6Address peerAddr, byte hop, byte[] interfaceIdBytes,
                           DHCP6 dhcp6Payload) {

    dhcp6Relay.setMsgType(msgType);

    dhcp6Relay.setLinkAddress(linkAddr.toOctets());
    dhcp6Relay.setPeerAddress(peerAddr.toOctets());
    dhcp6Relay.setHopCount(hop);
    List<Dhcp6Option> options = new ArrayList<Dhcp6Option>();

    // interfaceId  option
    Dhcp6Option interfaceId = new Dhcp6Option();
    interfaceId.setCode(DHCP6.OptionCode.INTERFACE_ID.value());


    interfaceId.setData(interfaceIdBytes);
    interfaceId.setLength((short) interfaceIdBytes.length);
    Dhcp6InterfaceIdOption interfaceIdOption = new Dhcp6InterfaceIdOption(interfaceId);
    byte[] optionData = interfaceIdOption.getData();
    ByteBuffer bb = ByteBuffer.wrap(interfaceIdBytes);

    byte[] macAddr = new byte[MacAddress.MAC_ADDRESS_LENGTH];
    byte[] port =  new byte[optionData.length - MacAddress.MAC_ADDRESS_LENGTH -
                            VLAN_LEN - SEPARATOR_LEN * 2];
    short vlan;
    bb.get(macAddr);
    bb.get();  // separator
    bb.get(port);
    bb.get();  // separator
    vlan = bb.getShort();
    interfaceIdOption.setMacAddress(MacAddress.valueOf(macAddr));
    interfaceIdOption.setInPort(port);
    interfaceIdOption.setVlanId(vlan);

    options.add(interfaceIdOption);

    // relay message option
    Dhcp6Option relayMsgOption = new Dhcp6Option();
    relayMsgOption.setCode(DHCP6.OptionCode.RELAY_MSG.value());
    byte[] dhcp6PayloadByte = dhcp6Payload.serialize();
    relayMsgOption.setLength((short) dhcp6PayloadByte.length);
    relayMsgOption.setPayload(dhcp6Payload);
    Dhcp6RelayOption relayOpt = new Dhcp6RelayOption(relayMsgOption);

    options.add(relayOpt);

    dhcp6Relay.setOptions(options);
}