本文整理汇总了Java中org.projectfloodlight.openflow.types.MacAddress.of方法的典型用法代码示例。如果您正苦于以下问题:Java MacAddress.of方法的具体用法?Java MacAddress.of怎么用?Java MacAddress.of使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.projectfloodlight.openflow.types.MacAddress
的用法示例。
在下文中一共展示了MacAddress.of方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testLastSeen
import org.projectfloodlight.openflow.types.MacAddress; //导入方法依赖的package包/类
@Test
public void testLastSeen() throws Exception {
Calendar c = Calendar.getInstance();
Date d1 = c.getTime();
Entity entity1 = new Entity(MacAddress.of(1L), VlanVid.ZERO /* untagged*/, IPv4Address.NONE, IPv6Address.NONE, DatapathId.NONE, OFPort.ZERO, d1);
c.add(Calendar.SECOND, 1);
Entity entity2 = new Entity(MacAddress.of(1L), VlanVid.ZERO /* untagged*/, IPv4Address.of(1), IPv6Address.NONE, DatapathId.NONE, OFPort.ZERO, c.getTime());
IDevice d = deviceManager.learnDeviceByEntity(entity2);
assertEquals(c.getTime(), d.getLastSeen());
d = deviceManager.learnDeviceByEntity(entity1);
assertEquals(c.getTime(), d.getLastSeen());
deviceManager.startUp(null);
d = deviceManager.learnDeviceByEntity(entity1);
assertEquals(d1, d.getLastSeen());
d = deviceManager.learnDeviceByEntity(entity2);
assertEquals(c.getTime(), d.getLastSeen());
}
示例2: decode_set_src_mac
import org.projectfloodlight.openflow.types.MacAddress; //导入方法依赖的package包/类
/**
* Parse set_dl_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 MacAddress'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 OFActionSetDlSrc decode_set_src_mac(String actionToDecode, OFVersion version, Logger log) {
Matcher n = Pattern.compile("(?:(\\p{XDigit}+)\\:(\\p{XDigit}+)\\:(\\p{XDigit}+)\\:(\\p{XDigit}+)\\:(\\p{XDigit}+)\\:(\\p{XDigit}+))").matcher(actionToDecode);
if (n.matches()) {
MacAddress macaddr = MacAddress.of(get_mac_addr(n, actionToDecode, log));
if (macaddr != null) {
OFActionSetDlSrc.Builder ab = OFFactories.getFactory(version).actions().buildSetDlSrc();
ab.setDlAddr(macaddr);
log.debug("action {}", ab.build());
return ab.build();
}
}
else {
log.debug("Invalid action: '{}'", actionToDecode);
return null;
}
return null;
}
示例3: testGetSwitchPortVlanId
import org.projectfloodlight.openflow.types.MacAddress; //导入方法依赖的package包/类
@Test
public void testGetSwitchPortVlanId() {
Entity entity1 = new Entity(MacAddress.of(1L), VlanVid.ofVlan(1), IPv4Address.NONE, IPv6Address.NONE, DatapathId.of(10L), OFPort.of(1), new Date());
Entity entity2 = new Entity(MacAddress.of(1L), VlanVid.ZERO, IPv4Address.NONE, IPv6Address.NONE, DatapathId.of(10L), OFPort.of(1), new Date());
Entity entity3 = new Entity(MacAddress.of(1L), VlanVid.ofVlan(3), IPv4Address.NONE, IPv6Address.NONE, DatapathId.of(1L), OFPort.of(1), new Date());
Entity entity4 = new Entity(MacAddress.of(1L), VlanVid.ofVlan(42), IPv4Address.NONE, IPv6Address.NONE, DatapathId.of(1L), OFPort.of(1), new Date());
Entity[] entities = new Entity[] { entity1, entity2,
entity3, entity4
};
Device d = new Device(null,1L, null, null, null,
Arrays.asList(entities), null);
SwitchPort swp1x1 = new SwitchPort(DatapathId.of(1L), OFPort.of(1));
SwitchPort swp1x2 = new SwitchPort(DatapathId.of(1L), OFPort.of(2));
SwitchPort swp2x1 = new SwitchPort(DatapathId.of(2L), OFPort.of(1));
SwitchPort swp10x1 = new SwitchPort(DatapathId.of(10L), OFPort.of(1));
assertArrayEquals(new VlanVid[] { VlanVid.ZERO, VlanVid.ofVlan(1)},
d.getSwitchPortVlanIds(swp10x1));
assertArrayEquals(new VlanVid[] { VlanVid.ofVlan(3), VlanVid.ofVlan(42)},
d.getSwitchPortVlanIds(swp1x1));
assertArrayEquals(new VlanVid[0],
d.getSwitchPortVlanIds(swp1x2));
assertArrayEquals(new VlanVid[0],
d.getSwitchPortVlanIds(swp2x1));
}
示例4: testLayer2Rule
import org.projectfloodlight.openflow.types.MacAddress; //导入方法依赖的package包/类
@Test
public void testLayer2Rule() throws Exception {
// enable firewall first
firewall.enableFirewall(true);
// add L2 rule
FirewallRule rule = new FirewallRule();
rule.dl_src = MacAddress.of("00:44:33:22:11:00");
rule.any_dl_src = false;
rule.dl_dst = MacAddress.of("00:11:22:33:44:55");
rule.any_dl_dst = false;
rule.priority = 1;
firewall.addRule(rule);
// add TCP deny all rule
rule = new FirewallRule();
rule.nw_proto = IpProtocol.TCP;
rule.any_nw_proto = false;
rule.priority = 2;
rule.action = FirewallRule.FirewallAction.DROP;
firewall.addRule(rule);
// simulate a packet-in event
this.setPacketIn(tcpPacket);
firewall.receive(sw, this.packetIn, cntx);
verify(sw);
IRoutingDecision decision = IRoutingDecision.rtStore.get(cntx, IRoutingDecision.CONTEXT_DECISION);
assertEquals(decision.getRoutingAction(), IRoutingDecision.RoutingAction.FORWARD_OR_FLOOD);
}
示例5: parseMAC
import org.projectfloodlight.openflow.types.MacAddress; //导入方法依赖的package包/类
@Override
public long parseMAC(String mac){
MacAddress macAddr = MacAddress.of(mac);
if (macAddr != null){
return macAddr.getLong();
}
else{
return -1;
}
}
示例6: asEntity
import org.projectfloodlight.openflow.types.MacAddress; //导入方法依赖的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;
}
示例7: queryDestinationId
import org.projectfloodlight.openflow.types.MacAddress; //导入方法依赖的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);
}
示例8: doTestEntityOrdering
import org.projectfloodlight.openflow.types.MacAddress; //导入方法依赖的package包/类
private void doTestEntityOrdering(boolean computeInsertionPoint) throws Exception {
Entity e = new Entity(MacAddress.of(10L), VlanVid.ZERO, IPv4Address.NONE, IPv6Address.NONE, DatapathId.NONE, OFPort.ZERO, Entity.NO_DATE);
IEntityClass ec = createNiceMock(IEntityClass.class);
Device d = new Device(deviceManager, 1L, e, ec);
int expectedLength = 1;
Long[] macs = new Long[] { 5L, // new first element
15L, // new last element
7L, // insert in middle
12L, // insert in middle
6L, // insert at idx 1
14L, // insert at idx length-2
1L,
20L
};
for (Long mac: macs) {
e = new Entity(MacAddress.of(mac), VlanVid.ZERO, IPv4Address.NONE, IPv6Address.NONE, DatapathId.NONE, OFPort.ZERO, Entity.NO_DATE);
int insertionPoint;
if (computeInsertionPoint) {
insertionPoint = -(Arrays.binarySearch(d.entities, e)+1);
} else {
insertionPoint = -1;
}
d = deviceManager.allocateDevice(d, e, insertionPoint);
expectedLength++;
assertEquals(expectedLength, d.entities.length);
for (int i = 0; i < d.entities.length-1; i++)
assertEquals(-1, d.entities[i].compareTo(d.entities[i+1]));
}
}
示例9: testReadRulesFromStorage
import org.projectfloodlight.openflow.types.MacAddress; //导入方法依赖的package包/类
@Test
public void testReadRulesFromStorage() throws Exception {
// add 2 rules first
FirewallRule rule = new FirewallRule();
rule.in_port = OFPort.of(2);
rule.dl_src = MacAddress.of("00:00:00:00:00:01");
rule.dl_dst = MacAddress.of("00:00:00:00:00:02");
rule.priority = 1;
rule.action = FirewallRule.FirewallAction.DROP;
firewall.addRule(rule);
rule = new FirewallRule();
rule.in_port = OFPort.of(3);
rule.dl_src = MacAddress.of("00:00:00:00:00:02");
rule.dl_dst = MacAddress.of("00:00:00:00:00:01");
rule.nw_proto = IpProtocol.TCP;
rule.any_nw_proto = false;
rule.tp_dst = TransportPort.of(80);
rule.priority = 2;
rule.action = FirewallRule.FirewallAction.ALLOW;
firewall.addRule(rule);
List<FirewallRule> rules = firewall.readRulesFromStorage();
// verify rule 1
FirewallRule r = rules.get(0);
assertEquals(r.in_port, OFPort.of(2));
assertEquals(r.priority, 1);
assertEquals(r.dl_src, MacAddress.of("00:00:00:00:00:01"));
assertEquals(r.dl_dst, MacAddress.of("00:00:00:00:00:02"));
assertEquals(r.action, FirewallRule.FirewallAction.DROP);
// verify rule 2
r = rules.get(1);
assertEquals(r.in_port, OFPort.of(3));
assertEquals(r.priority, 2);
assertEquals(r.dl_src, MacAddress.of("00:00:00:00:00:02"));
assertEquals(r.dl_dst, MacAddress.of("00:00:00:00:00:01"));
assertEquals(r.nw_proto, IpProtocol.TCP);
assertEquals(r.tp_dst, TransportPort.of(80));
assertEquals(r.any_nw_proto, false);
assertEquals(r.action, FirewallRule.FirewallAction.ALLOW);
}
示例10: testBDAttachmentPointLearning
import org.projectfloodlight.openflow.types.MacAddress; //导入方法依赖的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);
}
示例11: getObfuscatedSrcMacMask
import org.projectfloodlight.openflow.types.MacAddress; //导入方法依赖的package包/类
public MacAddress getObfuscatedSrcMacMask() {
return MacAddress.of(extractFromBitSet(obfuscatedHeaderMask,ObfuscationPolicy.Field.MAC_SRC.getLength(),ObfuscationPolicy.Field.MAC_SRC.getOffset()));
}
示例12: doTestDeviceQuery
import org.projectfloodlight.openflow.types.MacAddress; //导入方法依赖的package包/类
protected void doTestDeviceQuery() throws Exception {
Entity entity1 = new Entity(MacAddress.of(1L), VlanVid.ofVlan(1), IPv4Address.of(1), DatapathId.of(1L), OFPort.of(1), new Date());
Entity entity2 = new Entity(MacAddress.of(2L), VlanVid.ofVlan(2), IPv4Address.of(2), DatapathId.of(1L), OFPort.of(2), new Date());
Entity entity3 = new Entity(MacAddress.of(3L), VlanVid.ofVlan(3), IPv4Address.of(3), DatapathId.of(5L), OFPort.of(1), new Date());
Entity entity4 = new Entity(MacAddress.of(4L), VlanVid.ofVlan(4), IPv4Address.of(3), DatapathId.of(5L), OFPort.of(2), new Date());
Entity entity5 = new Entity(MacAddress.of(1L), VlanVid.ofVlan(4), IPv4Address.of(3), DatapathId.of(5L), OFPort.of(2), new Date());
Device d1 = deviceManager.learnDeviceByEntity(entity1);
deviceManager.learnDeviceByEntity(entity2);
Device d3 = deviceManager.learnDeviceByEntity(entity3);
Device d4 = deviceManager.learnDeviceByEntity(entity4);
IDevice d;
Iterator<? extends IDevice> iter =
deviceManager.queryDevices(null, VlanVid.ofVlan(1), IPv4Address.of(1), null, null);
int count = 0;
while (iter.hasNext()) {
count += 1;
d = iter.next();
assertEquals(d1.getDeviceKey(), d.getDeviceKey());
}
assertEquals(1, count);
iter = deviceManager.queryDevices(null, VlanVid.ofVlan(3), IPv4Address.of(3), null, null);
count = 0;
while (iter.hasNext()) {
count += 1;
d = iter.next();
assertEquals(d3.getDeviceKey(), d.getDeviceKey());
}
assertEquals(1, count);
iter = deviceManager.queryDevices(null, VlanVid.ofVlan(1), IPv4Address.of(3), null, null);
count = 0;
while (iter.hasNext()) {
count += 1;
iter.next();
}
assertEquals(0, count);
Device d5 = deviceManager.learnDeviceByEntity(entity5);
iter = deviceManager.queryDevices(null, VlanVid.ofVlan(4), IPv4Address.of(3), null, null);
count = 0;
Set<Long> deviceKeysFromIterator = new HashSet<Long>();
while (iter.hasNext()) {
count += 1;
d = iter.next();
deviceKeysFromIterator.add(d.getDeviceKey());
}
Set<Long> expectedDeviceKeys = new HashSet<Long>();
expectedDeviceKeys.add(d4.getDeviceKey());
expectedDeviceKeys.add(d5.getDeviceKey());
assertEquals(expectedDeviceKeys, deviceKeysFromIterator);
assertEquals(2, count);
iter = deviceManager.queryDevices(MacAddress.of(1L), null, null, null, null);
count = 0;
deviceKeysFromIterator = new HashSet<Long>();
while (iter.hasNext()) {
count += 1;
d = iter.next();
deviceKeysFromIterator.add(d.getDeviceKey());
}
expectedDeviceKeys = new HashSet<Long>();
expectedDeviceKeys.add(d1.getDeviceKey());
expectedDeviceKeys.add(d5.getDeviceKey());
assertEquals(expectedDeviceKeys, deviceKeysFromIterator);
assertEquals(2, count);
}
示例13: setSrcMacAddress
import org.projectfloodlight.openflow.types.MacAddress; //导入方法依赖的package包/类
public void setSrcMacAddress(MacAddress srcMacAddress) {
this.srcMacAddress = MacAddress.of(srcMacAddress.getLong());
}
示例14: doTestDeviceExpiration
import org.projectfloodlight.openflow.types.MacAddress; //导入方法依赖的package包/类
public void doTestDeviceExpiration() throws Exception {
IDeviceListener mockListener =
createMock(IDeviceListener.class);
expect(mockListener.getName()).andReturn("mockListener").anyTimes();
expect(mockListener.isCallbackOrderingPostreq((String)anyObject(), (String)anyObject()))
.andReturn(false).atLeastOnce();
expect(mockListener.isCallbackOrderingPrereq((String)anyObject(), (String)anyObject()))
.andReturn(false).atLeastOnce();
Calendar c = Calendar.getInstance();
c.add(Calendar.MILLISECOND, -DeviceManagerImpl.ENTITY_TIMEOUT-1);
Entity entity1 = new Entity(MacAddress.of(1L), null, IPv4Address.of(1), DatapathId.of(1L), OFPort.of(1), c.getTime());
Entity entity2 = new Entity(MacAddress.of(1L), null, IPv4Address.of(2), DatapathId.of(5L), OFPort.of(1), c.getTime());
ITopologyService mockTopology = createMock(ITopologyService.class);
deviceManager.topology = mockTopology;
expect(mockTopology.isAttachmentPointPort(DatapathId.of(EasyMock.anyLong()),
OFPort.of(EasyMock.anyShort()))).
andReturn(true).
anyTimes();
expect(mockTopology.getL2DomainId(DatapathId.of(1L))).andReturn(DatapathId.of(1L)).anyTimes();
expect(mockTopology.getL2DomainId(DatapathId.of(5L))).andReturn(DatapathId.of(1L)).anyTimes();
expect(mockTopology.isConsistent(DatapathId.of(EasyMock.anyLong()),
OFPort.of(EasyMock.anyShort()),
DatapathId.of(EasyMock.anyLong()),
OFPort.of(EasyMock.anyShort()))).andReturn(false).
anyTimes();
expect(mockTopology.isBroadcastDomainPort(DatapathId.of(EasyMock.anyLong()),
OFPort.of(EasyMock.anyShort()))).
andReturn(false).anyTimes();
replay(mockTopology);
IDevice d = deviceManager.learnDeviceByEntity(entity2);
d = deviceManager.learnDeviceByEntity(entity1);
assertArrayEquals(new IPv4Address[] { IPv4Address.of(1), IPv4Address.of(2) }, d.getIPv4Addresses());
replay(mockListener);
deviceManager.addListener(mockListener);
verify(mockListener);
reset(mockListener);
mockListener.deviceRemoved(isA(IDevice.class));
replay(mockListener);
deviceManager.entityCleanupTask.reschedule(0, null);
IDevice r = deviceManager.getDevice(d.getDeviceKey());
assertNull(r);
Iterator<? extends IDevice> diter =
deviceManager.queryClassDevices(d.getEntityClass(),
null, null, IPv4Address.of(1), null, null);
assertFalse(diter.hasNext());
r = deviceManager.findDevice(MacAddress.of(1L), null, null, null, null);
assertNull(r);
verify(mockListener);
}
示例15: setDestinationMACAddress
import org.projectfloodlight.openflow.types.MacAddress; //导入方法依赖的package包/类
/**
* @param destinationMACAddress the destination MAC to set
*/
public Ethernet setDestinationMACAddress(byte[] destinationMACAddress) {
this.destinationMACAddress = MacAddress.of(destinationMACAddress);
return this;
}