Thomas Vachuska

Added application ID store; both trivial and distributed variants.

Showing 65 changed files with 627 additions and 133 deletions
......@@ -30,8 +30,8 @@ import org.apache.felix.scr.annotations.Modified;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onlab.onos.ApplicationId;
import org.onlab.onos.CoreService;
import org.onlab.onos.core.ApplicationId;
import org.onlab.onos.core.CoreService;
import org.onlab.onos.net.Host;
import org.onlab.onos.net.HostId;
import org.onlab.onos.net.Path;
......
......@@ -23,8 +23,8 @@ import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onlab.onos.ApplicationId;
import org.onlab.onos.CoreService;
import org.onlab.onos.core.ApplicationId;
import org.onlab.onos.core.CoreService;
import org.onlab.onos.net.Host;
import org.onlab.onos.net.HostId;
import org.onlab.onos.net.PortNumber;
......
......@@ -27,8 +27,8 @@ import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onlab.onos.ApplicationId;
import org.onlab.onos.CoreService;
import org.onlab.onos.core.ApplicationId;
import org.onlab.onos.core.CoreService;
import org.onlab.onos.net.Device;
import org.onlab.onos.net.Host;
import org.onlab.onos.net.device.DeviceService;
......
......@@ -30,8 +30,8 @@ import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onlab.onos.ApplicationId;
import org.onlab.onos.CoreService;
import org.onlab.onos.core.ApplicationId;
import org.onlab.onos.core.CoreService;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.Link;
import org.onlab.onos.net.Path;
......
......@@ -27,8 +27,8 @@ import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onlab.onos.ApplicationId;
import org.onlab.onos.CoreService;
import org.onlab.onos.core.ApplicationId;
import org.onlab.onos.core.CoreService;
import org.onlab.onos.net.Device;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.PortNumber;
......
......@@ -25,8 +25,8 @@ import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onlab.onos.ApplicationId;
import org.onlab.onos.CoreService;
import org.onlab.onos.core.ApplicationId;
import org.onlab.onos.core.CoreService;
import org.onlab.onos.net.packet.PacketContext;
import org.onlab.onos.net.packet.PacketProcessor;
import org.onlab.onos.net.packet.PacketService;
......
......@@ -20,7 +20,7 @@ package org.onlab.onos.sdnip;
import java.util.List;
import org.onlab.onos.ApplicationId;
import org.onlab.onos.core.ApplicationId;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.flow.DefaultTrafficSelector;
import org.onlab.onos.net.flow.DefaultTrafficTreatment;
......
......@@ -34,7 +34,7 @@ import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.Semaphore;
import org.apache.commons.lang3.tuple.Pair;
import org.onlab.onos.ApplicationId;
import org.onlab.onos.core.ApplicationId;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.Host;
import org.onlab.onos.net.flow.DefaultTrafficSelector;
......
......@@ -28,8 +28,8 @@ import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.onlab.onos.ApplicationId;
import org.onlab.onos.CoreService;
import org.onlab.onos.core.ApplicationId;
import org.onlab.onos.core.CoreService;
import org.onlab.onos.net.host.HostService;
import org.onlab.onos.net.intent.IntentService;
import org.onlab.onos.sdnip.bgp.BgpRouteEntry;
......
......@@ -23,7 +23,7 @@ import org.easymock.IArgumentMatcher;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.onlab.onos.ApplicationId;
import org.onlab.onos.core.ApplicationId;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.PortNumber;
......
......@@ -37,7 +37,7 @@ import org.junit.Before;
import org.junit.Test;
import org.onlab.junit.TestUtils;
import org.onlab.junit.TestUtils.TestUtilsException;
import org.onlab.onos.ApplicationId;
import org.onlab.onos.core.ApplicationId;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.DefaultHost;
import org.onlab.onos.net.DeviceId;
......
......@@ -19,7 +19,7 @@ import org.junit.Before;
import org.junit.Test;
import org.onlab.junit.TestUtils;
import org.onlab.junit.TestUtils.TestUtilsException;
import org.onlab.onos.ApplicationId;
import org.onlab.onos.core.ApplicationId;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.DefaultHost;
import org.onlab.onos.net.DeviceId;
......
......@@ -22,8 +22,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.karaf.shell.commands.Option;
import org.apache.karaf.shell.console.OsgiCommandSupport;
import org.onlab.onos.ApplicationId;
import org.onlab.onos.CoreService;
import org.onlab.onos.core.ApplicationId;
import org.onlab.onos.core.CoreService;
import org.onlab.onos.net.Annotations;
import org.onlab.osgi.DefaultServiceDirectory;
import org.onlab.osgi.ServiceNotFoundException;
......
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.onlab.onos.cli;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import org.apache.karaf.shell.commands.Command;
import org.onlab.onos.core.ApplicationId;
import org.onlab.onos.core.CoreService;
import java.util.Collections;
import java.util.List;
import static com.google.common.collect.Lists.newArrayList;
/**
* Lists application ID information.
*/
@Command(scope = "onos", name = "apps",
description = "Lists application ID information")
public class ApplicationIdListCommand extends AbstractShellCommand {
@Override
protected void execute() {
CoreService service = get(CoreService.class);
List<ApplicationId> ids = newArrayList(service.getAppIds());
Collections.sort(ids, Comparators.APP_ID_COMPARATOR);
if (outputJson()) {
print("%s", json(ids));
} else {
for (ApplicationId id : ids) {
print("id=%d, name=%s", id.id(), id.name());
}
}
}
// ApplicationId
private JsonNode json(List<ApplicationId> ids) {
ObjectMapper mapper = new ObjectMapper();
ArrayNode result = mapper.createArrayNode();
for (ApplicationId id : ids) {
result.add(mapper.createObjectNode()
.put("id", id.id())
.put("name", id.name()));
}
return result;
}
}
......@@ -18,6 +18,7 @@
*/
package org.onlab.onos.cli;
import org.onlab.onos.core.ApplicationId;
import org.onlab.onos.cluster.ControllerNode;
import org.onlab.onos.net.Element;
import org.onlab.onos.net.ElementId;
......@@ -36,6 +37,13 @@ public final class Comparators {
private Comparators() {
}
public static final Comparator<ApplicationId> APP_ID_COMPARATOR = new Comparator<ApplicationId>() {
@Override
public int compare(ApplicationId id1, ApplicationId id2) {
return id1.id() - id2.id();
}
};
public static final Comparator<ElementId> ELEMENT_ID_COMPARATOR = new Comparator<ElementId>() {
@Override
public int compare(ElementId id1, ElementId id2) {
......
......@@ -20,7 +20,7 @@ package org.onlab.onos.cli;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.karaf.shell.commands.Command;
import org.onlab.onos.CoreService;
import org.onlab.onos.core.CoreService;
import org.onlab.onos.cluster.ClusterService;
import org.onlab.onos.net.device.DeviceService;
import org.onlab.onos.net.flow.FlowRuleService;
......
......@@ -25,7 +25,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.collect.Maps;
import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
import org.onlab.onos.CoreService;
import org.onlab.onos.core.CoreService;
import org.onlab.onos.cli.AbstractShellCommand;
import org.onlab.onos.cli.Comparators;
import org.onlab.onos.net.Device;
......
......@@ -37,9 +37,9 @@
</command>
<command>
<action class="org.onlab.onos.cli.MastersListCommand"/>
<completers>
<ref component-id="clusterIdCompleter"/>
</completers>
</command>
<command>
<action class="org.onlab.onos.cli.ApplicationIdListCommand"/>
</command>
<command>
......
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.onlab.onos.core;
import java.util.Set;
/**
* Manages application IDs.
*/
public interface ApplicationIdStore {
/**
* Returns the set of currently registered application identifiers.
*
* @return set of application ids
*/
Set<ApplicationId> getAppIds();
/**
* Returns an existing application id from a given id.
* @param id the short value of the id
* @return an application id
*/
ApplicationId getAppId(Short id);
/**
* Registers a new application by its name, which is expected
* to follow the reverse DNS convention, e.g.
* {@code org.flying.circus.app}
*
* @param identifier string identifier
* @return the application id
*/
ApplicationId registerApplication(String identifier);
}
package org.onlab.onos;
package org.onlab.onos.core;
import java.util.Set;
/**
* Service for interacting with the core system of the controller.
......@@ -13,14 +15,11 @@ public interface CoreService {
Version version();
/**
* Registers a new application by its name, which is expected
* to follow the reverse DNS convention, e.g.
* {@code org.flying.circus.app}
* Returns the set of currently registered application identifiers.
*
* @param identifier string identifier
* @return the application id
* @return set of application ids
*/
ApplicationId registerApplication(String identifier);
Set<ApplicationId> getAppIds();
/**
* Returns an existing application id from a given id.
......@@ -29,4 +28,14 @@ public interface CoreService {
*/
ApplicationId getAppId(Short id);
/**
* Registers a new application by its name, which is expected
* to follow the reverse DNS convention, e.g.
* {@code org.flying.circus.app}
*
* @param identifier string identifier
* @return the application id
*/
ApplicationId registerApplication(String identifier);
}
......
package org.onlab.onos.impl;
import org.onlab.onos.ApplicationId;
package org.onlab.onos.core;
import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
/**
* Application id generator class.
* Application identifier.
*/
public class DefaultApplicationId implements ApplicationId {
private final short id;
private final String name;
// Ban public construction
protected DefaultApplicationId(Short id, String identifier) {
/**
* Creates a new application ID.
*
* @param id application identifier
* @param name application name
*/
public DefaultApplicationId(Short id, String name) {
this.id = id;
this.name = identifier;
this.name = name;
}
// Constructor for serializers.
private DefaultApplicationId() {
this.id = 0;
this.name = null;
}
@Override
......
/**
* ONOS Core API definitions.
*/
package org.onlab.onos;
package org.onlab.onos.core;
......
......@@ -23,7 +23,7 @@ import static org.slf4j.LoggerFactory.getLogger;
import java.util.Objects;
import org.onlab.onos.ApplicationId;
import org.onlab.onos.core.ApplicationId;
import org.onlab.onos.net.DeviceId;
import org.slf4j.Logger;
......
......@@ -18,7 +18,7 @@
*/
package org.onlab.onos.net.flow;
import org.onlab.onos.ApplicationId;
import org.onlab.onos.core.ApplicationId;
import org.onlab.onos.net.provider.Provider;
import com.google.common.util.concurrent.ListenableFuture;
......
......@@ -20,7 +20,7 @@ package org.onlab.onos.net.flow;
import java.util.concurrent.Future;
import org.onlab.onos.ApplicationId;
import org.onlab.onos.core.ApplicationId;
import org.onlab.onos.net.DeviceId;
/**
......
......@@ -19,7 +19,7 @@
package org.onlab.onos.net.intent;
import com.google.common.collect.ImmutableSet;
import org.onlab.onos.ApplicationId;
import org.onlab.onos.core.ApplicationId;
import org.onlab.onos.net.Link;
import org.onlab.onos.net.NetworkResource;
import org.onlab.onos.net.flow.TrafficSelector;
......
......@@ -19,7 +19,7 @@
package org.onlab.onos.net.intent;
import com.google.common.base.MoreObjects;
import org.onlab.onos.ApplicationId;
import org.onlab.onos.core.ApplicationId;
import org.onlab.onos.net.HostId;
import org.onlab.onos.net.flow.TrafficSelector;
import org.onlab.onos.net.flow.TrafficTreatment;
......
......@@ -18,7 +18,7 @@
*/
package org.onlab.onos.net.intent;
import org.onlab.onos.ApplicationId;
import org.onlab.onos.core.ApplicationId;
import org.onlab.onos.net.NetworkResource;
import org.onlab.onos.net.flow.BatchOperationTarget;
......
......@@ -19,7 +19,7 @@
package org.onlab.onos.net.intent;
import com.google.common.base.MoreObjects;
import org.onlab.onos.ApplicationId;
import org.onlab.onos.core.ApplicationId;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.Link;
import org.onlab.onos.net.flow.TrafficSelector;
......
......@@ -20,7 +20,7 @@ package org.onlab.onos.net.intent;
import com.google.common.base.MoreObjects;
import com.google.common.collect.Sets;
import org.onlab.onos.ApplicationId;
import org.onlab.onos.core.ApplicationId;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.flow.TrafficSelector;
import org.onlab.onos.net.flow.TrafficTreatment;
......
package org.onlab.onos.net.intent;
import org.onlab.onos.ApplicationId;
import org.onlab.onos.core.ApplicationId;
import org.onlab.onos.net.ConnectPoint;
/**
......
......@@ -2,7 +2,7 @@ package org.onlab.onos.net.intent;
import java.util.Collection;
import org.onlab.onos.ApplicationId;
import org.onlab.onos.core.ApplicationId;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.Link;
import org.onlab.onos.net.NetworkResource;
......
......@@ -19,7 +19,7 @@
package org.onlab.onos.net.intent;
import com.google.common.base.MoreObjects;
import org.onlab.onos.ApplicationId;
import org.onlab.onos.core.ApplicationId;
import org.onlab.onos.net.Path;
import org.onlab.onos.net.flow.TrafficSelector;
import org.onlab.onos.net.flow.TrafficTreatment;
......
......@@ -19,7 +19,7 @@
package org.onlab.onos.net.intent;
import com.google.common.base.MoreObjects;
import org.onlab.onos.ApplicationId;
import org.onlab.onos.core.ApplicationId;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.flow.TrafficSelector;
import org.onlab.onos.net.flow.TrafficTreatment;
......
......@@ -20,7 +20,7 @@ package org.onlab.onos.net.intent;
import com.google.common.base.MoreObjects;
import com.google.common.collect.Sets;
import org.onlab.onos.ApplicationId;
import org.onlab.onos.core.ApplicationId;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.flow.TrafficSelector;
import org.onlab.onos.net.flow.TrafficTreatment;
......
package org.onlab.onos;
import org.onlab.onos.core.ApplicationId;
import java.util.Objects;
/**
......
......@@ -2,9 +2,10 @@ package org.onlab.onos;
import com.google.common.testing.EqualsTester;
import org.junit.Test;
import org.onlab.onos.core.Version;
import static org.junit.Assert.*;
import static org.onlab.onos.Version.version;
import static org.onlab.onos.core.Version.version;
/**
* Tests of the version descriptor.
......
......@@ -2,7 +2,7 @@ package org.onlab.onos.net.intent;
import java.util.Set;
import org.onlab.onos.ApplicationId;
import org.onlab.onos.core.ApplicationId;
import org.onlab.onos.TestApplicationId;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.DeviceId;
......
package org.onlab.onos.impl;
package org.onlab.onos.core.impl;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.onlab.onos.ApplicationId;
import org.onlab.onos.CoreService;
import org.onlab.onos.Version;
import org.onlab.onos.core.ApplicationId;
import org.onlab.onos.core.ApplicationIdStore;
import org.onlab.onos.core.CoreService;
import org.onlab.onos.core.Version;
import org.onlab.util.Tools;
import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Core service implementation.
......@@ -21,15 +24,11 @@ import java.util.concurrent.atomic.AtomicInteger;
@Service
public class CoreManager implements CoreService {
private static final AtomicInteger ID_DISPENSER = new AtomicInteger(1);
private static final File VERSION_FILE = new File("../VERSION");
private static Version version = Version.version("1.0.0-SNAPSHOT");
private final Map<Short, DefaultApplicationId> appIds = new ConcurrentHashMap<>();
private final Map<String, DefaultApplicationId> appIdsByName = new ConcurrentHashMap<>();
// TODO: work in progress
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected ApplicationIdStore applicationIdStore;
@Activate
public void activate() {
......@@ -45,20 +44,19 @@ public class CoreManager implements CoreService {
}
@Override
public Set<ApplicationId> getAppIds() {
return applicationIdStore.getAppIds();
}
@Override
public ApplicationId getAppId(Short id) {
return appIds.get(id);
return applicationIdStore.getAppId(id);
}
@Override
public ApplicationId registerApplication(String name) {
DefaultApplicationId appId = appIdsByName.get(name);
if (appId == null) {
short id = (short) ID_DISPENSER.getAndIncrement();
appId = new DefaultApplicationId(id, name);
appIds.put(id, appId);
appIdsByName.put(name, appId);
}
return appId;
checkNotNull(name, "Application ID cannot be null");
return applicationIdStore.registerApplication(name);
}
}
......
package org.onlab.onos.impl;
package org.onlab.onos.core.impl;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
......
/**
* Miscellaneous core system implementations.
*/
package org.onlab.onos.impl;
\ No newline at end of file
package org.onlab.onos.core.impl;
\ No newline at end of file
......
......@@ -22,7 +22,7 @@ import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.onlab.onos.ApplicationId;
import org.onlab.onos.core.ApplicationId;
import org.onlab.onos.event.AbstractListenerRegistry;
import org.onlab.onos.event.EventDeliveryService;
import org.onlab.onos.net.Device;
......
......@@ -9,8 +9,8 @@ import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onlab.onos.ApplicationId;
import org.onlab.onos.CoreService;
import org.onlab.onos.core.ApplicationId;
import org.onlab.onos.core.CoreService;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.Link;
import org.onlab.onos.net.PortNumber;
......
......@@ -12,7 +12,7 @@ import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onlab.onos.CoreService;
import org.onlab.onos.core.CoreService;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.Link;
import org.onlab.onos.net.Path;
......
......@@ -10,8 +10,8 @@ import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onlab.onos.ApplicationId;
import org.onlab.onos.CoreService;
import org.onlab.onos.core.ApplicationId;
import org.onlab.onos.core.CoreService;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.Link;
import org.onlab.onos.net.flow.DefaultFlowRule;
......
......@@ -11,8 +11,8 @@ import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onlab.onos.ApplicationId;
import org.onlab.onos.CoreService;
import org.onlab.onos.core.ApplicationId;
import org.onlab.onos.core.CoreService;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.Link;
import org.onlab.onos.net.flow.DefaultFlowRule;
......
package org.onlab.onos.net.flow.impl;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.onlab.onos.net.flow.FlowRuleEvent.Type.RULE_ADDED;
import static org.onlab.onos.net.flow.FlowRuleEvent.Type.RULE_ADD_REQUESTED;
import static org.onlab.onos.net.flow.FlowRuleEvent.Type.RULE_REMOVED;
import static org.onlab.onos.net.flow.FlowRuleEvent.Type.RULE_REMOVE_REQUESTED;
import static org.onlab.onos.net.flow.FlowRuleEvent.Type.RULE_UPDATED;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.common.util.concurrent.ListenableFuture;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onlab.onos.ApplicationId;
import org.onlab.onos.core.ApplicationId;
import org.onlab.onos.core.DefaultApplicationId;
import org.onlab.onos.event.impl.TestEventDispatcher;
import org.onlab.onos.impl.DefaultApplicationId;
import org.onlab.onos.net.DefaultDevice;
import org.onlab.onos.net.Device;
import org.onlab.onos.net.Device.Type;
......@@ -63,11 +44,21 @@ import org.onlab.onos.net.provider.AbstractProvider;
import org.onlab.onos.net.provider.ProviderId;
import org.onlab.onos.store.trivial.impl.SimpleFlowRuleStore;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.common.util.concurrent.ListenableFuture;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import static org.junit.Assert.*;
import static org.onlab.onos.net.flow.FlowRuleEvent.Type.*;
/**
* Test codifying the flow rule service & flow rule provider service contracts.
......@@ -75,7 +66,6 @@ import com.google.common.util.concurrent.ListenableFuture;
public class FlowRuleManagerTest {
private static final ProviderId PID = new ProviderId("of", "foo");
private static final DeviceId DID = DeviceId.deviceId("of:001");
private static final int TIMEOUT = 10;
......@@ -135,7 +125,7 @@ public class FlowRuleManagerTest {
return rule;
}
private void validateEvents(FlowRuleEvent.Type ... events) {
private void validateEvents(FlowRuleEvent.Type... events) {
if (events == null) {
assertTrue("events generated", listener.events.isEmpty());
}
......@@ -156,6 +146,7 @@ public class FlowRuleManagerTest {
private int flowCount() {
return Sets.newHashSet(service.getFlowEntries(DID)).size();
}
@Test
public void getFlowEntries() {
assertTrue("store should be empty",
......@@ -448,7 +439,6 @@ public class FlowRuleManagerTest {
}
private static class TestListener implements FlowRuleListener {
final List<FlowRuleEvent> events = new ArrayList<>();
......
package org.onlab.onos.net.intent;
import org.junit.Test;
import org.onlab.onos.ApplicationId;
import org.onlab.onos.core.ApplicationId;
import org.onlab.onos.TestApplicationId;
import org.onlab.onos.net.HostId;
import org.onlab.onos.net.flow.TrafficSelector;
......
......@@ -12,7 +12,7 @@ import java.util.Set;
import org.junit.Before;
import org.junit.Test;
import org.onlab.onos.ApplicationId;
import org.onlab.onos.core.ApplicationId;
import org.onlab.onos.TestApplicationId;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.DeviceId;
......
......@@ -2,7 +2,7 @@ package org.onlab.onos.net.intent;
import org.junit.Before;
import org.junit.Test;
import org.onlab.onos.ApplicationId;
import org.onlab.onos.core.ApplicationId;
import org.onlab.onos.TestApplicationId;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.flow.TrafficSelector;
......
package org.onlab.onos.net.intent;
import org.junit.Test;
import org.onlab.onos.ApplicationId;
import org.onlab.onos.core.ApplicationId;
import org.onlab.onos.TestApplicationId;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.flow.TrafficSelector;
......
......@@ -3,7 +3,7 @@ package org.onlab.onos.net.intent.impl;
import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Test;
import org.onlab.onos.ApplicationId;
import org.onlab.onos.core.ApplicationId;
import org.onlab.onos.TestApplicationId;
import org.onlab.onos.net.Host;
import org.onlab.onos.net.HostId;
......
......@@ -2,7 +2,7 @@ package org.onlab.onos.net.intent.impl;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.onlab.onos.ApplicationId;
import org.onlab.onos.core.ApplicationId;
import org.onlab.onos.TestApplicationId;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.ElementId;
......
......@@ -2,7 +2,7 @@ package org.onlab.onos.net.intent.impl;
import org.hamcrest.Matchers;
//import org.junit.Test;
import org.onlab.onos.ApplicationId;
import org.onlab.onos.core.ApplicationId;
import org.onlab.onos.TestApplicationId;
import org.onlab.onos.net.flow.TrafficSelector;
import org.onlab.onos.net.flow.TrafficTreatment;
......
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.onlab.onos.store.core.impl;
import org.onlab.onos.core.ApplicationId;
import org.onlab.onos.event.AbstractEvent;
/**
* Application ID event.
*/
public class AppIdEvent extends AbstractEvent<AppIdEvent.Type, ApplicationId> {
public enum Type {
APP_REGISTERED
}
protected AppIdEvent(Type type, ApplicationId subject) {
super(type, subject);
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.onlab.onos.store.core.impl;
import org.onlab.onos.store.StoreDelegate;
/**
* Application ID store delegate.
*/
public interface AppIdStoreDelegate extends StoreDelegate<AppIdEvent> {
}
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.onlab.onos.store.core.impl;
import com.google.common.collect.ImmutableSet;
import com.hazelcast.core.EntryEvent;
import com.hazelcast.core.EntryListener;
import com.hazelcast.core.IAtomicLong;
import com.hazelcast.core.MapEvent;
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.onlab.onos.core.ApplicationId;
import org.onlab.onos.core.ApplicationIdStore;
import org.onlab.onos.core.DefaultApplicationId;
import org.onlab.onos.store.hz.AbstractHazelcastStore;
import org.onlab.onos.store.hz.SMap;
import org.onlab.onos.store.serializers.KryoNamespaces;
import org.onlab.onos.store.serializers.KryoSerializer;
import org.onlab.util.KryoNamespace;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
/**
* Simple implementation of the application ID registry using in-memory
* structures.
*/
@Component(immediate = true)
@Service
public class DistributedApplicationIdStore
extends AbstractHazelcastStore<AppIdEvent, AppIdStoreDelegate>
implements ApplicationIdStore {
protected IAtomicLong lastAppId;
protected SMap<String, DefaultApplicationId> appIdsByName;
protected Map<Short, DefaultApplicationId> appIds = new ConcurrentHashMap<>();
@Override
@Activate
public void activate() {
super.activate();
this.serializer = new KryoSerializer() {
@Override
protected void setupKryoPool() {
serializerPool = KryoNamespace.newBuilder()
.register(KryoNamespaces.API)
.build()
.populate(1);
}
};
lastAppId = theInstance.getAtomicLong("applicationId");
appIdsByName = new SMap<>(theInstance.<byte[], byte[]>getMap("appIdsByName"), this.serializer);
appIdsByName.addEntryListener((new RemoteAppIdEventHandler()), true);
primeAppIds();
log.info("Started");
}
@Deactivate
public void deactivate() {
log.info("Stopped");
}
@Override
public Set<ApplicationId> getAppIds() {
return ImmutableSet.<ApplicationId>copyOf(appIds.values());
}
@Override
public ApplicationId getAppId(Short id) {
ApplicationId appId = appIds.get(id);
if (appId == null) {
primeAppIds();
}
return appId;
}
private synchronized void primeAppIds() {
for (DefaultApplicationId appId : appIdsByName.values()) {
appIds.put(appId.id(), appId);
}
}
@Override
public synchronized ApplicationId registerApplication(String name) {
DefaultApplicationId appId = appIdsByName.get(name);
if (appId == null) {
short id = (short) lastAppId.getAndIncrement();
appId = new DefaultApplicationId(id, name);
appIds.put(id, appId);
appIdsByName.put(name, appId);
}
return appId;
}
private class RemoteAppIdEventHandler implements EntryListener<String, DefaultApplicationId> {
@Override
public void entryAdded(EntryEvent<String, DefaultApplicationId> event) {
DefaultApplicationId appId = event.getValue();
appIds.put(appId.id(), appId);
}
@Override
public void entryRemoved(EntryEvent<String, DefaultApplicationId> event) {
}
@Override
public void entryUpdated(EntryEvent<String, DefaultApplicationId> event) {
entryAdded(event);
}
@Override
public void entryEvicted(EntryEvent<String, DefaultApplicationId> event) {
}
@Override
public void mapEvicted(MapEvent event) {
}
@Override
public void mapCleared(MapEvent event) {
}
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 a distributed application ID registry store using Hazelcast.
*/
package org.onlab.onos.store.core.impl;
......@@ -15,7 +15,7 @@ import com.google.common.base.MoreObjects.ToStringHelper;
/**
* A structure that holds node mastership roles associated with a
* {@link DeviceId}. This structure needs to be locked through IMap.
* {@link org.onlab.onos.net.DeviceId}. This structure needs to be locked through IMap.
*/
final class RoleValue {
......
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.onlab.onos.store.serializers;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.Serializer;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
import org.onlab.onos.core.DefaultApplicationId;
/**
* Kryo Serializer for {@link org.onlab.onos.core.DefaultApplicationId}.
*/
public final class DefaultApplicationIdSerializer extends Serializer<DefaultApplicationId> {
/**
* Creates {@link org.onlab.onos.core.DefaultApplicationId} serializer instance.
*/
public DefaultApplicationIdSerializer() {
// non-null, immutable
super(false, true);
}
@Override
public void write(Kryo kryo, Output output, DefaultApplicationId object) {
kryo.writeObject(output, object.id());
kryo.writeObject(output, object.name());
}
@Override
public DefaultApplicationId read(Kryo kryo, Input input, Class<DefaultApplicationId> type) {
short id = kryo.readObject(input, Short.class);
String name = kryo.readObject(input, String.class);
return new DefaultApplicationId(id, name);
}
}
......@@ -7,6 +7,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import org.onlab.onos.core.DefaultApplicationId;
import org.onlab.onos.cluster.ControllerNode;
import org.onlab.onos.cluster.DefaultControllerNode;
import org.onlab.onos.cluster.NodeId;
......@@ -129,6 +130,7 @@ public final class KryoNamespaces {
FlowRuleBatchEntry.class,
FlowRuleBatchEntry.FlowRuleOperation.class
)
.register(DefaultApplicationId.class, new DefaultApplicationIdSerializer())
.register(URI.class, new URISerializer())
.register(NodeId.class, new NodeIdSerializer())
.register(ProviderId.class, new ProviderIdSerializer())
......
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.onlab.onos.store.trivial.impl;
import com.google.common.collect.ImmutableSet;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;
import org.onlab.onos.core.ApplicationId;
import org.onlab.onos.core.ApplicationIdStore;
import org.onlab.onos.core.DefaultApplicationId;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
/**
* Simple implementation of the application ID registry using in-memory
* structures.
*/
@Component(immediate = true)
@Service
public class SimpleApplicationIdStore implements ApplicationIdStore {
private static final AtomicInteger ID_DISPENSER = new AtomicInteger(1);
private final Map<Short, DefaultApplicationId> appIds = new ConcurrentHashMap<>();
private final Map<String, DefaultApplicationId> appIdsByName = new ConcurrentHashMap<>();
@Override
public Set<ApplicationId> getAppIds() {
return ImmutableSet.<ApplicationId>copyOf(appIds.values());
}
@Override
public ApplicationId getAppId(Short id) {
return appIds.get(id);
}
@Override
public ApplicationId registerApplication(String name) {
DefaultApplicationId appId = appIdsByName.get(name);
if (appId == null) {
short id = (short) ID_DISPENSER.getAndIncrement();
appId = new DefaultApplicationId(id, name);
appIds.put(id, appId);
appIdsByName.put(name, appId);
}
return appId;
}
}
......@@ -38,7 +38,7 @@ import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onlab.onos.ApplicationId;
import org.onlab.onos.core.ApplicationId;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.flow.BatchOperation;
import org.onlab.onos.net.flow.CompletedBatchOperation;
......