本文整理汇总了Java中org.projectfloodlight.openflow.types.IPv4Address.of方法的典型用法代码示例。如果您正苦于以下问题:Java IPv4Address.of方法的具体用法?Java IPv4Address.of怎么用?Java IPv4Address.of使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.projectfloodlight.openflow.types.IPv4Address
的用法示例。
在下文中一共展示了IPv4Address.of方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUp
import org.projectfloodlight.openflow.types.IPv4Address; //导入方法依赖的package包/类
@Override
protected void setUp() throws Exception {
super.setUp();
e1a = new Entity(MacAddress.of(1L), VlanVid.ofVlan(1), IPv4Address.of(1), IPv6Address.of(1, 1), DatapathId.of(1L), OFPort.of(1), new Date());
e1b = new Entity(MacAddress.of(1L), VlanVid.ofVlan(2), IPv4Address.of(1), IPv6Address.of(1, 1), DatapathId.of(1L), OFPort.of(1), new Date());
List<Entity> d1Entities = new ArrayList<Entity>(2);
d1Entities.add(e1a);
d1Entities.add(e1b);
d1 = new Device(null, Long.valueOf(1), null, null, null,
d1Entities, null);
// e2 and e2 alt match in MAC and VLAN
e2 = new Entity(MacAddress.of(2L), VlanVid.ofVlan(2), IPv4Address.of(2), IPv6Address.of(2, 2), DatapathId.of(2L), OFPort.of(2), new Date());
e2alt = new Entity(MacAddress.of(2L), VlanVid.ofVlan(2), IPv4Address.NONE, IPv6Address.NONE, DatapathId.NONE, OFPort.ZERO, Entity.NO_DATE);
// IP is null
e3 = new Entity(MacAddress.of(3L), VlanVid.ofVlan(3), IPv4Address.NONE, IPv6Address.NONE, DatapathId.of(3L), OFPort.of(3), new Date());
// IP and switch and port are null
e4 = new Entity(MacAddress.of(4L), VlanVid.ofVlan(4), IPv4Address.NONE, IPv6Address.NONE, DatapathId.NONE, OFPort.ZERO, new Date());
}
示例2: queryDestinationId
import org.projectfloodlight.openflow.types.IPv4Address; //导入方法依赖的package包/类
public int queryDestinationId(MacAddress mac, IPv4Address ip, IpProtocol protocol, TransportPort port) {
if (!oPolicy.doRewrite(ObfuscationPolicy.Field.MAC_DST))
mac = MacAddress.of(1);
if (!oPolicy.doRewrite(ObfuscationPolicy.Field.IP_DST))
ip = IPv4Address.of(1);
if (!(oPolicy.doRewrite(ObfuscationPolicy.Field.TP_DST) && oPolicy.doRewrite(port.getPort())))
port = TransportPort.of(0);
return queryHostId(1, mac, ip, protocol, port);
}
示例3: asEntity
import org.projectfloodlight.openflow.types.IPv4Address; //导入方法依赖的package包/类
public Entity asEntity() {
Entity e = new Entity(macAddress == 0 ? null : MacAddress.of(macAddress),
vlan == -1 ? null : VlanVid.ofVlan(vlan),
ipv4Address == 0 ? null : IPv4Address.of(ipv4Address),
switchDPID == 0 ? null : DatapathId.of(switchDPID),
switchPort == 0 ? null : OFPort.of(switchPort),
lastSeenTimestamp);
e.setActiveSince(activeSince);
return e;
}
示例4: decode_set_dst_ip
import org.projectfloodlight.openflow.types.IPv4Address; //导入方法依赖的package包/类
/**
* Parse set_nw_dst actions.
* The key and delimiter for the action should be omitted, and only the
* data should be presented to this decoder.
*
* TODO should consider using IPv4AddressWithMask's built-in parser....
*
* @param actionToDecode; The action as a string to decode
* @param version; The OF version to create the action for
* @param log
* @return
*/
private static OFActionSetNwDst decode_set_dst_ip(String actionToDecode, OFVersion version, Logger log) {
Matcher n = Pattern.compile("(?:(\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+))").matcher(actionToDecode);
if (n.matches()) {
IPv4Address ipaddr = IPv4Address.of(get_ip_addr(n, actionToDecode, log));
OFActionSetNwDst.Builder ab = OFFactories.getFactory(version).actions().buildSetNwDst();
ab.setNwAddr(ipaddr);
log.debug("action {}", ab.build());
return ab.build();
}
else {
log.debug("Invalid action: '{}'", actionToDecode);
return null;
}
}
示例5: decode_set_src_ip
import org.projectfloodlight.openflow.types.IPv4Address; //导入方法依赖的package包/类
/**
* Parse set_nw_src actions.
* The key and delimiter for the action should be omitted, and only the
* data should be presented to this decoder.
*
* TODO should consider using IPv4AddressWithMask's built-in parser....
*
* @param actionToDecode; The action as a string to decode
* @param version; The OF version to create the action for
* @param log
* @return
*/
private static OFActionSetNwSrc decode_set_src_ip(String actionToDecode, OFVersion version, Logger log) {
Matcher n = Pattern.compile("(?:(\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+))").matcher(actionToDecode);
if (n.matches()) {
IPv4Address ipaddr = IPv4Address.of(get_ip_addr(n, actionToDecode, log));
OFActionSetNwSrc.Builder ab = OFFactories.getFactory(version).actions().buildSetNwSrc();
ab.setNwAddr(ipaddr);
log.debug("action {}", ab.build());
return ab.build();
}
else {
log.debug("Invalid action: '{}'", actionToDecode);
return null;
}
}
示例6: getSrcNwAddr
import org.projectfloodlight.openflow.types.IPv4Address; //导入方法依赖的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;
}
示例7: testSyncEntity
import org.projectfloodlight.openflow.types.IPv4Address; //导入方法依赖的package包/类
@Test
public void testSyncEntity() {
Date d1 = new Date();
Date d2 = new Date(1);
Entity e1 = new Entity(MacAddress.of(1L), VlanVid.ofVlan(2), IPv4Address.of(3), IPv6Address.NONE, DatapathId.of(4L), OFPort.of(5), d1);
e1.setActiveSince(d2);
SyncEntity se1 = new SyncEntity(e1);
assertEntityEquals(e1, se1);
assertEquals(1L, se1.macAddress);
assertEquals(2, se1.vlan);
assertEquals(3, se1.ipv4Address);
assertEquals(4L, se1.switchDPID);
assertEquals(5, se1.switchPort);
assertEquals(d1, se1.lastSeenTimestamp);
assertEquals(d2, se1.activeSince);
assertNotSame(d1, se1.lastSeenTimestamp);
assertNotSame(d2, se1.activeSince);
Entity e2 = new Entity(MacAddress.of(42L), VlanVid.ZERO, IPv4Address.NONE, IPv6Address.NONE, DatapathId.NONE, OFPort.ZERO, Entity.NO_DATE);
SyncEntity se2 = new SyncEntity(e2);
assertEntityEquals(e2, se2);
SyncEntity se3 = new SyncEntity();
SyncEntity se4 = new SyncEntity();
se3.lastSeenTimestamp = new Date(1000);
se4.lastSeenTimestamp = new Date(2000);
assertTrue("", se3.compareTo(se4) < 0);
assertTrue("", se4.compareTo(se3) > 0);
se4.lastSeenTimestamp = new Date(1000);
assertTrue("", se3.compareTo(se4) == 0);
assertTrue("", se4.compareTo(se3) == 0);
se4.lastSeenTimestamp = new Date(500);
assertTrue("", se3.compareTo(se4) > 0);
assertTrue("", se4.compareTo(se3) < 0);
}
示例8: testDeviceSyncRepresentationBasics
import org.projectfloodlight.openflow.types.IPv4Address; //导入方法依赖的package包/类
@Test
public void testDeviceSyncRepresentationBasics() {
DeviceSyncRepresentation dsr = new DeviceSyncRepresentation();
assertNull(dsr.getKey());
assertNull(dsr.getEntities());
dsr.setKey("MyKey");
assertEquals("MyKey", dsr.getKey());
assertEquals("MyKey", dsr.toString());
List<SyncEntity> entities = new ArrayList<SyncEntity>();
Entity e1a = new Entity(MacAddress.of(1L), VlanVid.ofVlan(2), IPv4Address.of(3), IPv6Address.NONE, DatapathId.of(4L), OFPort.of(5), new Date(1000));
Entity e1b = new Entity(MacAddress.of(1L), VlanVid.ofVlan(2), IPv4Address.NONE, IPv6Address.NONE, DatapathId.of(4L), OFPort.of(5), new Date(1));
entities.add(new SyncEntity(e1a));
entities.add(new SyncEntity(e1b));
// e1b comes before e1 (lastSeen) but we add it after it to test
// sorting
dsr.setEntities(entities);
assertEquals(2, dsr.getEntities().size());
// e1b has earlier time
assertEquals(e1b, dsr.getEntities().get(0).asEntity());
assertEquals(e1a, dsr.getEntities().get(1).asEntity());
dsr.setKey(null);
dsr.setEntities(null);
assertNull(dsr.getKey());
assertNull(dsr.getEntities());
}
示例9: setDestinationAddress
import org.projectfloodlight.openflow.types.IPv4Address; //导入方法依赖的package包/类
/**
* @param destinationAddress the destinationAddress to set
*/
public IPv4 setDestinationAddress(String destinationAddress) {
this.destinationAddress = IPv4Address.of(destinationAddress);
return this;
}
示例10: setSubnetMask
import org.projectfloodlight.openflow.types.IPv4Address; //导入方法依赖的package包/类
@Override
public void setSubnetMask(String newMask) {
if (newMask.trim().isEmpty())
return;
this.subnet_mask = IPv4Address.of(newMask.trim());
}
示例11: testConsolitateStore
import org.projectfloodlight.openflow.types.IPv4Address; //导入方法依赖的package包/类
@Test
public void testConsolitateStore() throws Exception {
int syncStoreInternalMs = 0;
ITopologyService mockTopology = makeMockTopologyAllPortsAp();
replay(mockTopology);
deviceManager.topology = mockTopology;
// We want an EntityClassifier that has switch/port as key fields
deviceManager.entityClassifier = new MockEntityClassifier();
deviceManager.setSyncStoreWriteInterval(syncStoreInternalMs);
// Add Device1 with two entities to store and let device manager
// learn
Entity e1a = new Entity(MacAddress.of(1L), null, null, DatapathId.of(4L), OFPort.of(5), new Date(1000));
Entity e1b = new Entity(MacAddress.of(1L), null, IPv4Address.of(3), DatapathId.of(4L), OFPort.of(5), new Date(2000));
Device d1 = deviceManager.learnDeviceByEntity(e1a);
deviceManager.learnDeviceByEntity(e1b);
String dev1Key = DeviceSyncRepresentation.computeKey(d1);
// Add a second device to the store but do NOT add to device manager
Entity e2 = new Entity(MacAddress.of(2L), null, null, DatapathId.of(5L), OFPort.of(5), new Date());
Device d2 = deviceManager.allocateDevice(42L, e2,
DefaultEntityClassifier.entityClass);
DeviceSyncRepresentation dsr = new DeviceSyncRepresentation(d2);
storeClient.put(dsr.getKey(), dsr);
String dev2Key = DeviceSyncRepresentation.computeKey(d2);
// Make sure we have two devices in the store
List<DeviceSyncRepresentation> entries = getEntriesFromStore();
assertEquals(2, entries.size());
deviceManager.scheduleConsolidateStoreNow();
Thread.sleep(25); // give the scheduler time to run the task
// We should still have two entries, however one of them will be a
// tombstone
entries = getEntriesFromStore();
assertEquals(2, entries.size());
// Device 1 should still be in store
Versioned<DeviceSyncRepresentation> versioned =
storeClient.get(dev1Key);
dsr = versioned.getValue();
assertNotNull(dsr);
assertEquals(2, dsr.getEntities().size());
assertEntityEquals(e1a, dsr.getEntities().get(0));
assertEntityEquals(e1b, dsr.getEntities().get(1));
// Device2 should be gone
versioned = storeClient.get(dev2Key);
assertNull(versioned.getValue());
// Run consolitate again. This time we check that tombstones in
// the store are handled correctly
deviceManager.scheduleConsolidateStoreNow();
Thread.sleep(25); // give the scheduler time to run the task
// Now write a device to the store that doesn't have any switch-port
// it should be removed
Entity e3 = new Entity(MacAddress.of(3L), null, null, null, null, null);
dsr.setKey("Device3");
dsr.setEntities(Collections.singletonList(new SyncEntity(e3)));
storeClient.put(dsr.getKey(), dsr);
// Run consolitate again. This time we check that tombstones in
// the store are handled correctly
deviceManager.scheduleConsolidateStoreNow();
Thread.sleep(25); // give the scheduler time to run the task
versioned = storeClient.get("Device3");
assertNull(versioned.getValue());
}
示例12: setDestinationAddress
import org.projectfloodlight.openflow.types.IPv4Address; //导入方法依赖的package包/类
/**
* @param destinationAddress the destinationAddress to set
*/
public IPv4 setDestinationAddress(int destinationAddress) {
this.destinationAddress = IPv4Address.of(destinationAddress);
return this;
}
示例13: deserialize
import org.projectfloodlight.openflow.types.IPv4Address; //导入方法依赖的package包/类
@Override
public IPacket deserialize(byte[] data, int offset, int length)
throws PacketParsingException {
ByteBuffer bb = ByteBuffer.wrap(data, offset, length);
short sscratch;
this.version = bb.get();
this.headerLength = (byte) (this.version & 0xf);
this.version = (byte) ((this.version >> 4) & 0xf);
if (this.version != 4) {
throw new PacketParsingException(
"Invalid version for IPv4 packet: " +
this.version);
}
this.diffServ = bb.get();
this.totalLength = bb.getShort();
this.identification = bb.getShort();
sscratch = bb.getShort();
this.flags = (byte) ((sscratch >> IPV4_FLAGS_SHIFT) & IPV4_FLAGS_MASK);
this.fragmentOffset = (short) (sscratch & IPV4_OFFSET_MASK);
this.ttl = bb.get();
this.protocol = IpProtocol.of(U8.f(bb.get()));
this.checksum = bb.getShort();
this.sourceAddress = IPv4Address.of(bb.getInt());
this.destinationAddress = IPv4Address.of(bb.getInt());
if (this.headerLength > 5) {
int optionsLength = (this.headerLength - 5) * 4;
this.options = new byte[optionsLength];
bb.get(this.options);
}
IPacket payload;
isFragment = ((this.flags & IPV4_FLAGS_DONTFRAG) == 0) &&
((this.flags & IPV4_FLAGS_MOREFRAG) != 0 ||
this.fragmentOffset != 0);
if (!isFragment && IPv4.protocolClassMap.containsKey(this.protocol)) {
Class<? extends IPacket> clazz = IPv4.protocolClassMap.get(this.protocol);
try {
payload = clazz.newInstance();
} catch (Exception e) {
throw new RuntimeException("Error parsing payload for IPv4 packet", e);
}
} else {
if (log.isTraceEnabled() && isFragment) {
log.trace("IPv4 fragment detected {}->{}, forward using IP header only",
this.sourceAddress.toString(),
this.destinationAddress.toString());
}
payload = new Data();
}
int payloadLength = this.totalLength - this.headerLength * 4;
int remLength = bb.limit()-bb.position();
if (remLength < payloadLength)
payloadLength = bb.limit()-bb.position();
this.payload = payload.deserialize(data, bb.position(), payloadLength);
this.payload.setParent(this);
if (this.totalLength > length)
this.isTruncated = true;
else
this.isTruncated = false;
return this;
}
示例14: getObfuscatedDstIpMask
import org.projectfloodlight.openflow.types.IPv4Address; //导入方法依赖的package包/类
public IPv4Address getObfuscatedDstIpMask() {
return IPv4Address.of((int) extractFromBitSet(obfuscatedHeaderMask,ObfuscationPolicy.Field.IP_DST.getLength(),ObfuscationPolicy.Field.IP_DST.getOffset()));
}
示例15: testBDAttachmentPointLearning
import org.projectfloodlight.openflow.types.IPv4Address; //导入方法依赖的package包/类
@Test
public void testBDAttachmentPointLearning() throws Exception {
ITopologyService mockTopology = createMock(ITopologyService.class);
expect(mockTopology.getL2DomainId(DatapathId.of(anyLong()))).andReturn(DatapathId.of(1L)).anyTimes();
expect(mockTopology.isAttachmentPointPort(DatapathId.of(anyLong()), OFPort.of(anyShort()))).
andReturn(true).anyTimes();
expect(mockTopology.isBroadcastDomainPort(DatapathId.of(1L), OFPort.of(1))).
andReturn(false).anyTimes();
expect(mockTopology.isBroadcastDomainPort(DatapathId.of(1L), OFPort.of(2))).
andReturn(true).anyTimes();
expect(mockTopology.isInSameBroadcastDomain(DatapathId.of(1L), OFPort.of(1),
DatapathId.of(1L), OFPort.of(2))).andReturn(true).anyTimes();
expect(mockTopology.isInSameBroadcastDomain(DatapathId.of(1L), OFPort.of(2),
DatapathId.of(1L), OFPort.of(1))).andReturn(true).anyTimes();
expect(mockTopology.isConsistent(DatapathId.of(anyLong()), OFPort.of(anyShort()), DatapathId.of(anyLong()), OFPort.of(anyShort()))).andReturn(false).anyTimes();
Date topologyUpdateTime = new Date();
expect(mockTopology.getLastUpdateTime()).andReturn(topologyUpdateTime).
anyTimes();
replay(mockTopology);
deviceManager.topology = mockTopology;
Calendar c = Calendar.getInstance();
Entity entity1 = new Entity(MacAddress.of(1L), null, IPv4Address.of(1), DatapathId.of(1L), OFPort.of(1), c.getTime());
c.add(Calendar.MILLISECOND,
(int)AttachmentPoint.OPENFLOW_TO_EXTERNAL_TIMEOUT/ 2);
Entity entity2 = new Entity(MacAddress.of(1L), null, null, DatapathId.of(1L), OFPort.of(2), c.getTime());
c.add(Calendar.MILLISECOND,
(int)AttachmentPoint.OPENFLOW_TO_EXTERNAL_TIMEOUT / 2 + 1);
Entity entity3 = new Entity(MacAddress.of(1L), null, null, DatapathId.of(1L), OFPort.of(2), c.getTime());
IDevice d;
SwitchPort[] aps;
d = deviceManager.learnDeviceByEntity(entity1);
assertEquals(1, deviceManager.getAllDevices().size());
aps = d.getAttachmentPoints();
assertArrayEquals(new SwitchPort[] { new SwitchPort(DatapathId.of(1L), OFPort.of(1)) }, aps);
// this timestamp is too soon; don't switch
d = deviceManager.learnDeviceByEntity(entity2);
assertEquals(1, deviceManager.getAllDevices().size());
aps = d.getAttachmentPoints();
assertArrayEquals(new SwitchPort[] { new SwitchPort(DatapathId.of(1L), OFPort.of(1)) }, aps);
// it should switch when we learn with a timestamp after the
// timeout
d = deviceManager.learnDeviceByEntity(entity3);
assertEquals(1, deviceManager.getAllDevices().size());
aps = d.getAttachmentPoints();
assertArrayEquals(new SwitchPort[] { new SwitchPort(DatapathId.of(1L), OFPort.of(2)) }, aps);
}