当前位置: 首页>>代码示例>>Java>>正文


Java VlanVid.ZERO属性代码示例

本文整理汇总了Java中org.projectfloodlight.openflow.types.VlanVid.ZERO属性的典型用法代码示例。如果您正苦于以下问题:Java VlanVid.ZERO属性的具体用法?Java VlanVid.ZERO怎么用?Java VlanVid.ZERO使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.projectfloodlight.openflow.types.VlanVid的用法示例。


在下文中一共展示了VlanVid.ZERO属性的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testLastSeen

@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());
}
 
开发者ID:xuraylei,项目名称:fresco_floodlight,代码行数:19,代码来源:DeviceManagerImplTest.java

示例2: testGetSwitchPortVlanId

@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));
}
 
开发者ID:xuraylei,项目名称:fresco_floodlight,代码行数:24,代码来源:DeviceManagerImplTest.java

示例3: doTestEntityOrdering

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]));
	}
}
 
开发者ID:xuraylei,项目名称:fresco_floodlight,代码行数:31,代码来源:DeviceManagerImplTest.java

示例4: testSyncEntity

@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);
}
 
开发者ID:xuraylei,项目名称:fresco_floodlight,代码行数:35,代码来源:DeviceManagerImplTest.java

示例5: processPacketInMessage

/**
 * 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) {
	OFPort inPort = (pi.getVersion().compareTo(OFVersion.OF_12) < 0 ? pi.getInPort() : pi.getMatch().get(MatchField.IN_PORT));

	/* Read packet header attributes into Match */
	Match m = createMatchFromPacket(sw, inPort, cntx);
	MacAddress sourceMac = m.get(MatchField.ETH_SRC);
	MacAddress destMac = m.get(MatchField.ETH_DST);
	VlanVid vlan = m.get(MatchField.VLAN_VID) == null ? VlanVid.ZERO : m.get(MatchField.VLAN_VID).getVlanVid();

	if (sourceMac == null) {
		sourceMac = MacAddress.NONE;
	}
	if (destMac == null) {
		destMac = MacAddress.NONE;
	}
	if (vlan == null) {
		vlan = VlanVid.ZERO;
	}

	if ((destMac.getLong() & 0xfffffffffff0L) == 0x0180c2000000L) {
		if (log.isTraceEnabled()) {
			log.trace("ignoring packet addressed to 802.1D/Q reserved addr: switch {} vlan {} dest MAC {}",
					new Object[]{ sw, vlan, destMac.toString() });
		}
		return Command.STOP;
	}
	if ((sourceMac.getLong() & 0x010000000000L) == 0) {
		// If source MAC is a unicast address, learn the port for this MAC/VLAN
		this.addToPortMap(sw, sourceMac, vlan, inPort);
	}

	// Now output flow-mod and/or packet
	OFPort 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.FLOOD);
	} else if (outPort.equals(inPort)) {
		log.trace("ignoring packet that arrived on same port as learned destination:"
				+ " switch {} vlan {} dest MAC {} port {}",
				new Object[]{ sw, vlan, destMac.toString(), outPort.getPortNumber() });
	} 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
		// We write FlowMods with Buffer ID none then explicitly PacketOut the buffered packet
		this.pushPacket(sw, m, pi, outPort);
		this.writeFlowMod(sw, OFFlowModCommand.ADD, OFBufferId.NO_BUFFER, m, outPort);
		if (LEARNING_SWITCH_REVERSE_FLOW) {
			Match.Builder mb = m.createBuilder();
			mb.setExact(MatchField.ETH_SRC, m.get(MatchField.ETH_DST))                 
			.setExact(MatchField.ETH_DST, m.get(MatchField.ETH_SRC))     
			.setExact(MatchField.IN_PORT, outPort);
			if (m.get(MatchField.VLAN_VID) != null) {
				mb.setExact(MatchField.VLAN_VID, m.get(MatchField.VLAN_VID));
			}

			this.writeFlowMod(sw, OFFlowModCommand.ADD, OFBufferId.NO_BUFFER, mb.build(), inPort);
		}
	}
	return Command.CONTINUE;
}
 
