本文整理汇总了Java中net.floodlightcontroller.packet.Ethernet.toLong方法的典型用法代码示例。如果您正苦于以下问题:Java Ethernet.toLong方法的具体用法?Java Ethernet.toLong怎么用?Java Ethernet.toLong使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.floodlightcontroller.packet.Ethernet
的用法示例。
在下文中一共展示了Ethernet.toLong方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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,
long swdpid,
int port) {
byte[] dlAddrArr = eth.getSourceMACAddress();
long dlAddr = Ethernet.toLong(dlAddrArr);
// Ignore broadcast/multicast source
if ((dlAddrArr[0] & 0x1) != 0)
return null;
// Ignore 0 source mac
if (dlAddr == 0)
return null;
short vlan = eth.getVlanID();
int nwSrc = getSrcNwAddr(eth, dlAddr);
return new Entity(dlAddr,
((vlan >= 0) ? vlan : null),
((nwSrc != 0) ? nwSrc : null),
swdpid,
port,
new Date());
}
示例2: getDestEntityFromPacket
import net.floodlightcontroller.packet.Ethernet; //导入方法依赖的package包/类
/**
* Get a (partial) entity for the destination from the packet.
* @param eth
* @return
*/
protected Entity getDestEntityFromPacket(Ethernet eth) {
byte[] dlAddrArr = eth.getDestinationMACAddress();
long dlAddr = Ethernet.toLong(dlAddrArr);
short vlan = eth.getVlanID();
int nwDst = 0;
// Ignore broadcast/multicast destination
if ((dlAddrArr[0] & 0x1) != 0)
return null;
// Ignore zero dest mac
if (dlAddr == 0)
return null;
if (eth.getPayload() instanceof IPv4) {
IPv4 ipv4 = (IPv4) eth.getPayload();
nwDst = ipv4.getDestinationAddress();
}
return new Entity(dlAddr,
((vlan >= 0) ? vlan : null),
((nwDst != 0) ? nwDst : null),
null,
null,
null);
}
示例3: getSrcNwAddr
import net.floodlightcontroller.packet.Ethernet; //导入方法依赖的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 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());
}
}
return 0;
}
示例4: 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);
}
示例5: getEntityFromFlowMod
import net.floodlightcontroller.packet.Ethernet; //导入方法依赖的package包/类
/**
* Parse an entity from an OFMatchWithSwDpid.
* @param ofmWithSwDpid
* @return the entity from the packet
*/
private Entity getEntityFromFlowMod(OFMatchWithSwDpid ofmWithSwDpid,
boolean isSource) {
byte[] dlAddrArr = ofmWithSwDpid.getOfMatch().getDataLayerSource();
int nwSrc = ofmWithSwDpid.getOfMatch().getNetworkSource();
if (!isSource) {
dlAddrArr = ofmWithSwDpid.getOfMatch().getDataLayerDestination();
nwSrc = ofmWithSwDpid.getOfMatch().getNetworkDestination();
}
long dlAddr = Ethernet.toLong(dlAddrArr);
// Ignore broadcast/multicast source
if ((dlAddrArr[0] & 0x1) != 0)
return null;
Long swDpid = null;
Short inPort = null;
if (isSource) {
swDpid = ofmWithSwDpid.getSwitchDataPathId();
inPort = ofmWithSwDpid.getOfMatch().getInputPort();
}
/**for the new flow cache design, the flow mods retrived are not always
* from the source, learn AP should be disabled --meiyang*/
boolean learnap = false;
/**
* if (swDpid == null ||
inPort == null ||
!isValidAttachmentPoint(swDpid, inPort)) {
// If this is an internal port or we otherwise don't want
// to learn on these ports. In the future, we should
// handle this case by labeling flows with something that
// will give us the entity class. For now, we'll do our
// best assuming attachment point information isn't used
// as a key field.
learnap = false;
}
*/
short vlan = ofmWithSwDpid.getOfMatch().getDataLayerVirtualLan();
return new Entity(dlAddr,
((vlan >= 0) ? vlan : null),
((nwSrc != 0) ? nwSrc : null),
(learnap ? swDpid : null),
(learnap ? (int)inPort : null),
new Date());
}
示例6: processPacketInMessage
import net.floodlightcontroller.packet.Ethernet; //导入方法依赖的package包/类
/**
* Processes a OFPacketIn message. If the switch has learned the MAC/VLAN to port mapping
* for the pair it will write a FlowMod for. If the mapping has not been learned the
* we will flood the packet.
* @param sw
* @param pi
* @param cntx
* @return
*/
private Command processPacketInMessage(IOFSwitch sw, OFPacketIn pi, FloodlightContext cntx) {
// Read in packet data headers by using OFMatch
OFMatch match = new OFMatch();
match.loadFromPacket(pi.getPacketData(), pi.getInPort());
Long sourceMac = Ethernet.toLong(match.getDataLayerSource());
Long destMac = Ethernet.toLong(match.getDataLayerDestination());
Short vlan = match.getDataLayerVirtualLan();
if ((destMac & 0xfffffffffff0L) == 0x0180c2000000L) {
if (log.isTraceEnabled()) {
log.trace("ignoring packet addressed to 802.1D/Q reserved addr: switch {} vlan {} dest MAC {}",
new Object[]{ sw, vlan, HexString.toHexString(destMac) });
}
return Command.STOP;
}
if ((sourceMac & 0x010000000000L) == 0) {
// If source MAC is a unicast address, learn the port for this MAC/VLAN
this.addToPortMap(sw, sourceMac, vlan, pi.getInPort());
}
// Now output flow-mod and/or packet
Short outPort = getFromPortMap(sw, destMac, vlan);
if (outPort == null) {
// If we haven't learned the port for the dest MAC/VLAN, flood it
// Don't flood broadcast packets if the broadcast is disabled.
// XXX For LearningSwitch this doesn't do much. The sourceMac is removed
// from port map whenever a flow expires, so you would still see
// a lot of floods.
this.writePacketOutForPacketIn(sw, pi, OFPort.OFPP_FLOOD.getValue());
} else if (outPort == match.getInputPort()) {
log.trace("ignoring packet that arrived on same port as learned destination:"
+ " switch {} vlan {} dest MAC {} port {}",
new Object[]{ sw, vlan, HexString.toHexString(destMac), outPort });
} else {
// Add flow table entry matching source MAC, dest MAC, VLAN and input port
// that sends to the port we previously learned for the dest MAC/VLAN. Also
// add a flow table entry with source and destination MACs reversed, and
// input and output ports reversed. When either entry expires due to idle
// timeout, remove the other one. This ensures that if a device moves to
// a different port, a constant stream of packets headed to the device at
// its former location does not keep the stale entry alive forever.
// FIXME: current HP switches ignore DL_SRC and DL_DST fields, so we have to match on
// NW_SRC and NW_DST as well
match.setWildcards(((Integer)sw.getAttribute(IOFSwitch.PROP_FASTWILDCARDS)).intValue()
& ~OFMatch.OFPFW_IN_PORT
& ~OFMatch.OFPFW_DL_VLAN & ~OFMatch.OFPFW_DL_SRC & ~OFMatch.OFPFW_DL_DST
& ~OFMatch.OFPFW_NW_SRC_MASK & ~OFMatch.OFPFW_NW_DST_MASK);
// We write FlowMods with Buffer ID none then explicitly PacketOut the buffered packet
this.pushPacket(sw, match, pi, outPort);
this.writeFlowMod(sw, OFFlowMod.OFPFC_ADD, OFPacketOut.BUFFER_ID_NONE, match, outPort);
if (LEARNING_SWITCH_REVERSE_FLOW) {
this.writeFlowMod(sw, OFFlowMod.OFPFC_ADD, -1, match.clone()
.setDataLayerSource(match.getDataLayerDestination())
.setDataLayerDestination(match.getDataLayerSource())
.setNetworkSource(match.getNetworkDestination())
.setNetworkDestination(match.getNetworkSource())
.setTransportSource(match.getTransportDestination())
.setTransportDestination(match.getTransportSource())
.setInputPort(outPort),
match.getInputPort());
}
}
return Command.CONTINUE;
}
示例7: testDeviceLearningFromArpResponseData
import net.floodlightcontroller.packet.Ethernet; //导入方法依赖的package包/类
/**
* This test ensures the device manager learns the source device
* corresponding to the senderHardwareAddress and senderProtocolAddress
* in an ARP response whenever the senderHardwareAddress is different
* from the source MAC address of the Ethernet frame.
*
* @throws Exception
*/
@Test
public void testDeviceLearningFromArpResponseData() throws Exception {
ARP arp = (ARP)((Ethernet)this.testARPReplyPacket_2).getPayload();
long senderMac = Ethernet.toLong(arp.getSenderHardwareAddress());
long sourceMac =
Ethernet.toLong(((Ethernet)this.testARPReplyPacket_2)
.getSourceMACAddress());
Integer ipaddr = IPv4.toIPv4Address("192.168.1.1");
OFPacketIn packetIn = testARPReplyPacketIn_2;
// Mock up our expected behavior
ITopologyService mockTopology = createMock(ITopologyService.class);
deviceManager.topology = mockTopology;
mockTopologyForPacketInTests(mockTopology);
replay(mockTopology);
FloodlightContext cntx = new FloodlightContext();
Command cmd = dispatchPacketIn(1L, packetIn, cntx);
verify(mockTopology);
assertEquals(Command.CONTINUE, cmd);
// Verify the device for the sender HW address
Device senderDev = (Device)
deviceManager.findDevice(senderMac, (short)5, null, null, null);
verifyDevice(senderDev, senderMac, (short)5, ipaddr, 1L, 1);
Device result = null;
Iterator<? extends IDevice> dstiter =
deviceManager.queryDevices(null, null, ipaddr,
null, null);
if (dstiter.hasNext()) {
result = (Device)dstiter.next();
}
assertFalse("There shouldn't be more than 1 device", dstiter.hasNext());
assertEquals(senderDev, result);
// Verify the device for the source MAC
Device srcDev = (Device)
deviceManager.findDevice(sourceMac, (short)5, null, null, null);
// must NOT learn IP on this device
verifyDevice(srcDev, sourceMac, (short)5, null, 1L, 1);
assertFalse("Device must differ", srcDev.equals(senderDev));
// Context is annotated with this device, not the device associated
// with ARP sender address
IDevice cntxSrcDev = IDeviceService.fcStore.get(cntx,
IDeviceService.CONTEXT_SRC_DEVICE);
assertEquals(srcDev, cntxSrcDev);
assertEquals(2, deviceManager.getAllDevices().size());
}
示例8: testPacketInInvalidDstMac
import net.floodlightcontroller.packet.Ethernet; //导入方法依赖的package包/类
@Test
public void testPacketInInvalidDstMac() throws Exception {
// Mock up our expected behavior
ITopologyService mockTopology = createMock(ITopologyService.class);
deviceManager.topology = mockTopology;
mockTopologyForPacketInTests(mockTopology);
replay(mockTopology);
FloodlightContext cntx = new FloodlightContext();
long srcMac = Ethernet.toLong(testUDPPacket.getSourceMACAddress());
long dstMac = Ethernet.toLong(testUDPPacket.getDestinationMACAddress());
// Prime device manager with the source device
Command cmd = dispatchPacketIn(1L, testUDPPacketIn, cntx);
assertEquals(Command.CONTINUE, cmd);
IDevice cntxSrcDev = IDeviceService.fcStore.get(cntx,
IDeviceService.CONTEXT_SRC_DEVICE);
verifyDevice(cntxSrcDev, srcMac, (short)5, null,
1L, testUDPPacketIn.getInPort());
IDevice cntxDstDev = IDeviceService.fcStore.get(cntx,
IDeviceService.CONTEXT_DST_DEVICE);
assertNull(cntxDstDev);
IDevice expectedSrcDev = cntxSrcDev;
// Create a device for the destination. We can use testARPPacketIn_1
// for that.
cntx = new FloodlightContext();
// Prime device manager with the source device
cmd = dispatchPacketIn(1L, testARPReplyPacketIn_1, cntx);
assertEquals(Command.CONTINUE, cmd);
cntxSrcDev = IDeviceService.fcStore.get(cntx,
IDeviceService.CONTEXT_SRC_DEVICE);
// yes: we check that cntxSrcDev matched dstMAC because we are
// just adding the dest device
int ip = IPv4.toIPv4Address("192.168.1.1");
verifyDevice(cntxSrcDev, dstMac, (short)5, ip,
1L, testARPReplyPacketIn_1.getInPort());
// yes: we set the expected dst device to the current srcDev
IDevice expectedDstDev = cntxSrcDev;
//-------------------------------
// Let the real tests begin
cntx = new FloodlightContext();
testUDPPacket.setDestinationMACAddress(Ethernet.toByteArray(0L));
updateUDPPacketIn();
cmd = dispatchPacketIn(1L, testUDPPacketIn, cntx);
assertEquals(Command.STOP, cmd);
cntxDstDev = IDeviceService.fcStore.get(cntx,
IDeviceService.CONTEXT_DST_DEVICE);
assertNull(cntxDstDev);
// use a real dest mac
cntx = new FloodlightContext();
testUDPPacket.setDestinationMACAddress(Ethernet.toByteArray(dstMac));
updateUDPPacketIn();
cmd = dispatchPacketIn(1L, testUDPPacketIn, cntx);
assertEquals(Command.CONTINUE, cmd);
cntxSrcDev = IDeviceService.fcStore.get(cntx,
IDeviceService.CONTEXT_SRC_DEVICE);
assertEquals(expectedSrcDev, cntxSrcDev);
cntxDstDev = IDeviceService.fcStore.get(cntx,
IDeviceService.CONTEXT_DST_DEVICE);
assertEquals(expectedDstDev, cntxDstDev);
verify(mockTopology);
}