Java Code Examples for org.onlab.packet.Ethernet#setPad()

The following examples show how to use org.onlab.packet.Ethernet#setPad() . 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: LldpLinkProviderTest.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public InboundPacket inPacket() {
    ONOSLLDP lldp = ONOSLLDP.onosSecureLLDP(deviceService.getDevice(DID1).id().toString(),
                                            device.chassisId(),
                                            (int) pd1.number().toLong(), "", "test");

    Ethernet ethPacket = new Ethernet();
    ethPacket.setEtherType(Ethernet.TYPE_LLDP);
    ethPacket.setDestinationMACAddress(MacAddress.ONOS_LLDP);
    ethPacket.setPayload(lldp);
    ethPacket.setPad(true);

    ethPacket.setSourceMACAddress("DE:AD:BE:EF:BA:11");

    ConnectPoint cp = new ConnectPoint(device.id(), pd3.number());

    return new DefaultInboundPacket(cp, ethPacket,
                                    ByteBuffer.wrap(ethPacket.serialize()));

}
 
Example 2
Source File: NetworkConfigLinksProviderTest.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public InboundPacket inPacket() {
    ONOSLLDP lldp = ONOSLLDP.onosSecureLLDP(src.deviceId().toString(),
                                            new ChassisId(),
                                            (int) src.port().toLong(), "", "test-secret");

    Ethernet ethPacket = new Ethernet();
    ethPacket.setEtherType(Ethernet.TYPE_LLDP);
    ethPacket.setDestinationMACAddress(MacAddress.ONOS_LLDP);
    ethPacket.setPayload(lldp);
    ethPacket.setPad(true);

    ethPacket.setSourceMACAddress("DE:AD:BE:EF:BA:11");

    return new DefaultInboundPacket(dst, ethPacket,
                                    ByteBuffer.wrap(ethPacket.serialize()));

}
 
Example 3
Source File: LinkDiscovery.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Instantiates discovery manager for the given physical switch. Creates a
 * generic LLDP packet that will be customized for the port it is sent out on.
 * Starts the the timer for the discovery process.
 *
 * @param deviceId  the physical switch
 * @param context discovery context
 */
public LinkDiscovery(DeviceId deviceId, LinkDiscoveryContext context) {
    this.deviceId = deviceId;
    this.context = context;

    ethPacket = new Ethernet();
    ethPacket.setEtherType(Ethernet.TYPE_LLDP);
    ethPacket.setDestinationMACAddress(MacAddress.ONOS_LLDP);
    ethPacket.setPad(true);

    bddpEth = new Ethernet();
    bddpEth.setEtherType(Ethernet.TYPE_BSN);
    bddpEth.setDestinationMACAddress(MacAddress.BROADCAST);
    bddpEth.setPad(true);

    isStopped = true;
    start();
    log.debug("Started discovery manager for switch {}", deviceId);

}
 
Example 4
Source File: VtnManager.java    From onos with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 5
Source File: VtnManager.java    From onos with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 6
Source File: CastorArpManager.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Builds the ARP request when MAC is not known.
 *
 * @param peer The Peer whose MAC is not known.
 * @return Ethernet
 */
private Ethernet buildArpRequest(Peer peer) {
    ARP arp = new ARP();
    arp.setHardwareType(ARP.HW_TYPE_ETHERNET)
            .setHardwareAddressLength((byte) Ethernet.DATALAYER_ADDRESS_LENGTH)
            .setProtocolType(ARP.PROTO_TYPE_IP)
            .setProtocolAddressLength((byte) IpAddress.INET_BYTE_LENGTH)
            .setOpCode(ARP.OP_REQUEST);

    arp.setSenderHardwareAddress(ARP_SOURCEMAC.toBytes())
            .setSenderProtocolAddress(ARP_SRC.toOctets())
            .setTargetHardwareAddress(ZERO_MAC_ADDRESS)
            .setTargetProtocolAddress(IpAddress.valueOf(peer.getIpAddress()).toOctets());

    Ethernet ethernet = new Ethernet();
    ethernet.setEtherType(Ethernet.TYPE_ARP)
            .setDestinationMACAddress(MacAddress.BROADCAST)
            .setSourceMACAddress(ARP_SOURCEMAC)
            .setPayload(arp);
    ethernet.setPad(true);

    return ethernet;
}
 
Example 7
Source File: MQEventHandlerTest.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public InboundPacket inPacket() {
    ONOSLLDP lldp = ONOSLLDP.onosSecureLLDP(deviceService.getDevice(DID1)
                                      .id().toString(),
                                            device.chassisId(),
                                            (int) pd1.number().toLong(), "", "test");

    Ethernet ethPacket = new Ethernet();
    ethPacket.setEtherType(Ethernet.TYPE_LLDP);
    ethPacket.setDestinationMACAddress(MacAddress.ONOS_LLDP);
    ethPacket.setPayload(lldp);
    ethPacket.setPad(true);

    ethPacket.setSourceMACAddress("DE:AD:BE:EF:BA:11");

    ConnectPoint cp = new ConnectPoint(device.id(), pd3.number());

    return new DefaultInboundPacket(cp, ethPacket,
                                    ByteBuffer.wrap(ethPacket
                                    .serialize()));

}
 
Example 8
Source File: EthernetCodecTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Unit test for the ethernet object codec.
 */
@Test
public void ethernetCodecTest() {
    final CodecContext context = new MockCodecContext();
    final JsonCodec<Ethernet> ethernetCodec = context.codec(Ethernet.class);
    assertThat(ethernetCodec, notNullValue());

    final Ethernet eth1 = new Ethernet();
    eth1.setSourceMACAddress("11:22:33:44:55:01");
    eth1.setDestinationMACAddress("11:22:33:44:55:02");
    eth1.setPad(true);
    eth1.setEtherType(Ethernet.TYPE_ARP);
    eth1.setPriorityCode((byte) 7);
    eth1.setVlanID((short) 33);

    final ObjectNode eth1Json = ethernetCodec.encode(eth1, context);
    assertThat(eth1Json, notNullValue());
    assertThat(eth1Json, matchesEthernet(eth1));
}
 
Example 9
Source File: HostMonitor.java    From onos with Apache License 2.0 5 votes vote down vote up
private Ethernet buildArpRequest(IpAddress targetIp, IpAddress sourceIp,
                                 MacAddress sourceMac, VlanId vlan) {

    ARP arp = new ARP();
    arp.setHardwareType(ARP.HW_TYPE_ETHERNET)
       .setHardwareAddressLength((byte) Ethernet.DATALAYER_ADDRESS_LENGTH)
       .setProtocolType(ARP.PROTO_TYPE_IP)
       .setProtocolAddressLength((byte) IpAddress.INET_BYTE_LENGTH)
       .setOpCode(ARP.OP_REQUEST);

    arp.setSenderHardwareAddress(sourceMac.toBytes())
       .setSenderProtocolAddress(sourceIp.toOctets())
       .setTargetHardwareAddress(ZERO_MAC_ADDRESS)
       .setTargetProtocolAddress(targetIp.toOctets());

    Ethernet ethernet = new Ethernet();
    ethernet.setEtherType(Ethernet.TYPE_ARP)
            .setDestinationMACAddress(MacAddress.BROADCAST)
            .setSourceMACAddress(sourceMac)
            .setPayload(arp);

    if (!vlan.equals(VlanId.NONE)) {
        ethernet.setVlanID(vlan.toShort());
    }

    ethernet.setPad(true);

    return ethernet;
}