开发者ID:xuraylei,项目名称:fresco_floodlight,代码行数:80,代码来源:LearningSwitch.java

示例6: testBDAttachmentPointLearning

@Test
public void testBDAttachmentPointLearning() throws Exception {
	ITopologyService mockTopology = createMock(ITopologyService.class);
	expect(mockTopology.getOpenflowDomainId(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), VlanVid.ZERO, IPv4Address.of(1), IPv6Address.NONE, 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), VlanVid.ZERO, IPv4Address.NONE, IPv6Address.NONE, 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), VlanVid.ZERO, IPv4Address.NONE, IPv6Address.NONE, 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);
}
 
开发者ID:xuraylei,项目名称:fresco_floodlight,代码行数:54,代码来源:DeviceManagerImplTest.java

示例7: testLOCALAttachmentPointLearning

/**
 * This test verifies that the learning behavior on OFPP_LOCAL ports.
 * Once a host is learned on OFPP_LOCAL, it is allowed to move only from
 * one OFPP_LOCAL to another OFPP_LOCAL port.
 * @throws Exception
 */
@Test
public void testLOCALAttachmentPointLearning() throws Exception {
	ITopologyService mockTopology = createMock(ITopologyService.class);
	expect(mockTopology.getOpenflowDomainId(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.LOCAL)).
	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.LOCAL)).andReturn(true).anyTimes();
	expect(mockTopology.isInSameBroadcastDomain(DatapathId.of(1L), OFPort.LOCAL,
			DatapathId.of(1L), OFPort.of(2))).andReturn(true).anyTimes();
	expect(mockTopology.isInSameBroadcastDomain(DatapathId.of(1L), OFPort.of(2),
			DatapathId.of(1L), OFPort.LOCAL)).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), VlanVid.ZERO, IPv4Address.of(1), IPv6Address.NONE, 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), VlanVid.ZERO, IPv4Address.NONE, IPv6Address.NONE, DatapathId.of(1L), OFPort.LOCAL, c.getTime());
	c.add(Calendar.MILLISECOND,
			(int)AttachmentPoint.OPENFLOW_TO_EXTERNAL_TIMEOUT + 1);
	Entity entity3 = new Entity(MacAddress.of(1L), VlanVid.ZERO, IPv4Address.NONE, IPv6Address.NONE, 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);

	// Ensure that the attachment point changes to OFPP_LOCAL
	d = deviceManager.learnDeviceByEntity(entity2);
	assertEquals(1, deviceManager.getAllDevices().size());
	aps = d.getAttachmentPoints();
	assertArrayEquals(new SwitchPort[] { new SwitchPort(DatapathId.of(1L), OFPort.LOCAL) }, aps);

	// Even though the new attachment point is consistent with old
	// and the time has elapsed, OFPP_LOCAL attachment point should
	// be maintained.
	d = deviceManager.learnDeviceByEntity(entity3);
	assertEquals(1, deviceManager.getAllDevices().size());
	aps = d.getAttachmentPoints();
	assertArrayEquals(new SwitchPort[] { new SwitchPort(DatapathId.of(1L), OFPort.LOCAL) }, aps);
}
 
开发者ID:xuraylei,项目名称:fresco_floodlight,代码行数:66,代码来源:DeviceManagerImplTest.java

示例8: doTestDeviceExpiration

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), VlanVid.ZERO, IPv4Address.of(1), IPv6Address.NONE, DatapathId.of(1L), OFPort.of(1), c.getTime());
	Entity entity2 = new Entity(MacAddress.of(1L), VlanVid.ZERO, IPv4Address.of(2), IPv6Address.NONE, 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.getOpenflowDomainId(DatapathId.of(1L))).andReturn(DatapathId.of(1L)).anyTimes();
	expect(mockTopology.getOpenflowDomainId(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(),
					MacAddress.NONE, VlanVid.ZERO, IPv4Address.of(1), IPv6Address.NONE, DatapathId.NONE, OFPort.ZERO);
	assertFalse(diter.hasNext());

	r = deviceManager.findDevice(MacAddress.of(1L), VlanVid.ZERO, IPv4Address.NONE, IPv6Address.NONE, DatapathId.NONE, OFPort.ZERO);
	assertNull(r);

	verify(mockListener);
}
 
