本文整理汇总了Java中org.projectfloodlight.openflow.types.VlanVid.ofVlan方法的典型用法代码示例。如果您正苦于以下问题:Java VlanVid.ofVlan方法的具体用法?Java VlanVid.ofVlan怎么用?Java VlanVid.ofVlan使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.projectfloodlight.openflow.types.VlanVid
的用法示例。
在下文中一共展示了VlanVid.ofVlan方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSourceEntityFromPacket
import org.projectfloodlight.openflow.types.VlanVid; //导入方法依赖的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 org.projectfloodlight.openflow.types.VlanVid; //导入方法依赖的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: decode_set_vlan_id
import org.projectfloodlight.openflow.types.VlanVid; //导入方法依赖的package包/类
/**
* Parse set_vlan_id actions.
* The key and delimiter for the action should be omitted, and only the
* data should be presented to this decoder. Data with a leading 0x is permitted.
*
* @param actionToDecode; The action as a string to decode
* @param version; The OF version to create the action for
* @param log
* @return
*/
private static OFActionSetVlanVid decode_set_vlan_id(String actionToDecode, OFVersion version, Logger log) {
Matcher n = Pattern.compile("((?:0x)?\\d+)").matcher(actionToDecode);
if (n.matches()) {
if (n.group(1) != null) {
try {
VlanVid vlanid = VlanVid.ofVlan(get_short(n.group(1)));
OFActionSetVlanVid.Builder ab = OFFactories.getFactory(version).actions().buildSetVlanVid();
ab.setVlanVid(vlanid);
log.debug("action {}", ab.build());
return ab.build();
}
catch (NumberFormatException e) {
log.debug("Invalid VLAN in: {} (error ignored)", actionToDecode);
return null;
}
}
}
else {
log.debug("Invalid action: '{}'", actionToDecode);
return null;
}
return null;
}
示例4: setUp
import org.projectfloodlight.openflow.types.VlanVid; //导入方法依赖的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());
}
示例5: computeVlandIds
import org.projectfloodlight.openflow.types.VlanVid; //导入方法依赖的package包/类
private VlanVid[] computeVlandIds() {
if (entities.length == 1) {
if (entities[0].getVlan() != null) {
return new VlanVid[]{ entities[0].getVlan() };
} else {
return new VlanVid[] { VlanVid.ofVlan(-1) };
}
}
TreeSet<VlanVid> vals = new TreeSet<VlanVid>();
for (Entity e : entities) {
if (e.getVlan() == null)
vals.add(VlanVid.ofVlan(-1));
else
vals.add(e.getVlan());
}
return vals.toArray(new VlanVid[vals.size()]);
}
示例6: getSourceEntityFromPacket
import org.projectfloodlight.openflow.types.VlanVid; //导入方法依赖的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());
}
示例7: removeFromPortMap
import org.projectfloodlight.openflow.types.VlanVid; //导入方法依赖的package包/类
/**
* Removes a host from the MAC/VLAN->SwitchPort mapping
* @param sw The switch to remove the mapping from
* @param mac The MAC address of the host to remove
* @param vlan The VLAN that the host is on
*/
protected void removeFromPortMap(IOFSwitch sw, MacAddress mac, VlanVid vlan) {
if (vlan == VlanVid.FULL_MASK) {
vlan = VlanVid.ofVlan(0);
}
Map<MacVlanPair, OFPort> swMap = macVlanToSwitchPortMap.get(sw);
if (swMap != null) {
swMap.remove(new MacVlanPair(mac, vlan));
}
}
示例8: getDestEntityFromPacket
import org.projectfloodlight.openflow.types.VlanVid; //导入方法依赖的package包/类
/**
* Get a (partial) entity for the destination from the packet.
* @param eth
* @return
*/
protected Entity getDestEntityFromPacket(Ethernet eth) {
MacAddress dlAddr = eth.getDestinationMACAddress();
VlanVid vlan = VlanVid.ofVlan(eth.getVlanID());
IPv4Address ipv4Dst = IPv4Address.NONE;
IPv6Address ipv6Dst = IPv6Address.NONE;
// Ignore broadcast/multicast destination
if (dlAddr.isBroadcast() || dlAddr.isMulticast())
return null;
// Ignore zero dest mac
if (dlAddr.equals(MacAddress.of(0)))
return null;
if (eth.getPayload() instanceof IPv4) {
IPv4 ipv4 = (IPv4) eth.getPayload();
ipv4Dst = ipv4.getDestinationAddress();
} else if (eth.getPayload() instanceof IPv6) {
IPv6 ipv6 = (IPv6) eth.getPayload();
ipv6Dst = ipv6.getDestinationAddress();
}
return new Entity(dlAddr,
vlan,
ipv4Dst,
ipv6Dst,
DatapathId.NONE,
OFPort.ZERO,
Entity.NO_DATE);
}
示例9: asEntity
import org.projectfloodlight.openflow.types.VlanVid; //导入方法依赖的package包/类
public Entity asEntity() {
Entity e = new Entity(MacAddress.of(macAddress),
VlanVid.ofVlan(vlan),
IPv4Address.of(ipv4Address),
IPv6Address.NONE,
DatapathId.of(switchDPID),
OFPort.of(switchPort),
lastSeenTimestamp);
e.setActiveSince(activeSince);
return e;
}
示例10: values
import org.projectfloodlight.openflow.types.VlanVid; //导入方法依赖的package包/类
@Override
public Collection<Device> values() {
// Get the values from the real map and copy them since
// the collection returned by values can reflect changed
Collection<Device> devs = new ArrayList<Device>(super.values());
for (Device d: devs) {
if (remove) {
// We remove the device from the underlying map
super.remove(d.getDeviceKey());
} else {
super.remove(d.getDeviceKey());
// We add a different Device instance with the same
// key to the map. We'll do some hackery so the device
// is different enough to compare differently in equals
// but otherwise looks the same.
// It's ugly but it works.
// clone entities
Device newDevice = d;
for (Entity e: d.getEntities()) {
Entity newEntity = new Entity (e.macAddress,
e.vlan,
e.ipv4Address,
e.switchDPID,
e.switchPort,
e.lastSeenTimestamp);
if (e.vlan == null)
newEntity.vlan = VlanVid.ofVlan(1);
else
newEntity.vlan = VlanVid.ofVlan(((e.vlan.getVlan() + 1 % 4095)+1));
newDevice = new Device(newDevice, newEntity, -1);
}
assertEquals(false, newDevice.equals(d));
super.put(newDevice.getDeviceKey(), newDevice);
}
}
return devs;
}
示例11: testSyncEntity
import org.projectfloodlight.openflow.types.VlanVid; //导入方法依赖的package包/类
@Test
public void testSyncEntity() {
Date d1 = new Date();
Date d2 = new Date(0);
Entity e1 = new Entity(MacAddress.of(1L), VlanVid.ofVlan(2), IPv4Address.of(3), 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), null, null, null, null, null);
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);
}
示例12: asEntity
import org.projectfloodlight.openflow.types.VlanVid; //导入方法依赖的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;
}
示例13: addToPortMap
import org.projectfloodlight.openflow.types.VlanVid; //导入方法依赖的package包/类
/**
* Adds a host to the MAC/VLAN->SwitchPort mapping
* @param sw The switch to add the mapping to
* @param mac The MAC address of the host to add
* @param vlan The VLAN that the host is on
* @param portVal The switchport that the host is on
*/
protected void addToPortMap(IOFSwitch sw, MacAddress mac, VlanVid vlan, OFPort portVal) {
Map<MacVlanPair, OFPort> swMap = macVlanToSwitchPortMap.get(sw);
if (vlan == VlanVid.FULL_MASK || vlan == null) {
vlan = VlanVid.ofVlan(0);
}
if (swMap == null) {
// May be accessed by REST API so we need to make it thread safe
swMap = Collections.synchronizedMap(new LRULinkedHashMap<MacVlanPair, OFPort>(MAX_MACS_PER_SWITCH));
macVlanToSwitchPortMap.put(sw, swMap);
}
swMap.put(new MacVlanPair(mac, vlan), portVal);
}
示例14: testDeviceSyncRepresentationBasics
import org.projectfloodlight.openflow.types.VlanVid; //导入方法依赖的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), DatapathId.of(4L), OFPort.of(5), new Date(1000));
Entity e1b = new Entity(MacAddress.of(1L), VlanVid.ofVlan(2), null, DatapathId.of(4L), OFPort.of(5), new Date(0));
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());
}
示例15: testSyncEntity
import org.projectfloodlight.openflow.types.VlanVid; //导入方法依赖的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);
}