本文整理汇总了Java中net.floodlightcontroller.packet.ARP类的典型用法代码示例。如果您正苦于以下问题:Java ARP类的具体用法?Java ARP怎么用?Java ARP使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ARP类属于net.floodlightcontroller.packet包,在下文中一共展示了ARP类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSrcIP
import net.floodlightcontroller.packet.ARP; //导入依赖的package包/类
@Override
public int getSrcIP(FPContext cntx) {
FloodlightContext flCntx = cntx.getFlowContext();
Ethernet eth = IFloodlightProviderService.bcStore.get(flCntx,IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
IPv4Address srcIP;
if(eth.getEtherType() == EthType.IPv4)
{
IPv4 ipv4 = (IPv4) eth.getPayload();
srcIP = ipv4.getSourceAddress();
return srcIP.getInt();
}
else if (eth.getEtherType() == EthType.ARP){
ARP arp = (ARP) eth.getPayload();
srcIP = arp.getSenderProtocolAddress();
return srcIP.getInt();
}
//for other packets without source IP information
return 0;
}
示例2: getDstIP
import net.floodlightcontroller.packet.ARP; //导入依赖的package包/类
@Override
public int getDstIP(FPContext cntx) {
FloodlightContext flCntx = cntx.getFlowContext();
Ethernet eth = IFloodlightProviderService.bcStore.get(flCntx,IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
IPv4Address dstIP;
if(eth.getEtherType() == EthType.IPv4)
{
IPv4 ipv4 = (IPv4) eth.getPayload();
dstIP = ipv4.getDestinationAddress();
return dstIP.getInt();
}
else if (eth.getEtherType() == EthType.ARP){
ARP arp = (ARP) eth.getPayload();
dstIP = arp.getTargetProtocolAddress();
return dstIP.getInt();
}
//for other packets without destination IP information
return 0;
}
示例3: getARPSenderMAC
import net.floodlightcontroller.packet.ARP; //导入依赖的package包/类
@Override
public long getARPSenderMAC(FPContext cntx){
FloodlightContext flCntx = cntx.getFlowContext();
Ethernet eth = IFloodlightProviderService.bcStore.get(flCntx,IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
MacAddress senderMAC;
if (eth.getEtherType() == EthType.ARP){
ARP arp = (ARP) eth.getPayload();
senderMAC = arp.getSenderHardwareAddress();
return senderMAC.getLong();
}
//for other non-arp packets
return 0;
}
示例4: getARPTargetMAC
import net.floodlightcontroller.packet.ARP; //导入依赖的package包/类
@Override
public long getARPTargetMAC(FPContext cntx){
FloodlightContext flCntx = cntx.getFlowContext();
Ethernet eth = IFloodlightProviderService.bcStore.get(flCntx,IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
MacAddress senderMAC;
if (eth.getEtherType() == EthType.ARP){
ARP arp = (ARP) eth.getPayload();
senderMAC = arp.getTargetHardwareAddress();
return senderMAC.getLong();
}
//for other non-arp packets
return 0;
}
示例5: updateTopologyMappings
import net.floodlightcontroller.packet.ARP; //导入依赖的package包/类
public void updateTopologyMappings(IOFSwitch sw, OFPacketIn pi, FloodlightContext cntx) {
Ethernet eth = IFloodlightProviderService.bcStore.get(cntx,IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
if (eth.getPayload() instanceof IPv4) {
IPv4 ip_pkt = (IPv4) eth.getPayload();
if (ip_pkt.getSourceAddress().getInt() > 0) {
IpToMac.put(ip_pkt.getSourceAddress(), eth.getSourceMACAddress());
IpToSwitch.put(ip_pkt.getSourceAddress(),new SwitchHostInfo(sw,pi.getMatch().get(MatchField.IN_PORT)));
}
}
else if (eth.getPayload() instanceof ARP) {
ARP arp_pkt = (ARP) eth.getPayload();
if (IPv4Address.of(arp_pkt.getSenderProtocolAddress()).getInt() > 0) {
if (!IPv4Address.of(arp_pkt.getSenderProtocolAddress()).toString().contentEquals("10.0.0.111")) {// ignore crafted requests from switches
IpToMac.put(IPv4Address.of(arp_pkt.getSenderProtocolAddress()), eth.getSourceMACAddress());
IpToSwitch.put(IPv4Address.of(arp_pkt.getSenderProtocolAddress()),new SwitchHostInfo(sw,pi.getMatch().get(MatchField.IN_PORT)));
}
}
}
}
示例6: receive
import net.floodlightcontroller.packet.ARP; //导入依赖的package包/类
@Override
public net.floodlightcontroller.core.IListener.Command receive(IOFSwitch sw, OFMessage msg, FloodlightContext cntx) {
Ethernet eth = IFloodlightProviderService.bcStore.get(cntx,IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
oTopologyManager.updateTopologyMappings(sw, (OFPacketIn) msg, cntx);
//log.debug("receive {}",eth);
if ((eth.getPayload() instanceof ARP)) {
handleARP(sw, (OFPacketIn) msg, cntx);
}
else if (eth.getPayload() instanceof IPv4) {
handleIP(sw, (OFPacketIn) msg, cntx);
}
else {
//handleCbench(sw, (OFPacketIn) msg, cntx);
//log.warn("could not handle packet {}",eth.toString());
}
return Command.CONTINUE;
}
示例7: sendArpReply
import net.floodlightcontroller.packet.ARP; //导入依赖的package包/类
private void sendArpReply(MacAddress senderMac, IPv4Address senderIp, MacAddress targetMac, IPv4Address targetIp, IOFSwitch sw, OFPort port) {
IPacket arpReply = new Ethernet()
.setSourceMACAddress(senderMac)
.setDestinationMACAddress(targetMac)
.setEtherType(EthType.ARP)
.setPayload(
new ARP()
.setHardwareType(ARP.HW_TYPE_ETHERNET)
.setProtocolType(ARP.PROTO_TYPE_IP)
.setHardwareAddressLength((byte) 6)
.setProtocolAddressLength((byte) 4)
.setOpCode(ARP.OP_REPLY)
.setSenderHardwareAddress(senderMac.getBytes())
.setSenderProtocolAddress(senderIp.getBytes())
.setTargetHardwareAddress(targetMac.getBytes())
.setTargetProtocolAddress(targetIp.getBytes()));
pushPacket(arpReply, sw, OFBufferId.NO_BUFFER, OFPort.ANY, port);
}
示例8: generateARPPing
import net.floodlightcontroller.packet.ARP; //导入依赖的package包/类
protected byte[] generateARPPing(InetAddress ip, MACAddress mac){
targetIP = ip;
ARP arp = new ARP().setHardwareType(ARP.HW_TYPE_ETHERNET)
.setProtocolType(ARP.PROTO_TYPE_IP)
.setHardwareAddressLength((byte) 6)
.setProtocolAddressLength((byte) 4)
.setOpCode(ARP.OP_RARP_REQUEST)
.setSenderHardwareAddress(senderMAC.toBytes())
.setSenderProtocolAddress(senderIP.getAddress())
.setTargetHardwareAddress(emptyMAC.toBytes())
.setTargetProtocolAddress(targetIP.getAddress());
Ethernet ethernet = new Ethernet().setSourceMACAddress(senderMAC.toBytes())
.setDestinationMACAddress(broadcastMAC.toBytes())
.setEtherType(Ethernet.TYPE_ARP);
ethernet.setPayload(arp);
return ethernet.serialize();
}
示例9: getSrcNwAddr
import net.floodlightcontroller.packet.ARP; //导入依赖的package包/类
/**
* Get IP address from packet if the packet is either an ARP
* or a DHCP packet
* @param eth
* @param dlAddr
* @return
*/
private int getSrcNwAddr(Ethernet eth, long dlAddr) {
if (eth.getPayload() instanceof ARP) {
ARP arp = (ARP) eth.getPayload();
if ((arp.getProtocolType() == ARP.PROTO_TYPE_IP) &&
(Ethernet.toLong(arp.getSenderHardwareAddress()) == dlAddr)) {
return IPv4.toIPv4Address(arp.getSenderProtocolAddress());
}
} else if (eth.getPayload() instanceof IPv4) {
IPv4 ipv4 = (IPv4) eth.getPayload();
if (ipv4.getPayload() instanceof UDP) {
UDP udp = (UDP)ipv4.getPayload();
if (udp.getPayload() instanceof DHCP) {
DHCP dhcp = (DHCP)udp.getPayload();
if (dhcp.getOpCode() == DHCP.OPCODE_REPLY) {
return ipv4.getSourceAddress();
}
}
}
}
return 0;
}
示例10: getSrcIPv4AddrFromARP
import net.floodlightcontroller.packet.ARP; //导入依赖的package包/类
/**
* Get sender IPv4 address from packet if the packet is an ARP
* packet and if the source MAC address matches the ARP packets
* sender MAC address.
* @param eth
* @param dlAddr
* @return
*/
private IPv4Address getSrcIPv4AddrFromARP(Ethernet eth, MacAddress dlAddr) {
if (eth.getPayload() instanceof ARP) {
ARP arp = (ARP) eth.getPayload();
if ((arp.getProtocolType() == ARP.PROTO_TYPE_IP) && (arp.getSenderHardwareAddress().equals(dlAddr))) {
return arp.getSenderProtocolAddress();
}
}
return IPv4Address.NONE;
}
示例11: learnDeviceFromArpResponseData
import net.floodlightcontroller.packet.ARP; //导入依赖的package包/类
/**
* Learn device from ARP data in scenarios where the
* Ethernet source MAC is different from the sender hardware
* address in ARP data.
*/
protected void learnDeviceFromArpResponseData(Ethernet eth,
DatapathId swdpid,
OFPort port) {
if (!(eth.getPayload() instanceof ARP)) return;
ARP arp = (ARP) eth.getPayload();
MacAddress dlAddr = eth.getSourceMACAddress();
MacAddress senderAddr = arp.getSenderHardwareAddress();
if (dlAddr.equals(senderAddr)) return; // arp request
// Ignore broadcast/multicast source
if (senderAddr.isBroadcast() || senderAddr.isMulticast())
return;
// Ignore zero sender mac
if (senderAddr.equals(MacAddress.of(0)))
return;
VlanVid vlan = VlanVid.ofVlan(eth.getVlanID());
IPv4Address nwSrc = arp.getSenderProtocolAddress();
Entity e = new Entity(senderAddr,
vlan, /* will either be a valid tag or VlanVid.ZERO if untagged */
nwSrc,
IPv6Address.NONE, /* must be none for ARP */
swdpid,
port,
new Date());
learnDeviceByEntity(e);
}
示例12: vipProxyArpReply
import net.floodlightcontroller.packet.ARP; //导入依赖的package包/类
/**
* used to send proxy Arp for load balanced service requests
* @param IOFSwitch sw
* @param OFPacketIn pi
* @param FloodlightContext cntx
* @param String vipId
*/
protected void vipProxyArpReply(IOFSwitch sw, OFPacketIn pi, FloodlightContext cntx, String vipId) {
log.debug("vipProxyArpReply");
Ethernet eth = IFloodlightProviderService.bcStore.get(cntx,
IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
// retrieve original arp to determine host configured gw IP address
if (! (eth.getPayload() instanceof ARP))
return;
ARP arpRequest = (ARP) eth.getPayload();
// have to do proxy arp reply since at this point we cannot determine the requesting application type
// generate proxy ARP reply
IPacket arpReply = new Ethernet()
.setSourceMACAddress(vips.get(vipId).proxyMac)
.setDestinationMACAddress(eth.getSourceMACAddress())
.setEtherType(EthType.ARP)
.setVlanID(eth.getVlanID())
.setPriorityCode(eth.getPriorityCode())
.setPayload(
new ARP()
.setHardwareType(ARP.HW_TYPE_ETHERNET)
.setProtocolType(ARP.PROTO_TYPE_IP)
.setHardwareAddressLength((byte) 6)
.setProtocolAddressLength((byte) 4)
.setOpCode(ARP.OP_REPLY)
.setSenderHardwareAddress(vips.get(vipId).proxyMac)
.setSenderProtocolAddress(arpRequest.getTargetProtocolAddress())
.setTargetHardwareAddress(eth.getSourceMACAddress())
.setTargetProtocolAddress(arpRequest.getSenderProtocolAddress()));
// push ARP reply out
pushPacket(arpReply, sw, OFBufferId.NO_BUFFER, OFPort.ANY, (pi.getVersion().compareTo(OFVersion.OF_12) < 0 ? pi.getInPort() : pi.getMatch().get(MatchField.IN_PORT)), cntx, true);
log.debug("proxy ARP reply pushed as {}", IPv4.fromIPv4Address(vips.get(vipId).address));
return;
}
示例13: handleARP
import net.floodlightcontroller.packet.ARP; //导入依赖的package包/类
private void handleARP(IOFSwitch sw, OFPacketIn pi, FloodlightContext cntx) {
Ethernet eth = IFloodlightProviderService.bcStore.get(cntx, IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
if (! (eth.getPayload() instanceof ARP)) // not an ARP packet
return;
ARP arpRequest = (ARP) eth.getPayload();
if (arpRequest.getOpCode() == ARP.OP_REPLY) { // is a reply
oTopologyManager.updateTopologyMappings(sw, pi, cntx);
for (ARP pendingArpRequest : arpRequestBuffer.getPendingRequests(IPv4Address.of(arpRequest.getSenderProtocolAddress()))) {
if (oTopologyManager.knowSwitchForIp(IPv4Address.of(pendingArpRequest.getSenderProtocolAddress()))) {
SwitchHostInfo dstSwitchPort = oTopologyManager.getSwitchForIp(IPv4Address.of(pendingArpRequest.getSenderProtocolAddress()));
sendArpReply(MacAddress.of(arpRequest.getSenderHardwareAddress()), IPv4Address.of(arpRequest.getSenderProtocolAddress()), MacAddress.of(pendingArpRequest.getSenderHardwareAddress()), IPv4Address.of(pendingArpRequest.getSenderProtocolAddress()), dstSwitchPort.getSwitch(), dstSwitchPort.getPort());
arpRequestBuffer.removeRequest(pendingArpRequest);
}
else
log.warn("answering pending ARP request failed because dst switch/port is not known. {}",pendingArpRequest);
}
}
else { // is a request
if (IPv4Address.of(arpRequest.getSenderProtocolAddress()).toString().contentEquals("10.0.0.111")) // ignore crafted requests from switches
return;
if (oTopologyManager.knowMacForIp(IPv4Address.of(arpRequest.getTargetProtocolAddress()))) {
MacAddress senderMac = oTopologyManager.getMacForIp(IPv4Address.of(arpRequest.getTargetProtocolAddress()));
sendArpReply(senderMac, IPv4Address.of(arpRequest.getTargetProtocolAddress()), MacAddress.of(arpRequest.getSenderHardwareAddress()), IPv4Address.of(arpRequest.getSenderProtocolAddress()), sw, pi.getMatch().get(MatchField.IN_PORT));
}
else {
arpRequestBuffer.addRequest(arpRequest);
for (DatapathId swi : switchService.getAllSwitchDpids())
floodArpRequest(switchService.getSwitch(swi),IPv4Address.of(arpRequest.getTargetProtocolAddress()));
}
}
}
示例14: floodArpRequest
import net.floodlightcontroller.packet.ARP; //导入依赖的package包/类
private void floodArpRequest(IOFSwitch sw, IPv4Address requestedAddress) {
IPacket arpRequest = new Ethernet()
.setSourceMACAddress("00:00:00:00:00:01")
.setDestinationMACAddress("ff:ff:ff:ff:ff:ff")
.setEtherType(EthType.ARP)
.setVlanID((short) 0)
.setPriorityCode((byte) 0)
.setPayload(
new ARP()
.setHardwareType(ARP.HW_TYPE_ETHERNET)
.setProtocolType(ARP.PROTO_TYPE_IP)
.setHardwareAddressLength((byte) 6)
.setProtocolAddressLength((byte) 4)
.setOpCode(ARP.OP_REQUEST)
.setSenderHardwareAddress(HexString.fromHexString("00:00:00:00:00:01"))
.setSenderProtocolAddress(IPv4.toIPv4AddressBytes("10.0.0.111"))
.setTargetHardwareAddress(HexString.fromHexString("00:00:00:00:00:00"))
.setTargetProtocolAddress(requestedAddress.getBytes()));
Set<OFPort> portsConnectedToSwitches = new HashSet<OFPort>();
for (Link link : linkDiscoveryService.getSwitchLinks().get(sw.getId())) {
if (link.getSrc() == sw.getId())
portsConnectedToSwitches.add(link.getSrcPort());
}
for (OFPortDesc port : sw.getPorts()) {
if (!portsConnectedToSwitches.contains(port.getPortNo())) {
pushPacket(arpRequest, sw, OFBufferId.NO_BUFFER, OFPort.ANY, port.getPortNo());
}
}
}
示例15: getSrcNwAddr
import net.floodlightcontroller.packet.ARP; //导入依赖的package包/类
/**
* Get sender IP address from packet if the packet is an ARP
* packet and if the source MAC address matches the ARP packets
* sender MAC address.
* @param eth
* @param dlAddr
* @return
*/
private IPv4Address getSrcNwAddr(Ethernet eth, MacAddress dlAddr) {
if (eth.getPayload() instanceof ARP) {
ARP arp = (ARP) eth.getPayload();
if ((arp.getProtocolType() == ARP.PROTO_TYPE_IP) && (MacAddress.of(arp.getSenderHardwareAddress()).equals(dlAddr))) {
return IPv4Address.of(arp.getSenderProtocolAddress());
}
}
return IPv4Address.NONE;
}