本文整理汇总了Java中net.floodlightcontroller.packet.Ethernet.getSourceMACAddress方法的典型用法代码示例。如果您正苦于以下问题:Java Ethernet.getSourceMACAddress方法的具体用法?Java Ethernet.getSourceMACAddress怎么用?Java Ethernet.getSourceMACAddress使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.floodlightcontroller.packet.Ethernet
的用法示例。
在下文中一共展示了Ethernet.getSourceMACAddress方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSourceEntityFromPacket
import net.floodlightcontroller.packet.Ethernet; //导入方法依赖的package包/类
/**
* Parse an entity from an {@link Ethernet} packet.
* @param eth the packet to parse
* @param sw the switch on which the packet arrived
* @param pi the original packetin
* @return the entity from the packet
*/
protected Entity getSourceEntityFromPacket(Ethernet eth, DatapathId swdpid, OFPort port) {
MacAddress dlAddr = eth.getSourceMACAddress();
// Ignore broadcast/multicast source
if (dlAddr.isBroadcast() || dlAddr.isMulticast())
return null;
// Ignore 0 source mac
if (dlAddr.getLong() == 0)
return null;
VlanVid vlan = VlanVid.ofVlan(eth.getVlanID());
IPv4Address ipv4Src = getSrcIPv4AddrFromARP(eth, dlAddr);
IPv6Address ipv6Src = ipv4Src.equals(IPv4Address.NONE) ? getSrcIPv6Addr(eth) : IPv6Address.NONE;
return new Entity(dlAddr,
vlan,
ipv4Src,
ipv6Src,
swdpid,
port,
new Date());
}
示例2: createMatchFromPacket
import net.floodlightcontroller.packet.Ethernet; //导入方法依赖的package包/类
protected Match createMatchFromPacket(IOFSwitch sw, OFPort inPort, FloodlightContext cntx) {
// The packet in match will only contain the port number.
// We need to add in specifics for the hosts we're routing between.
Ethernet eth = IFloodlightProviderService.bcStore.get(cntx, IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
VlanVid vlan = VlanVid.ofVlan(eth.getVlanID());
MacAddress srcMac = eth.getSourceMACAddress();
MacAddress dstMac = eth.getDestinationMACAddress();
Match.Builder mb = sw.getOFFactory().buildMatch();
mb.setExact(MatchField.IN_PORT, inPort)
.setExact(MatchField.ETH_SRC, srcMac)
.setExact(MatchField.ETH_DST, dstMac);
if (!vlan.equals(VlanVid.ZERO)) {
mb.setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlanVid(vlan));
}
return mb.build();
}
示例3: isDefaultGateway
import net.floodlightcontroller.packet.Ethernet; //导入方法依赖的package包/类
/**
* Checks whether the frame is destined to or from a gateway.
* @param frame The ethernet frame to check.
* @return True if it is to/from a gateway, false otherwise.
*/
protected boolean isDefaultGateway(Ethernet frame) {
if (macToGateway.containsKey(frame.getSourceMACAddress()))
return true;
IPv4Address gwIp = macToGateway.get(frame.getDestinationMACAddress());
if (gwIp != null) {
MacAddress host = frame.getSourceMACAddress();
String srcNet = macToGuid.get(host);
if (srcNet != null) {
IPv4Address gwIpSrcNet = guidToGateway.get(srcNet);
if ((gwIpSrcNet != null) && (gwIp.equals(gwIpSrcNet)))
return true;
}
}
return false;
}
示例4: getSourceEntityFromPacket
import net.floodlightcontroller.packet.Ethernet; //导入方法依赖的package包/类
/**
* Parse an entity from an {@link Ethernet} packet.
* @param eth the packet to parse
* @param sw the switch on which the packet arrived
* @param pi the original packetin
* @return the entity from the packet
*/
protected Entity getSourceEntityFromPacket(Ethernet eth, DatapathId swdpid, OFPort port) {
MacAddress dlAddr = eth.getSourceMACAddress();
// Ignore broadcast/multicast source
if (dlAddr.isBroadcast() || dlAddr.isMulticast())
return null;
// Ignore 0 source mac
if (dlAddr.getLong() == 0)
return null;
VlanVid vlan = VlanVid.ofVlan(eth.getVlanID());
IPv4Address nwSrc = getSrcNwAddr(eth, dlAddr);
return new Entity(dlAddr,
vlan,
nwSrc,
swdpid,
port,
new Date());
}
示例5: learnDeviceFromArpResponseData
import net.floodlightcontroller.packet.Ethernet; //导入方法依赖的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);
}
示例6: learnDeviceFromArpResponseData
import net.floodlightcontroller.packet.Ethernet; //导入方法依赖的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 = MacAddress.of(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.getLong() == 0)
return;
VlanVid vlan = VlanVid.ofVlan(eth.getVlanID());
IPv4Address nwSrc = IPv4Address.of(arp.getSenderProtocolAddress());
Entity e = new Entity(senderAddr,
((vlan.getVlan() >= 0) ? vlan : null),
((nwSrc.getInt() != 0) ? nwSrc : null),
swdpid,
port,
new Date());
learnDeviceByEntity(e);
}
示例7: learnDeviceFromArpResponseData
import net.floodlightcontroller.packet.Ethernet; //导入方法依赖的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,
long swdpid,
int port) {
if (!(eth.getPayload() instanceof ARP)) return;
ARP arp = (ARP) eth.getPayload();
byte[] dlAddrArr = eth.getSourceMACAddress();
long dlAddr = Ethernet.toLong(dlAddrArr);
byte[] senderHardwareAddr = arp.getSenderHardwareAddress();
long senderAddr = Ethernet.toLong(senderHardwareAddr);
if (dlAddr == senderAddr) return;
// Ignore broadcast/multicast source
if ((senderHardwareAddr[0] & 0x1) != 0)
return;
// Ignore zero sender mac
if (senderAddr == 0)
return;
short vlan = eth.getVlanID();
int nwSrc = IPv4.toIPv4Address(arp.getSenderProtocolAddress());
Entity e = new Entity(senderAddr,
((vlan >= 0) ? vlan : null),
((nwSrc != 0) ? nwSrc : null),
swdpid,
port,
new Date());
learnDeviceByEntity(e);
}
示例8: createMatchFromPacket
import net.floodlightcontroller.packet.Ethernet; //导入方法依赖的package包/类
/**
* Instead of using the Firewall's routing decision Match, which might be as general
* as "in_port" and inadvertently Match packets erroneously, construct a more
* specific Match based on the deserialized OFPacketIn's payload, which has been
* placed in the FloodlightContext already by the Controller.
*
* @param sw, the switch on which the packet was received
* @param inPort, the ingress switch port on which the packet was received
* @param cntx, the current context which contains the deserialized packet
* @return a composed Match object based on the provided information
*/
protected Match createMatchFromPacket(IOFSwitch sw, OFPort inPort, FloodlightContext cntx) {
// The packet in match will only contain the port number.
// We need to add in specifics for the hosts we're routing between.
Ethernet eth = IFloodlightProviderService.bcStore.get(cntx, IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
VlanVid vlan = VlanVid.ofVlan(eth.getVlanID());
MacAddress srcMac = eth.getSourceMACAddress();
MacAddress dstMac = eth.getDestinationMACAddress();
// A retentive builder will remember all MatchFields of the parent the builder was generated from
// With a normal builder, all parent MatchFields will be lost if any MatchFields are added, mod, del
// TODO (This is a bug in Loxigen and the retentive builder is a workaround.)
Match.Builder mb = sw.getOFFactory().buildMatch();
mb.setExact(MatchField.IN_PORT, inPort)
.setExact(MatchField.ETH_SRC, srcMac)
.setExact(MatchField.ETH_DST, dstMac);
if (!vlan.equals(VlanVid.ZERO)) {
mb.setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlanVid(vlan));
}
// TODO Detect switch type and match to create hardware-implemented flow
// TODO Set option in config file to support specific or MAC-only matches
if (eth.getEtherType() == EthType.IPv4) { /* shallow check for equality is okay for EthType */
IPv4 ip = (IPv4) eth.getPayload();
IPv4Address srcIp = ip.getSourceAddress();
IPv4Address dstIp = ip.getDestinationAddress();
mb.setExact(MatchField.IPV4_SRC, srcIp)
.setExact(MatchField.IPV4_DST, dstIp)
.setExact(MatchField.ETH_TYPE, EthType.IPv4);
if (ip.getProtocol().equals(IpProtocol.TCP)) {
TCP tcp = (TCP) ip.getPayload();
mb.setExact(MatchField.IP_PROTO, IpProtocol.TCP)
.setExact(MatchField.TCP_SRC, tcp.getSourcePort())
.setExact(MatchField.TCP_DST, tcp.getDestinationPort());
} else if (ip.getProtocol().equals(IpProtocol.UDP)) {
UDP udp = (UDP) ip.getPayload();
mb.setExact(MatchField.IP_PROTO, IpProtocol.UDP)
.setExact(MatchField.UDP_SRC, udp.getSourcePort())
.setExact(MatchField.UDP_DST, udp.getDestinationPort());
}
} else if (eth.getEtherType() == EthType.ARP) { /* shallow check for equality is okay for EthType */
mb.setExact(MatchField.ETH_TYPE, EthType.ARP);
}
return mb.build();
}
示例9: getSrcMac
import net.floodlightcontroller.packet.Ethernet; //导入方法依赖的package包/类
@Override
public long getSrcMac(FPContext cntx) {
FloodlightContext flCntx = cntx.getFlowContext();
Ethernet eth = IFloodlightProviderService.bcStore.get(flCntx,IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
MacAddress srcMac = eth.getSourceMACAddress();
return srcMac.getLong();
}
示例10: getDstMac
import net.floodlightcontroller.packet.Ethernet; //导入方法依赖的package包/类
@Override
public long getDstMac(FPContext cntx) {
FloodlightContext flCntx = cntx.getFlowContext();
Ethernet eth = IFloodlightProviderService.bcStore.get(flCntx,IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
MacAddress dstMac = eth.getSourceMACAddress();
return dstMac.getLong();
}