本文整理汇总了Java中net.floodlightcontroller.packet.Ethernet类的典型用法代码示例。如果您正苦于以下问题:Java Ethernet类的具体用法?Java Ethernet怎么用?Java Ethernet使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Ethernet类属于net.floodlightcontroller.packet包,在下文中一共展示了Ethernet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deserialize
import net.floodlightcontroller.packet.Ethernet; //导入依赖的package包/类
private VerificationPacket deserialize(Ethernet eth) throws Exception {
if (eth.getPayload() instanceof IPv4) {
IPv4 ip = (IPv4) eth.getPayload();
if (ip.getPayload() instanceof UDP) {
UDP udp = (UDP) ip.getPayload();
if ((udp.getSourcePort().getPort() == PathVerificationService.VERIFICATION_PACKET_UDP_PORT)
&& (udp.getDestinationPort()
.getPort() == PathVerificationService.VERIFICATION_PACKET_UDP_PORT)) {
return new VerificationPacket((Data) udp.getPayload());
}
}
}
throw new Exception("Ethernet packet was not a verification packet");
}
示例2: dispatchMessage
import net.floodlightcontroller.packet.Ethernet; //导入依赖的package包/类
public void dispatchMessage(IOFSwitch sw, OFMessage msg, FloodlightContext bc) {
List<IOFMessageListener> theListeners = listeners.get(msg.getType()).getOrderedListeners();
if (theListeners != null) {
Command result = Command.CONTINUE;
Iterator<IOFMessageListener> it = theListeners.iterator();
if (OFType.PACKET_IN.equals(msg.getType())) {
OFPacketIn pi = (OFPacketIn)msg;
Ethernet eth = new Ethernet();
eth.deserialize(pi.getData(), 0, pi.getData().length);
IFloodlightProviderService.bcStore.put(bc,
IFloodlightProviderService.CONTEXT_PI_PAYLOAD,
eth);
}
while (it.hasNext() && !Command.STOP.equals(result)) {
result = it.next().receive(sw, msg, bc);
}
}
// paag
for (IControllerCompletionListener listener:completionListeners)
listener.onMessageConsumed(sw, msg, bc);
}
示例3: getSrcIP
import net.floodlightcontroller.packet.Ethernet; //导入依赖的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;
}
示例4: getDstIP
import net.floodlightcontroller.packet.Ethernet; //导入依赖的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;
}
示例5: getARPSenderMAC
import net.floodlightcontroller.packet.Ethernet; //导入依赖的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;
}
示例6: getARPTargetMAC
import net.floodlightcontroller.packet.Ethernet; //导入依赖的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;
}
示例7: snoopDHCPClientName
import net.floodlightcontroller.packet.Ethernet; //导入依赖的package包/类
/**
* Snoop and record client-provided host name from DHCP requests
* @param eth
* @param srcDevice
*/
private void snoopDHCPClientName(Ethernet eth, Device srcDevice) {
if (! (eth.getPayload() instanceof IPv4) )
return;
IPv4 ipv4 = (IPv4) eth.getPayload();
if (! (ipv4.getPayload() instanceof UDP) )
return;
UDP udp = (UDP) ipv4.getPayload();
if (!(udp.getPayload() instanceof DHCP))
return;
DHCP dhcp = (DHCP) udp.getPayload();
byte opcode = dhcp.getOpCode();
if (opcode == DHCP.OPCODE_REQUEST) {
DHCPOption dhcpOption = dhcp.getOption(
DHCPOptionCode.OptionCode_Hostname);
if (dhcpOption != null) {
cntDhcpClientNameSnooped.increment();
srcDevice.dhcpClientName = new String(dhcpOption.getData());
}
}
}
示例8: 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());
}
示例9: 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();
}
示例10: 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;
}
示例11: processPacketInMessage
import net.floodlightcontroller.packet.Ethernet; //导入依赖的package包/类
protected Command processPacketInMessage(IOFSwitch sw, OFPacketIn pi, FloodlightContext cntx) {
// get the packet-in switch.
Ethernet eth =
IFloodlightProviderService.bcStore.
get(cntx,IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
if (eth.getPayload() instanceof BSN) {
BSN bsn = (BSN) eth.getPayload();
if (bsn == null) return Command.STOP;
if (bsn.getPayload() == null) return Command.STOP;
// It could be a packet other than BSN LLDP, therefore
// continue with the regular processing.
if (bsn.getPayload() instanceof LLDP == false)
return Command.CONTINUE;
doFloodBDDP(sw.getId(), pi, cntx);
return Command.STOP;
} else {
return dropFilter(sw.getId(), pi, cntx);
}
}
示例12: createPacketIn
import net.floodlightcontroller.packet.Ethernet; //导入依赖的package包/类
private OFPacketIn createPacketIn(String srcMAC, String dstMAC,
String srcIp, String dstIp, short vlan) {
IPacket testPacket = new Ethernet()
.setDestinationMACAddress(dstMAC)
.setSourceMACAddress(srcMAC)
.setVlanID(vlan)
.setEtherType(EthType.IPv4)
.setPayload(
new IPv4()
.setTtl((byte) 128)
.setSourceAddress(srcIp)
.setDestinationAddress(dstIp)
.setPayload(new UDP()
.setSourcePort((short) 5000)
.setDestinationPort((short) 5001)
.setPayload(new Data(new byte[] {0x01}))));
byte[] testPacketSerialized = testPacket.serialize();
OFPacketIn pi;
// build out input packet
pi = OFFactories.getFactory(OFVersion.OF_13).buildPacketIn()
.setBufferId(OFBufferId.NO_BUFFER)
.setData(testPacketSerialized)
.setReason(OFPacketInReason.NO_MATCH)
.build();
return pi;
}
示例13: setObfuscatedHeader
import net.floodlightcontroller.packet.Ethernet; //导入依赖的package包/类
public void setObfuscatedHeader(Ethernet eth) {
try {
//System.out.println(m.get(MatchField.ETH_SRC).getLong());
//System.out.println(m.get(MatchField.ETH_SRC));
encodeInBitSet(obfuscatedHeaderValue, ObfuscationPolicy.Field.MAC_SRC.getOffset(), ObfuscationPolicy.Field.MAC_SRC.getLength(), eth.getSourceMACAddress().getLong());
encodeInBitSet(obfuscatedHeaderValue, ObfuscationPolicy.Field.MAC_DST.getOffset(), ObfuscationPolicy.Field.MAC_DST.getLength(), eth.getDestinationMACAddress().getLong());
if (eth.getPayload() instanceof IPv4) {
IPv4 ip_pkt = (IPv4) eth.getPayload();
encodeInBitSet(obfuscatedHeaderValue, ObfuscationPolicy.Field.IP_SRC.getOffset(), ObfuscationPolicy.Field.IP_SRC.getLength(), ip_pkt.getSourceAddress().getInt());
encodeInBitSet(obfuscatedHeaderValue, ObfuscationPolicy.Field.IP_DST.getOffset(), ObfuscationPolicy.Field.IP_DST.getLength(), ip_pkt.getDestinationAddress().getInt());
}
}
catch (Exception e) {
e.printStackTrace();
System.out.println(eth);
}
}
示例14: updateTopologyMappings
import net.floodlightcontroller.packet.Ethernet; //导入依赖的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)));
}
}
}
}
示例15: receive
import net.floodlightcontroller.packet.Ethernet; //导入依赖的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;
}