Search in sources :

Example 21 with Timestamp

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();
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) DeviceEvent(org.onosproject.net.device.DeviceEvent) DefaultDevice(org.onosproject.net.DefaultDevice) Device(org.onosproject.net.Device) Port(org.onosproject.net.Port) DefaultPort(org.onosproject.net.DefaultPort) ArrayList(java.util.ArrayList) PortDescription(org.onosproject.net.device.PortDescription) WallClockTimestamp(org.onosproject.store.service.WallClockTimestamp) Timestamp(org.onosproject.store.Timestamp) MastershipBasedTimestamp(org.onosproject.store.impl.MastershipBasedTimestamp) MultiValuedTimestamp(org.onosproject.store.service.MultiValuedTimestamp) PortNumber(org.onosproject.net.PortNumber) HashSet(java.util.HashSet)

Example 22 with Timestamp

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);
}
Also used : DeviceId(org.onosproject.net.DeviceId) Timestamp(org.onosproject.store.Timestamp)

Example 23 with Timestamp

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());
}
Also used : IntentStoreDelegate(org.onosproject.net.intent.IntentStoreDelegate) SystemClockTimestamp(org.onosproject.store.trivial.SystemClockTimestamp) IntentData(org.onosproject.net.intent.IntentData) Intent(org.onosproject.net.intent.Intent) MockIntent(org.onosproject.net.intent.IntentTestsMocks.MockIntent) SystemClockTimestamp(org.onosproject.store.trivial.SystemClockTimestamp) Timestamp(org.onosproject.store.Timestamp) MockIntent(org.onosproject.net.intent.IntentTestsMocks.MockIntent) IntentEvent(org.onosproject.net.intent.IntentEvent) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 24 with Timestamp

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());
}
Also used : IntentStoreDelegate(org.onosproject.net.intent.IntentStoreDelegate) SystemClockTimestamp(org.onosproject.store.trivial.SystemClockTimestamp) IntentData(org.onosproject.net.intent.IntentData) Intent(org.onosproject.net.intent.Intent) MockIntent(org.onosproject.net.intent.IntentTestsMocks.MockIntent) SystemClockTimestamp(org.onosproject.store.trivial.SystemClockTimestamp) Timestamp(org.onosproject.store.Timestamp) MockIntent(org.onosproject.net.intent.IntentTestsMocks.MockIntent) IntentEvent(org.onosproject.net.intent.IntentEvent) Ignore(org.junit.Ignore) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 25 with Timestamp

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());
}
Also used : IntentStoreDelegate(org.onosproject.net.intent.IntentStoreDelegate) SystemClockTimestamp(org.onosproject.store.trivial.SystemClockTimestamp) IntentData(org.onosproject.net.intent.IntentData) Intent(org.onosproject.net.intent.Intent) MockIntent(org.onosproject.net.intent.IntentTestsMocks.MockIntent) SystemClockTimestamp(org.onosproject.store.trivial.SystemClockTimestamp) Timestamp(org.onosproject.store.Timestamp) MockIntent(org.onosproject.net.intent.IntentTestsMocks.MockIntent) IntentEvent(org.onosproject.net.intent.IntentEvent) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Aggregations

Timestamp (org.onosproject.store.Timestamp)32 Test (org.junit.Test)15 WallClockTimestamp (org.onosproject.store.service.WallClockTimestamp)14 MastershipBasedTimestamp (org.onosproject.store.impl.MastershipBasedTimestamp)13 MultiValuedTimestamp (org.onosproject.store.service.MultiValuedTimestamp)13 ProviderId (org.onosproject.net.provider.ProviderId)9 DeviceEvent (org.onosproject.net.device.DeviceEvent)8 AbstractIntentTest (org.onosproject.net.intent.AbstractIntentTest)8 Intent (org.onosproject.net.intent.Intent)8 IntentData (org.onosproject.net.intent.IntentData)8 IntentEvent (org.onosproject.net.intent.IntentEvent)8 IntentStoreDelegate (org.onosproject.net.intent.IntentStoreDelegate)8 MockIntent (org.onosproject.net.intent.IntentTestsMocks.MockIntent)8 SystemClockTimestamp (org.onosproject.store.trivial.SystemClockTimestamp)8 DeviceId (org.onosproject.net.DeviceId)6 ArrayList (java.util.ArrayList)5 ControllerNodeToNodeId.toNodeId (org.onosproject.cluster.ControllerNodeToNodeId.toNodeId)5 NodeId (org.onosproject.cluster.NodeId)5 DefaultDevice (org.onosproject.net.DefaultDevice)5 Device (org.onosproject.net.Device)5