use of org.onlab.packet.Ethernet in project onos by opennetworkinglab.
the class KubevirtNetworkingUtil method buildGarpPacket.
/**
* Builds a GARP packet using the given source MAC and source IP address.
*
* @param srcMac source MAC address
* @param srcIp source IP address
* @return GARP packet
*/
public static Ethernet buildGarpPacket(MacAddress srcMac, IpAddress srcIp) {
if (srcMac == null || srcIp == null) {
return null;
}
Ethernet ethernet = new Ethernet();
ethernet.setDestinationMACAddress(MacAddress.BROADCAST);
ethernet.setSourceMACAddress(srcMac);
ethernet.setEtherType(Ethernet.TYPE_ARP);
ARP arp = new ARP();
arp.setOpCode(ARP.OP_REPLY);
arp.setProtocolType(ARP.PROTO_TYPE_IP);
arp.setHardwareType(ARP.HW_TYPE_ETHERNET);
arp.setProtocolAddressLength((byte) Ip4Address.BYTE_LENGTH);
arp.setHardwareAddressLength((byte) Ethernet.DATALAYER_ADDRESS_LENGTH);
arp.setSenderHardwareAddress(srcMac.toBytes());
arp.setTargetHardwareAddress(MacAddress.BROADCAST.toBytes());
arp.setSenderProtocolAddress(srcIp.toOctets());
arp.setTargetProtocolAddress(srcIp.toOctets());
ethernet.setPayload(arp);
return ethernet;
}
use of org.onlab.packet.Ethernet in project onos by opennetworkinglab.
the class DefaultVirtualPacketProvider method virtualize.
/**
* Translate the requested physical PacketContext into a virtual PacketContext.
* See {@link org.onosproject.net.packet.PacketContext}
*
* @param context A physical PacketContext be translated
* @return A translated virtual PacketContext
*/
private VirtualPacketContext virtualize(PacketContext context) {
VirtualPort vPort = getMappedVirtualPort(context.inPacket().receivedFrom());
if (vPort != null) {
ConnectPoint cp = new ConnectPoint(vPort.element().id(), vPort.number());
Ethernet eth = context.inPacket().parsed();
eth.setVlanID(Ethernet.VLAN_UNTAGGED);
InboundPacket inPacket = new DefaultInboundPacket(cp, eth, ByteBuffer.wrap(eth.serialize()));
DefaultOutboundPacket outPkt = new DefaultOutboundPacket(cp.deviceId(), DefaultTrafficTreatment.builder().build(), ByteBuffer.wrap(eth.serialize()));
VirtualPacketContext vContext = new DefaultVirtualPacketContext(context.time(), inPacket, outPkt, false, vPort.networkId(), this);
return vContext;
} else {
return null;
}
}
use of org.onlab.packet.Ethernet in project onos by opennetworkinglab.
the class CastorArpManager method updateMac.
/**
* Updates the IP address to mac address map.
*
* @param context The message context.
*/
private void updateMac(MessageContext context) {
if ((castorStore.getAddressMap()).containsKey(context.sender())) {
return;
}
Ethernet eth = context.packet();
MacAddress macAddress = eth.getSourceMAC();
IpAddress ipAddress = context.sender();
castorStore.setAddressMap(ipAddress, macAddress);
}
use of org.onlab.packet.Ethernet in project onos by opennetworkinglab.
the class CastorArpManager method buildArpRequest.
/**
* 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;
}
use of org.onlab.packet.Ethernet in project onos by opennetworkinglab.
the class CastorArpManager method createArp.
@Override
public void createArp(Peer peer) {
Ethernet packet = null;
packet = buildArpRequest(peer);
ByteBuffer buf = ByteBuffer.wrap(packet.serialize());
ConnectPoint connectPoint = ConnectPoint.deviceConnectPoint(peer.getPort());
TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
builder.setOutput(connectPoint.port());
packetService.emit(new DefaultOutboundPacket(connectPoint.deviceId(), builder.build(), buf));
}
Aggregations