summaryrefslogtreecommitdiffstats
path: root/framework/src/onos/incubator/store
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/onos/incubator/store')
-rw-r--r--framework/src/onos/incubator/store/src/main/java/org/onosproject/incubator/store/meter/impl/DistributedMeterStore.java51
-rw-r--r--framework/src/onos/incubator/store/src/main/java/org/onosproject/incubator/store/virtual/impl/DistributedVirtualNetworkStore.java147
-rw-r--r--framework/src/onos/incubator/store/src/main/java/org/onosproject/incubator/store/virtual/impl/package-info.java20
3 files changed, 197 insertions, 21 deletions
diff --git a/framework/src/onos/incubator/store/src/main/java/org/onosproject/incubator/store/meter/impl/DistributedMeterStore.java b/framework/src/onos/incubator/store/src/main/java/org/onosproject/incubator/store/meter/impl/DistributedMeterStore.java
index 32890cb1..62a94675 100644
--- a/framework/src/onos/incubator/store/src/main/java/org/onosproject/incubator/store/meter/impl/DistributedMeterStore.java
+++ b/framework/src/onos/incubator/store/src/main/java/org/onosproject/incubator/store/meter/impl/DistributedMeterStore.java
@@ -33,6 +33,7 @@ import org.onosproject.net.meter.Meter;
import org.onosproject.net.meter.MeterEvent;
import org.onosproject.net.meter.MeterFailReason;
import org.onosproject.net.meter.MeterId;
+import org.onosproject.net.meter.MeterKey;
import org.onosproject.net.meter.MeterOperation;
import org.onosproject.net.meter.MeterState;
import org.onosproject.net.meter.MeterStore;
@@ -78,12 +79,12 @@ public class DistributedMeterStore extends AbstractStore<MeterEvent, MeterStoreD
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
private ClusterService clusterService;
- private ConsistentMap<MeterId, MeterData> meters;
+ private ConsistentMap<MeterKey, MeterData> meters;
private NodeId local;
- private MapEventListener mapListener = new InternalMapEventListener();
+ private MapEventListener<MeterKey, MeterData> mapListener = new InternalMapEventListener();
- private Map<MeterId, CompletableFuture<MeterStoreResult>> futures =
+ private Map<MeterKey, CompletableFuture<MeterStoreResult>> futures =
Maps.newConcurrentMap();
@Activate
@@ -92,9 +93,10 @@ public class DistributedMeterStore extends AbstractStore<MeterEvent, MeterStoreD
local = clusterService.getLocalNode().id();
- meters = storageService.<MeterId, MeterData>consistentMapBuilder()
+ meters = storageService.<MeterKey, MeterData>consistentMapBuilder()
.withName(METERSTORE)
.withSerializer(Serializer.using(Arrays.asList(KryoNamespaces.API),
+ MeterKey.class,
MeterData.class,
DefaultMeter.class,
DefaultBand.class,
@@ -120,11 +122,12 @@ public class DistributedMeterStore extends AbstractStore<MeterEvent, MeterStoreD
@Override
public CompletableFuture<MeterStoreResult> storeMeter(Meter meter) {
CompletableFuture<MeterStoreResult> future = new CompletableFuture<>();
- futures.put(meter.id(), future);
+ MeterKey key = MeterKey.key(meter.deviceId(), meter.id());
+ futures.put(key, future);
MeterData data = new MeterData(meter, null, local);
try {
- meters.put(meter.id(), data);
+ meters.put(key, data);
} catch (StorageException e) {
future.completeExceptionally(e);
}
@@ -136,14 +139,15 @@ public class DistributedMeterStore extends AbstractStore<MeterEvent, MeterStoreD
@Override
public CompletableFuture<MeterStoreResult> deleteMeter(Meter meter) {
CompletableFuture<MeterStoreResult> future = new CompletableFuture<>();
- futures.put(meter.id(), future);
+ MeterKey key = MeterKey.key(meter.deviceId(), meter.id());
+ futures.put(key, future);
MeterData data = new MeterData(meter, null, local);
// update the state of the meter. It will be pruned by observing
// that it has been removed from the dataplane.
try {
- if (meters.computeIfPresent(meter.id(), (k, v) -> data) == null) {
+ if (meters.computeIfPresent(key, (k, v) -> data) == null) {
future.complete(MeterStoreResult.success());
}
} catch (StorageException e) {
@@ -157,11 +161,12 @@ public class DistributedMeterStore extends AbstractStore<MeterEvent, MeterStoreD
@Override
public CompletableFuture<MeterStoreResult> updateMeter(Meter meter) {
CompletableFuture<MeterStoreResult> future = new CompletableFuture<>();
- futures.put(meter.id(), future);
+ MeterKey key = MeterKey.key(meter.deviceId(), meter.id());
+ futures.put(key, future);
MeterData data = new MeterData(meter, null, local);
try {
- if (meters.computeIfPresent(meter.id(), (k, v) -> data) == null) {
+ if (meters.computeIfPresent(key, (k, v) -> data) == null) {
future.complete(MeterStoreResult.fail(MeterFailReason.INVALID_METER));
}
} catch (StorageException e) {
@@ -172,7 +177,8 @@ public class DistributedMeterStore extends AbstractStore<MeterEvent, MeterStoreD
@Override
public void updateMeterState(Meter meter) {
- meters.computeIfPresent(meter.id(), (id, v) -> {
+ MeterKey key = MeterKey.key(meter.deviceId(), meter.id());
+ meters.computeIfPresent(key, (k, v) -> {
DefaultMeter m = (DefaultMeter) v.meter();
m.setState(meter.state());
m.setProcessedPackets(meter.packetsSeen());
@@ -185,8 +191,8 @@ public class DistributedMeterStore extends AbstractStore<MeterEvent, MeterStoreD
}
@Override
- public Meter getMeter(MeterId meterId) {
- MeterData data = Versioned.valueOrElse(meters.get(meterId), null);
+ public Meter getMeter(MeterKey key) {
+ MeterData data = Versioned.valueOrElse(meters.get(key), null);
return data == null ? null : data.meter();
}
@@ -198,19 +204,22 @@ public class DistributedMeterStore extends AbstractStore<MeterEvent, MeterStoreD
@Override
public void failedMeter(MeterOperation op, MeterFailReason reason) {
- meters.computeIfPresent(op.meter().id(), (k, v) ->
+ MeterKey key = MeterKey.key(op.meter().deviceId(), op.meter().id());
+ meters.computeIfPresent(key, (k, v) ->
new MeterData(v.meter(), reason, v.origin()));
}
@Override
public void deleteMeterNow(Meter m) {
- futures.remove(m.id());
- meters.remove(m.id());
+ MeterKey key = MeterKey.key(m.deviceId(), m.id());
+ futures.remove(key);
+ meters.remove(key);
}
- private class InternalMapEventListener implements MapEventListener<MeterId, MeterData> {
+ private class InternalMapEventListener implements MapEventListener<MeterKey, MeterData> {
@Override
- public void event(MapEvent<MeterId, MeterData> event) {
+ public void event(MapEvent<MeterKey, MeterData> event) {
+ MeterKey key = event.key();
MeterData data = event.value().value();
NodeId master = mastershipService.getMasterFor(data.meter().deviceId());
switch (event.type()) {
@@ -227,17 +236,17 @@ public class DistributedMeterStore extends AbstractStore<MeterEvent, MeterStoreD
} else if (data.reason().isPresent() && local.equals(data.origin())) {
MeterStoreResult msr = MeterStoreResult.fail(data.reason().get());
//TODO: No future -> no friend
- futures.get(data.meter().id()).complete(msr);
+ futures.get(key).complete(msr);
}
break;
case ADDED:
if (local.equals(data.origin()) && data.meter().state() == MeterState.PENDING_ADD) {
- futures.remove(data.meter().id()).complete(MeterStoreResult.success());
+ futures.remove(key).complete(MeterStoreResult.success());
}
break;
case REMOVED:
if (local.equals(data.origin()) && data.meter().state() == MeterState.PENDING_REMOVE) {
- futures.remove(data.meter().id()).complete(MeterStoreResult.success());
+ futures.remove(key).complete(MeterStoreResult.success());
}
break;
default:
diff --git a/framework/src/onos/incubator/store/src/main/java/org/onosproject/incubator/store/virtual/impl/DistributedVirtualNetworkStore.java b/framework/src/onos/incubator/store/src/main/java/org/onosproject/incubator/store/virtual/impl/DistributedVirtualNetworkStore.java
new file mode 100644
index 00000000..69e56c0b
--- /dev/null
+++ b/framework/src/onos/incubator/store/src/main/java/org/onosproject/incubator/store/virtual/impl/DistributedVirtualNetworkStore.java
@@ -0,0 +1,147 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.incubator.store.virtual.impl;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Service;
+import org.onosproject.incubator.net.tunnel.TunnelId;
+import org.onosproject.incubator.net.virtual.DefaultVirtualDevice;
+import org.onosproject.incubator.net.virtual.DefaultVirtualNetwork;
+import org.onosproject.incubator.net.virtual.NetworkId;
+import org.onosproject.incubator.net.virtual.TenantId;
+import org.onosproject.incubator.net.virtual.VirtualDevice;
+import org.onosproject.incubator.net.virtual.VirtualLink;
+import org.onosproject.incubator.net.virtual.VirtualNetwork;
+import org.onosproject.incubator.net.virtual.VirtualNetworkEvent;
+import org.onosproject.incubator.net.virtual.VirtualNetworkStore;
+import org.onosproject.incubator.net.virtual.VirtualNetworkStoreDelegate;
+import org.onosproject.incubator.net.virtual.VirtualPort;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.Port;
+import org.onosproject.net.PortNumber;
+import org.onosproject.store.AbstractStore;
+import org.slf4j.Logger;
+
+import java.util.Set;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Implementation of the network store.
+ */
+@Component(immediate = true)
+@Service
+public class DistributedVirtualNetworkStore
+ extends AbstractStore<VirtualNetworkEvent, VirtualNetworkStoreDelegate>
+ implements VirtualNetworkStore {
+
+ private final Logger log = getLogger(getClass());
+
+ // TODO: track tenants by ID
+ // TODO: track networks by ID and by tenants
+ // TODO: track devices by network ID and device ID
+ // TODO: track devices by network ID
+ // TODO: setup block allocator for network IDs
+
+ // TODO: notify delegate
+
+ @Activate
+ public void activate() {
+ log.info("Started");
+ }
+
+ @Deactivate
+ public void deactivate() {
+ log.info("Stopped");
+ }
+
+ @Override
+ public void addTenantId(TenantId tenantId) {
+ }
+
+ @Override
+ public void removeTenantId(TenantId tenantId) {
+ }
+
+ @Override
+ public Set<TenantId> getTenantIds() {
+ return null;
+ }
+
+ @Override
+ public VirtualNetwork addNetwork(TenantId tenantId) {
+ return new DefaultVirtualNetwork(genNetworkId(), tenantId);
+ }
+
+ private NetworkId genNetworkId() {
+ return NetworkId.networkId(0); // TODO: use a block allocator
+ }
+
+
+ @Override
+ public void removeNetwork(NetworkId networkId) {
+ }
+
+ @Override
+ public VirtualDevice addDevice(NetworkId networkId, DeviceId deviceId) {
+ return new DefaultVirtualDevice(networkId, deviceId);
+ }
+
+ @Override
+ public void removeDevice(NetworkId networkId, DeviceId deviceId) {
+ }
+
+ @Override
+ public VirtualLink addLink(NetworkId networkId, ConnectPoint src, ConnectPoint dst, TunnelId realizedBy) {
+ return null;
+ }
+
+ @Override
+ public void removeLink(NetworkId networkId, ConnectPoint src, ConnectPoint dst) {
+ }
+
+ @Override
+ public VirtualPort addPort(NetworkId networkId, DeviceId deviceId, PortNumber portNumber, Port realizedBy) {
+ return null;
+ }
+
+ @Override
+ public void removePort(NetworkId networkId, DeviceId deviceId, PortNumber portNumber) {
+ }
+
+ @Override
+ public Set<VirtualNetwork> getNetworks(TenantId tenantId) {
+ return null;
+ }
+
+ @Override
+ public Set<VirtualDevice> getDevices(NetworkId networkId) {
+ return null;
+ }
+
+ @Override
+ public Set<VirtualLink> getLinks(NetworkId networkId) {
+ return null;
+ }
+
+ @Override
+ public Set<VirtualPort> getPorts(NetworkId networkId, DeviceId deviceId) {
+ return null;
+ }
+}
diff --git a/framework/src/onos/incubator/store/src/main/java/org/onosproject/incubator/store/virtual/impl/package-info.java b/framework/src/onos/incubator/store/src/main/java/org/onosproject/incubator/store/virtual/impl/package-info.java
new file mode 100644
index 00000000..12fa9091
--- /dev/null
+++ b/framework/src/onos/incubator/store/src/main/java/org/onosproject/incubator/store/virtual/impl/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Implementation of distributed virtual network store.
+ */
+package org.onosproject.incubator.store.virtual.impl;