use of org.onosproject.net.DefaultDevice in project onos by opennetworkinglab.
the class DevicePortStatsCommandTest method setUp.
@Before
public void setUp() {
devicePortStatsCommand = new DevicePortStatsCommand();
id1 = NetTestTools.did("d1");
DefaultDevice d1 = new DefaultDevice(NetTestTools.PID, id1, Device.Type.SWITCH, "test", "1.0", "1.0", "abacab", new ChassisId("c"), DefaultAnnotations.EMPTY);
devices.add(d1);
portStatistics = DefaultPortStatistics.builder().setDurationSec(1).setBytesReceived(10).setBytesSent(20).setDurationNano(30).setPacketsReceived(40).setPacketsSent(50).setPacketsRxDropped(60).setPacketsRxErrors(70).setPacketsTxDropped(80).setPacketsTxErrors(90).setPort(PortNumber.portNumber(81)).setDeviceId(id1).build();
portStatisticsList.add(portStatistics);
deviceService = createMock(DeviceService.class);
expect(deviceService.getPortStatistics(id1)).andReturn(portStatisticsList);
expect(deviceService.getPortDeltaStatistics(id1)).andReturn(portStatisticsList);
replay(deviceService);
}
use of org.onosproject.net.DefaultDevice in project onos by opennetworkinglab.
the class SimpleDeviceStore method composeDevice.
/**
* Returns a Device, merging description given from multiple Providers.
*
* @param deviceId device identifier
* @param providerDescs Collection of Descriptions from multiple providers
* @return Device instance
*/
private Device composeDevice(DeviceId deviceId, Map<ProviderId, DeviceDescriptions> providerDescs) {
checkArgument(!providerDescs.isEmpty(), "No Device descriptions supplied");
ProviderId primary = pickPrimaryPid(providerDescs);
DeviceDescriptions desc = providerDescs.get(primary);
final DeviceDescription base = desc.getDeviceDesc();
Type type = base.type();
String manufacturer = base.manufacturer();
String hwVersion = base.hwVersion();
String swVersion = base.swVersion();
String serialNumber = base.serialNumber();
ChassisId chassisId = base.chassisId();
DefaultAnnotations annotations = DefaultAnnotations.builder().build();
annotations = merge(annotations, base.annotations());
for (Entry<ProviderId, DeviceDescriptions> e : providerDescs.entrySet()) {
if (e.getKey().equals(primary)) {
continue;
}
// TODO: should keep track of Description timestamp
// and only merge conflicting keys when timestamp is newer
// Currently assuming there will never be a key conflict between
// providers
// annotation merging. not so efficient, should revisit later
annotations = merge(annotations, e.getValue().getDeviceDesc().annotations());
}
return new DefaultDevice(primary, deviceId, type, manufacturer, hwVersion, swVersion, serialNumber, chassisId, annotations);
}
use of org.onosproject.net.DefaultDevice in project onos by opennetworkinglab.
the class HostLocationProviderTest method removeHostByDeviceOffline.
@Test
public void removeHostByDeviceOffline() {
provider.modified(CTX_FOR_REMOVE);
testProcessor.process(new TestArpPacketContext(DEV1));
testProcessor.process(new TestArpPacketContext(DEV4));
Device device = new DefaultDevice(ProviderId.NONE, deviceId(DEV1), SWITCH, "m", "h", "s", "n", new ChassisId(0L));
deviceService.listener.event(new DeviceEvent(DEVICE_AVAILABILITY_CHANGED, device));
assertEquals("incorrect remove count", 2, providerService.locationRemoveCount);
device = new DefaultDevice(ProviderId.NONE, deviceId(DEV4), SWITCH, "m", "h", "s", "n", new ChassisId(0L));
deviceService.listener.event(new DeviceEvent(DEVICE_AVAILABILITY_CHANGED, device));
assertEquals("incorrect remove count", 3, providerService.locationRemoveCount);
}
use of org.onosproject.net.DefaultDevice in project onos by opennetworkinglab.
the class HostLocationProviderTest method removeHostByDeviceRemove.
@Test
public void removeHostByDeviceRemove() {
provider.modified(CTX_FOR_REMOVE);
testProcessor.process(new TestArpPacketContext(DEV1));
testProcessor.process(new TestNaPacketContext(DEV4));
Device device = new DefaultDevice(ProviderId.NONE, deviceId(DEV1), SWITCH, "m", "h", "s", "n", new ChassisId(0L));
deviceService.listener.event(new DeviceEvent(DEVICE_REMOVED, device));
assertEquals("incorrect remove count", 2, providerService.locationRemoveCount);
device = new DefaultDevice(ProviderId.NONE, deviceId(DEV4), SWITCH, "m", "h", "s", "n", new ChassisId(0L));
deviceService.listener.event(new DeviceEvent(DEVICE_REMOVED, device));
assertEquals("incorrect remove count", 3, providerService.locationRemoveCount);
}
use of org.onosproject.net.DefaultDevice in project onos by opennetworkinglab.
the class CfmMepManagerTest method setup.
@Before
public void setup() throws CfmConfigException {
mepManager = new CfmMepManager();
mepStore = new DistributedMepStore();
storageService = new MockStorageService();
ma1 = DefaultMaintenanceAssociation.builder(MANAME1, MDNAME1.getNameLength()).build();
ma2 = DefaultMaintenanceAssociation.builder(MANAME2, MDNAME2.getNameLength()).build();
TestUtils.setField(mepStore, "storageService", storageService);
((DistributedMepStore) mepStore).activate();
TestUtils.setField(mepManager, "coreService", new TestCoreService());
TestUtils.setField(mepManager, "deviceService", deviceService);
TestUtils.setField(mepManager, "cfmMdService", mdService);
TestUtils.setField(mepManager, "mepStore", mepStore);
injectEventDispatcher(mepManager, new TestEventDispatcher());
mepService = mepManager;
mepManager.activate();
mep1 = DefaultMep.builder(MEPID1, DEVICE_ID1, PortNumber.P0, Mep.MepDirection.UP_MEP, MDNAME1, MANAME1).build();
mepStore.createUpdateMep(new MepKeyId(MDNAME1, MANAME1, MEPID1), mep1);
mep11 = DefaultMep.builder(MEPID11, DEVICE_ID1, PortNumber.P0, Mep.MepDirection.UP_MEP, MDNAME1, MANAME1).build();
mepStore.createUpdateMep(new MepKeyId(MDNAME1, MANAME1, MEPID11), mep11);
mep12 = DefaultMep.builder(MEPID12, DEVICE_ID1, PortNumber.P0, Mep.MepDirection.UP_MEP, MDNAME2, MANAME2).build();
mepStore.createUpdateMep(new MepKeyId(MDNAME2, MANAME2, MEPID12), mep12);
mep2 = DefaultMep.builder(MEPID2, DEVICE_ID2, PortNumber.portNumber(2), Mep.MepDirection.UP_MEP, MDNAME1, MANAME1).build();
mepStore.createUpdateMep(new MepKeyId(MDNAME1, MANAME1, MEPID2), mep2);
mep21 = DefaultMep.builder(MEPID21, DEVICE_ID2, PortNumber.portNumber(2), Mep.MepDirection.UP_MEP, MDNAME1, MANAME1).build();
mepStore.createUpdateMep(new MepKeyId(MDNAME1, MANAME1, MEPID21), mep21);
mep22 = DefaultMep.builder(MEPID22, DEVICE_ID2, PortNumber.portNumber(2), Mep.MepDirection.UP_MEP, MDNAME2, MANAME2).build();
mepStore.createUpdateMep(new MepKeyId(MDNAME2, MANAME2, MEPID22), mep22);
device1 = new DefaultDevice(ProviderId.NONE, DEVICE_ID1, Device.Type.SWITCH, TEST_MFR, TEST_HW_VERSION, TEST_SW_VERSION, TEST_SN, new ChassisId(1), DefaultAnnotations.builder().set(AnnotationKeys.DRIVER, TEST_DRIVER).build());
device2 = new DefaultDevice(ProviderId.NONE, DEVICE_ID2, Device.Type.SWITCH, TEST_MFR, TEST_HW_VERSION, TEST_SW_VERSION, TEST_SN, new ChassisId(2), DefaultAnnotations.builder().set(AnnotationKeys.DRIVER, TEST_DRIVER).build());
AbstractProjectableModel.setDriverService(null, driverService);
Map<Class<? extends Behaviour>, Class<? extends Behaviour>> behaviours = new HashMap<>();
behaviours.put(DeviceDescriptionDiscovery.class, TestDeviceDiscoveryBehavior.class);
behaviours.put(CfmMepProgrammable.class, TestCfmMepProgrammable.class);
behaviours.put(SoamDmProgrammable.class, TestSoamDmProgrammable.class);
testDriver = new DefaultDriver(TEST_DRIVER, new ArrayList<Driver>(), TEST_MFR, TEST_HW_VERSION, TEST_SW_VERSION, behaviours, new HashMap<>());
}
Aggregations