use of org.onosproject.store.Timestamp in project onos by opennetworkinglab.
the class GossipDeviceStore method updatePortsInternal.
private List<DeviceEvent> updatePortsInternal(ProviderId providerId, DeviceId deviceId, Timestamped<List<PortDescription>> portDescriptions) {
Device device = devices.get(deviceId);
if (device == null) {
log.debug("Device is no longer valid: {}", deviceId);
return Collections.emptyList();
}
Map<ProviderId, DeviceDescriptions> descsMap = deviceDescs.get(deviceId);
checkArgument(descsMap != null, DEVICE_NOT_FOUND, deviceId);
List<DeviceEvent> events = new ArrayList<>();
synchronized (descsMap) {
if (isDeviceRemoved(deviceId, portDescriptions.timestamp())) {
log.debug("Ignoring outdated events: {}", portDescriptions);
return Collections.emptyList();
}
DeviceDescriptions descs = descsMap.get(providerId);
// every provider must provide DeviceDescription.
checkArgument(descs != null, "Device description for Device ID %s from Provider %s was not found", deviceId, providerId);
Map<PortNumber, Port> ports = getPortMap(deviceId);
final Timestamp newTimestamp = portDescriptions.timestamp();
// Add new ports
Set<PortNumber> processed = new HashSet<>();
for (PortDescription portDescription : portDescriptions.value()) {
final PortNumber number = portDescription.portNumber();
processed.add(number);
final Port oldPort = ports.get(number);
final Port newPort;
boolean isRemoved = portDescription.isRemoved();
final Timestamped<PortDescription> existingPortDesc = descs.getPortDesc(number);
if (existingPortDesc == null || newTimestamp.compareTo(existingPortDesc.timestamp()) >= 0) {
// on new port or valid update
// update description
descs.putPortDesc(new Timestamped<>(portDescription, portDescriptions.timestamp()));
newPort = composePort(device, number, descsMap);
} else {
// outdated event, ignored.
continue;
}
if (isRemoved && oldPort != null) {
events.add(removePort(deviceId, oldPort.number(), providerId, descsMap));
} else if (!isRemoved) {
events.add(oldPort == null ? createPort(device, newPort, ports) : updatePort(device, oldPort, newPort, ports));
}
}
events.addAll(pruneOldPorts(device, ports, processed));
}
return FluentIterable.from(events).filter(notNull()).toList();
}
use of org.onosproject.store.Timestamp in project onos by opennetworkinglab.
the class InternalDeviceStatusChangeEventSerializer method read.
@Override
public InternalDeviceStatusChangeEvent read(Kryo kryo, Input input, Class<InternalDeviceStatusChangeEvent> type) {
DeviceId deviceId = kryo.readObject(input, DeviceId.class, deviceIdSerializer());
Timestamp timestamp = (Timestamp) kryo.readClassAndObject(input);
Boolean available = (Boolean) kryo.readClassAndObject(input);
return new InternalDeviceStatusChangeEvent(deviceId, timestamp, available);
}
use of org.onosproject.store.Timestamp in project onos by opennetworkinglab.
the class IntentCleanupTest method skipPoll.
/**
* Only submit one of two intents because one is too new.
*/
@Test
public void skipPoll() {
IntentStoreDelegate mockDelegate = new IntentStoreDelegate() {
@Override
public void process(IntentData intentData) {
intentData.setState(CORRUPT);
store.write(intentData);
}
@Override
public void notify(IntentEvent event) {
}
};
store.setDelegate(mockDelegate);
Intent intent = new MockIntent(1L);
IntentData data = new IntentData(intent, INSTALL_REQ, null);
store.addPending(data);
Intent intent2 = new MockIntent(2L);
Timestamp version = new SystemClockTimestamp(1L);
data = new IntentData(intent2, INSTALL_REQ, version);
store.addPending(data);
cleanup.run();
assertEquals("Expect number of submits incorrect", 1, service.submitCounter());
}
use of org.onosproject.store.Timestamp in project onos by opennetworkinglab.
the class IntentCleanupTest method installingPoll.
/**
* Trigger resubmit of intent in INSTALLING for too long.
*/
@Test
@Ignore("The implementation is dependent on the SimpleStore")
public void installingPoll() {
IntentStoreDelegate mockDelegate = new IntentStoreDelegate() {
@Override
public void process(IntentData intentData) {
intentData.setState(INSTALLING);
store.write(intentData);
}
@Override
public void notify(IntentEvent event) {
cleanup.event(event);
}
};
store.setDelegate(mockDelegate);
Intent intent = new MockIntent(1L);
Timestamp version = new SystemClockTimestamp(1L);
IntentData data = new IntentData(intent, INSTALL_REQ, version);
store.addPending(data);
cleanup.run();
assertEquals("Expect number of submits incorrect", 1, service.pendingCounter());
}
use of org.onosproject.store.Timestamp in project onos by opennetworkinglab.
the class IntentCleanupTest method corruptPoll.
/**
* Trigger resubmit of intent in CORRUPT during periodic poll.
*/
@Test
public void corruptPoll() {
IntentStoreDelegate mockDelegate = new IntentStoreDelegate() {
@Override
public void process(IntentData intentData) {
intentData.setState(CORRUPT);
store.write(intentData);
}
@Override
public void notify(IntentEvent event) {
}
};
store.setDelegate(mockDelegate);
Intent intent = new MockIntent(1L);
Timestamp version = new SystemClockTimestamp(1L);
IntentData data = new IntentData(intent, INSTALL_REQ, version);
store.addPending(data);
// FIXME broken?
cleanup.run();
assertEquals("Expect number of submits incorrect", 1, service.submitCounter());
}
Aggregations