开发者ID:xuraylei,项目名称:fresco_floodlight,代码行数:58,代码来源:DeviceManagerImplTest.java

示例9: testConsolitateStore

@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), VlanVid.ZERO, IPv4Address.NONE, IPv6Address.NONE, DatapathId.of(4L), OFPort.of(5), new Date(1000));
	Entity e1b = new Entity(MacAddress.of(1L), VlanVid.ZERO, IPv4Address.of(3), IPv6Address.NONE, 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), VlanVid.ZERO, IPv4Address.NONE, IPv6Address.NONE, 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), VlanVid.ZERO, IPv4Address.NONE, IPv6Address.NONE, DatapathId.NONE, OFPort.ZERO, Entity.NO_DATE);
	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());
}
 
开发者ID:xuraylei,项目名称:fresco_floodlight,代码行数:71,代码来源:DeviceManagerImplTest.java

示例10: processPacketInMessage

/**
 * 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) {
	OFPort inPort = (pi.getVersion().compareTo(OFVersion.OF_12) < 0 ? pi.getInPort() : pi.getMatch().get(MatchField.IN_PORT));

	/* Read packet header attributes into Match */
	Match m = createMatchFromPacket(sw, inPort, cntx);
	MacAddress sourceMac = m.get(MatchField.ETH_SRC);
	MacAddress destMac = m.get(MatchField.ETH_DST);
	VlanVid vlan = m.get(MatchField.VLAN_VID) == null ? VlanVid.ZERO : m.get(MatchField.VLAN_VID).getVlanVid();

	if (sourceMac == null) {
		sourceMac = MacAddress.NONE;
	}
	if (destMac == null) {
		destMac = MacAddress.NONE;
	}
	if (vlan == null) {
		vlan = VlanVid.ZERO;
	}

	if ((destMac.getLong() & 0xfffffffffff0L) == 0x0180c2000000L) {
		if (log.isTraceEnabled()) {
			log.trace("ignoring packet addressed to 802.1D/Q reserved addr: switch {} vlan {} dest MAC {}",
					new Object[]{ sw, vlan, destMac.toString() });
		}
		return Command.STOP;
	}
	if ((sourceMac.getLong() & 0x010000000000L) == 0) {
		// If source MAC is a unicast address, learn the port for this MAC/VLAN
		this.addToPortMap(sw, sourceMac, vlan, inPort);
	}

	// Now output flow-mod and/or packet
	OFPort 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.FLOOD);
	} else if (outPort.equals(inPort)) {
		log.trace("ignoring packet that arrived on same port as learned destination:"
				+ " switch {} vlan {} dest MAC {} port {}",
				new Object[]{ sw, vlan, destMac.toString(), outPort.getPortNumber() });
	} 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
		// We write FlowMods with Buffer ID none then explicitly PacketOut the buffered packet
		this.pushPacket(sw, m, pi, outPort);
		this.writeFlowMod(sw, OFFlowModCommand.ADD, OFBufferId.NO_BUFFER, m, outPort);
		if (LEARNING_SWITCH_REVERSE_FLOW) {
			Match.Builder mb = m.createBuilder();
			mb.setExact(MatchField.ETH_SRC, m.get(MatchField.ETH_DST))                         
			.setExact(MatchField.ETH_DST, m.get(MatchField.ETH_SRC))     
			.setExact(MatchField.IN_PORT, outPort);
			if (m.get(MatchField.VLAN_VID) != null) {
				mb.setExact(MatchField.VLAN_VID, m.get(MatchField.VLAN_VID));
			}

			this.writeFlowMod(sw, OFFlowModCommand.ADD, OFBufferId.NO_BUFFER, mb.build(), inPort);
		}
	}
	return Command.CONTINUE;
}
 
开发者ID:nsg-ethz,项目名称:iTAP-controller,代码行数:80,代码来源:LearningSwitch.java


注:本文中的org.projectfloodlight.openflow.types.VlanVid.ZERO属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。