diff options
Diffstat (limited to 'framework/src/onos/core/common/src/main/java/org/onosproject')
44 files changed, 0 insertions, 5394 deletions
diff --git a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/AnnotatedCodec.java b/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/AnnotatedCodec.java deleted file mode 100644 index 8c714625..00000000 --- a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/AnnotatedCodec.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2014-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.codec.impl; - -import com.fasterxml.jackson.databind.node.ObjectNode; - -import org.onosproject.codec.CodecContext; -import org.onosproject.codec.JsonCodec; -import org.onosproject.net.Annotated; -import org.onosproject.net.Annotations; -import org.onosproject.net.DefaultAnnotations; - -/** - * Base JSON codec for annotated entities. - */ -public abstract class AnnotatedCodec<T extends Annotated> extends JsonCodec<T> { - - /** - * Adds JSON encoding of the given item annotations to the specified node. - * - * @param node node to add annotations to - * @param entity annotated entity - * @param context encode context - * @return the given node - */ - protected ObjectNode annotate(ObjectNode node, T entity, CodecContext context) { - if (!entity.annotations().keys().isEmpty()) { - JsonCodec<Annotations> codec = context.codec(Annotations.class); - node.set("annotations", codec.encode(entity.annotations(), context)); - } - return node; - } - - /** - * Extracts annotations of given Object. - * - * @param objNode annotated JSON object node - * @param context decode context - * @return extracted Annotations - */ - protected Annotations extractAnnotations(ObjectNode objNode, CodecContext context) { - - JsonCodec<Annotations> codec = context.codec(Annotations.class); - if (objNode.has("annotations") && objNode.isObject()) { - return codec.decode(get(objNode, "annotations"), context); - } else { - return DefaultAnnotations.EMPTY; - } - } - -} diff --git a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/AnnotationsCodec.java b/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/AnnotationsCodec.java deleted file mode 100644 index de6ca1b9..00000000 --- a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/AnnotationsCodec.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2014-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.codec.impl; - -import com.fasterxml.jackson.databind.node.ObjectNode; - -import org.onosproject.codec.CodecContext; -import org.onosproject.codec.JsonCodec; -import org.onosproject.net.Annotations; -import org.onosproject.net.DefaultAnnotations; -import org.onosproject.net.DefaultAnnotations.Builder; - -/** - * Annotations JSON codec. - */ -public final class AnnotationsCodec extends JsonCodec<Annotations> { - - @Override - public ObjectNode encode(Annotations annotations, CodecContext context) { - ObjectNode result = context.mapper().createObjectNode(); - for (String key : annotations.keys()) { - result.put(key, annotations.value(key)); - } - return result; - } - - @Override - public Annotations decode(ObjectNode json, CodecContext context) { - Builder builder = DefaultAnnotations.builder(); - - json.fields().forEachRemaining(e -> - builder.set(e.getKey(), e.getValue().asText())); - - return builder.build(); - } -} diff --git a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/ApplicationCodec.java b/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/ApplicationCodec.java deleted file mode 100644 index a09c0bdb..00000000 --- a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/ApplicationCodec.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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.codec.impl; - -import com.fasterxml.jackson.databind.node.ObjectNode; -import org.onosproject.app.ApplicationService; -import org.onosproject.codec.CodecContext; -import org.onosproject.codec.JsonCodec; -import org.onosproject.core.Application; - -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * Application JSON codec. - */ -public final class ApplicationCodec extends JsonCodec<Application> { - - @Override - public ObjectNode encode(Application app, CodecContext context) { - checkNotNull(app, "Application cannot be null"); - ApplicationService service = context.getService(ApplicationService.class); - return context.mapper().createObjectNode() - .put("name", app.id().name()) - .put("id", app.id().id()) - .put("version", app.version().toString()) - .put("description", app.description()) - .put("origin", app.origin()) - .put("permissions", app.permissions().toString()) // FIXME: change to an array - .put("featuresRepo", app.featuresRepo().isPresent() ? - app.featuresRepo().get().toString() : "") - .put("features", app.features().toString()) // FIXME: change to an array - .put("requiredApps", app.requiredApps().toString()) // FIXME: change to an array - .put("state", service.getState(app.id()).toString()); - } - -} diff --git a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/CodecManager.java b/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/CodecManager.java deleted file mode 100644 index c7af4e5b..00000000 --- a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/CodecManager.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright 2014-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.codec.impl; - -import com.google.common.collect.ImmutableSet; - -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.packet.Ethernet; -import org.onosproject.cluster.ControllerNode; -import org.onosproject.codec.CodecService; -import org.onosproject.codec.JsonCodec; -import org.onosproject.core.Application; -import org.onosproject.net.Annotations; -import org.onosproject.net.ConnectPoint; -import org.onosproject.net.Device; -import org.onosproject.net.Host; -import org.onosproject.net.HostLocation; -import org.onosproject.net.Link; -import org.onosproject.net.Path; -import org.onosproject.net.Port; -import org.onosproject.net.driver.Driver; -import org.onosproject.net.flow.FlowEntry; -import org.onosproject.net.flow.FlowRule; -import org.onosproject.net.flow.TableStatisticsEntry; -import org.onosproject.net.device.PortStatistics; -import org.onosproject.net.flow.TrafficSelector; -import org.onosproject.net.flow.TrafficTreatment; -import org.onosproject.net.flow.criteria.Criterion; -import org.onosproject.net.flow.instructions.Instruction; -import org.onosproject.net.group.Group; -import org.onosproject.net.group.GroupBucket; -import org.onosproject.net.intent.ConnectivityIntent; -import org.onosproject.net.intent.Constraint; -import org.onosproject.net.intent.HostToHostIntent; -import org.onosproject.net.intent.Intent; -import org.onosproject.net.intent.PointToPointIntent; -import org.onosproject.net.statistic.Load; -import org.onosproject.net.topology.Topology; -import org.onosproject.net.topology.TopologyCluster; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; - -/** - * Implementation of the JSON codec brokering service. - */ -@Component(immediate = true) -@Service -public class CodecManager implements CodecService { - - private static Logger log = LoggerFactory.getLogger(CodecManager.class); - - private final Map<Class<?>, JsonCodec> codecs = new ConcurrentHashMap<>(); - - @Activate - public void activate() { - codecs.clear(); - registerCodec(Application.class, new ApplicationCodec()); - registerCodec(ControllerNode.class, new ControllerNodeCodec()); - registerCodec(Annotations.class, new AnnotationsCodec()); - registerCodec(Device.class, new DeviceCodec()); - registerCodec(Port.class, new PortCodec()); - registerCodec(ConnectPoint.class, new ConnectPointCodec()); - registerCodec(Link.class, new LinkCodec()); - registerCodec(Host.class, new HostCodec()); - registerCodec(HostLocation.class, new HostLocationCodec()); - registerCodec(HostToHostIntent.class, new HostToHostIntentCodec()); - registerCodec(PointToPointIntent.class, new PointToPointIntentCodec()); - registerCodec(Intent.class, new IntentCodec()); - registerCodec(ConnectivityIntent.class, new ConnectivityIntentCodec()); - registerCodec(FlowEntry.class, new FlowEntryCodec()); - registerCodec(FlowRule.class, new FlowRuleCodec()); - registerCodec(TrafficTreatment.class, new TrafficTreatmentCodec()); - registerCodec(TrafficSelector.class, new TrafficSelectorCodec()); - registerCodec(Instruction.class, new InstructionCodec()); - registerCodec(Criterion.class, new CriterionCodec()); - registerCodec(Ethernet.class, new EthernetCodec()); - registerCodec(Constraint.class, new ConstraintCodec()); - registerCodec(Topology.class, new TopologyCodec()); - registerCodec(TopologyCluster.class, new TopologyClusterCodec()); - registerCodec(Path.class, new PathCodec()); - registerCodec(Group.class, new GroupCodec()); - registerCodec(Driver.class, new DriverCodec()); - registerCodec(GroupBucket.class, new GroupBucketCodec()); - registerCodec(Load.class, new LoadCodec()); - registerCodec(TableStatisticsEntry.class, new TableStatisticsEntryCodec()); - registerCodec(PortStatistics.class, new PortStatisticsCodec()); - log.info("Started"); - } - - @Deactivate - public void deactivate() { - codecs.clear(); - log.info("Stopped"); - } - - @Override - public Set<Class<?>> getCodecs() { - return ImmutableSet.copyOf(codecs.keySet()); - } - - @Override - @SuppressWarnings("unchecked") - public <T> JsonCodec<T> getCodec(Class<T> entityClass) { - return codecs.get(entityClass); - } - - @Override - public <T> void registerCodec(Class<T> entityClass, JsonCodec<T> codec) { - codecs.putIfAbsent(entityClass, codec); - } - - @Override - public void unregisterCodec(Class<?> entityClass) { - codecs.remove(entityClass); - } - -} diff --git a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/ConnectPointCodec.java b/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/ConnectPointCodec.java deleted file mode 100644 index ac23ef89..00000000 --- a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/ConnectPointCodec.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2014-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.codec.impl; - -import com.fasterxml.jackson.databind.node.ObjectNode; - -import org.onosproject.codec.CodecContext; -import org.onosproject.codec.JsonCodec; -import org.onosproject.net.ConnectPoint; -import org.onosproject.net.DeviceId; -import org.onosproject.net.ElementId; -import org.onosproject.net.HostId; -import org.onosproject.net.PortNumber; - -import static com.google.common.base.Preconditions.checkNotNull; -import static org.onosproject.net.PortNumber.portNumber; - -/** - * Connection point JSON codec. - */ -public final class ConnectPointCodec extends JsonCodec<ConnectPoint> { - - // JSON field names - private static final String ELEMENT_HOST = "host"; - private static final String ELEMENT_DEVICE = "device"; - private static final String PORT = "port"; - - @Override - public ObjectNode encode(ConnectPoint point, CodecContext context) { - checkNotNull(point, "Connect point cannot be null"); - ObjectNode root = context.mapper().createObjectNode() - .put(PORT, point.port().toString()); - - if (point.elementId() instanceof DeviceId) { - root.put(ELEMENT_DEVICE, point.deviceId().toString()); - } else if (point.elementId() instanceof HostId) { - root.put(ELEMENT_HOST, point.hostId().toString()); - } - - return root; - } - - @Override - public ConnectPoint decode(ObjectNode json, CodecContext context) { - if (json == null || !json.isObject()) { - return null; - } - - ElementId elementId; - if (json.has(ELEMENT_DEVICE)) { - elementId = DeviceId.deviceId(json.get(ELEMENT_DEVICE).asText()); - } else if (json.has(ELEMENT_HOST)) { - elementId = HostId.hostId(json.get(ELEMENT_HOST).asText()); - } else { - // invalid JSON - return null; - } - PortNumber portNumber = portNumber(json.get(PORT).asText()); - return new ConnectPoint(elementId, portNumber); - } -} diff --git a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/ConnectivityIntentCodec.java b/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/ConnectivityIntentCodec.java deleted file mode 100644 index 9e8cd86c..00000000 --- a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/ConnectivityIntentCodec.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * 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.codec.impl; - -import java.util.ArrayList; -import java.util.stream.IntStream; - -import org.onosproject.codec.CodecContext; -import org.onosproject.codec.JsonCodec; -import org.onosproject.net.flow.TrafficSelector; -import org.onosproject.net.flow.TrafficTreatment; -import org.onosproject.net.intent.ConnectivityIntent; -import org.onosproject.net.intent.Constraint; -import org.onosproject.net.intent.Intent; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.node.ObjectNode; - -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * Connectivity intent codec. - */ -public final class ConnectivityIntentCodec extends JsonCodec<ConnectivityIntent> { - - private static final String CONSTRAINTS = "constraints"; - private static final String SELECTOR = "selector"; - private static final String TREATMENT = "treatment"; - - @Override - public ObjectNode encode(ConnectivityIntent intent, CodecContext context) { - checkNotNull(intent, "Connectivity intent cannot be null"); - - final JsonCodec<Intent> intentCodec = context.codec(Intent.class); - final ObjectNode result = intentCodec.encode(intent, context); - - if (intent.selector() != null) { - final JsonCodec<TrafficSelector> selectorCodec = - context.codec(TrafficSelector.class); - result.set(SELECTOR, selectorCodec.encode(intent.selector(), context)); - } - - if (intent.treatment() != null) { - final JsonCodec<TrafficTreatment> treatmentCodec = - context.codec(TrafficTreatment.class); - result.set(TREATMENT, treatmentCodec.encode(intent.treatment(), context)); - } - - result.put(IntentCodec.PRIORITY, intent.priority()); - - if (intent.constraints() != null) { - final ArrayNode jsonConstraints = result.putArray(CONSTRAINTS); - - if (intent.constraints() != null) { - final JsonCodec<Constraint> constraintCodec = - context.codec(Constraint.class); - for (final Constraint constraint : intent.constraints()) { - final ObjectNode constraintNode = - constraintCodec.encode(constraint, context); - jsonConstraints.add(constraintNode); - } - } - } - - return result; - } - - /** - * Extracts connectivity intent specific attributes from a JSON object - * and adds them to a builder. - * - * @param json root JSON object - * @param context code context - * @param builder builder to use for storing the attributes. Constraints, - * selector and treatment are modified by this call. - */ - public static void intentAttributes(ObjectNode json, CodecContext context, - ConnectivityIntent.Builder builder) { - JsonNode constraintsJson = json.get(CONSTRAINTS); - if (constraintsJson != null) { - JsonCodec<Constraint> constraintsCodec = context.codec(Constraint.class); - ArrayList<Constraint> constraints = new ArrayList<>(constraintsJson.size()); - IntStream.range(0, constraintsJson.size()) - .forEach(i -> constraints.add( - constraintsCodec.decode(get(constraintsJson, i), - context))); - builder.constraints(constraints); - } - - ObjectNode selectorJson = get(json, SELECTOR); - if (selectorJson != null) { - JsonCodec<TrafficSelector> selectorCodec = context.codec(TrafficSelector.class); - TrafficSelector selector = selectorCodec.decode(selectorJson, context); - builder.selector(selector); - } - - ObjectNode treatmentJson = get(json, TREATMENT); - if (treatmentJson != null) { - JsonCodec<TrafficTreatment> treatmentCodec = context.codec(TrafficTreatment.class); - TrafficTreatment treatment = treatmentCodec.decode(treatmentJson, context); - builder.treatment(treatment); - } - } -} diff --git a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/ConstraintCodec.java b/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/ConstraintCodec.java deleted file mode 100644 index 50738341..00000000 --- a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/ConstraintCodec.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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.codec.impl; - -import org.onosproject.codec.CodecContext; -import org.onosproject.codec.JsonCodec; -import org.onosproject.net.intent.Constraint; - -import com.fasterxml.jackson.databind.node.ObjectNode; - -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * Constraint JSON codec. - */ -public final class ConstraintCodec extends JsonCodec<Constraint> { - - protected static final String MISSING_MEMBER_MESSAGE = - " member is required in Constraint"; - protected static final String TYPE = "type"; - protected static final String TYPES = "types"; - protected static final String INCLUSIVE = "inclusive"; - protected static final String KEY = "key"; - protected static final String THRESHOLD = "threshold"; - protected static final String BANDWIDTH = "bandwidth"; - protected static final String LAMBDA = "lambda"; - protected static final String LATENCY_MILLIS = "latencyMillis"; - protected static final String OBSTACLES = "obstacles"; - protected static final String WAYPOINTS = "waypoints"; - - @Override - public ObjectNode encode(Constraint constraint, CodecContext context) { - checkNotNull(constraint, "Constraint cannot be null"); - - final EncodeConstraintCodecHelper encodeCodec = - new EncodeConstraintCodecHelper(constraint, context); - - return encodeCodec.encode(); - } - - @Override - public Constraint decode(ObjectNode json, CodecContext context) { - checkNotNull(json, "JSON cannot be null"); - - final DecodeConstraintCodecHelper decodeCodec = - new DecodeConstraintCodecHelper(json); - - return decodeCodec.decode(); - } -} diff --git a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/ControllerNodeCodec.java b/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/ControllerNodeCodec.java deleted file mode 100644 index 65d758ee..00000000 --- a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/ControllerNodeCodec.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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.codec.impl; - -import com.fasterxml.jackson.databind.node.ObjectNode; -import org.onlab.packet.IpAddress; -import org.onosproject.cluster.ClusterService; -import org.onosproject.cluster.ControllerNode; -import org.onosproject.cluster.DefaultControllerNode; -import org.onosproject.cluster.NodeId; -import org.onosproject.codec.CodecContext; -import org.onosproject.codec.JsonCodec; - -import static com.google.common.base.Preconditions.checkNotNull; -import static org.onosproject.cluster.DefaultControllerNode.DEFAULT_PORT; - -/** - * Device JSON codec. - */ -public final class ControllerNodeCodec extends JsonCodec<ControllerNode> { - - @Override - public ObjectNode encode(ControllerNode node, CodecContext context) { - checkNotNull(node, "Controller node cannot be null"); - ClusterService service = context.getService(ClusterService.class); - return context.mapper().createObjectNode() - .put("id", node.id().toString()) - .put("ip", node.ip().toString()) - .put("tcpPort", node.tcpPort()) - .put("status", service.getState(node.id()).toString()); - } - - - @Override - public ControllerNode decode(ObjectNode json, CodecContext context) { - checkNotNull(json, "JSON cannot be null"); - String ip = json.path("ip").asText(); - return new DefaultControllerNode(new NodeId(json.path("id").asText(ip)), - IpAddress.valueOf(ip), - json.path("tcpPort").asInt(DEFAULT_PORT)); - } - - -} diff --git a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/CriterionCodec.java b/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/CriterionCodec.java deleted file mode 100644 index 975503bb..00000000 --- a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/CriterionCodec.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * 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.codec.impl; - -import org.onosproject.codec.CodecContext; -import org.onosproject.codec.JsonCodec; -import org.onosproject.net.flow.criteria.Criterion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.fasterxml.jackson.databind.node.ObjectNode; - -/** - * Criterion codec. - */ -public final class CriterionCodec extends JsonCodec<Criterion> { - - protected static final Logger log = - LoggerFactory.getLogger(CriterionCodec.class); - - protected static final String TYPE = "type"; - protected static final String ETH_TYPE = "ethType"; - protected static final String MAC = "mac"; - protected static final String PORT = "port"; - protected static final String METADATA = "metadata"; - - protected static final String VLAN_ID = "vlanId"; - protected static final String PRIORITY = "priority"; - protected static final String IP_DSCP = "ipDscp"; - protected static final String IP_ECN = "ipEcn"; - protected static final String PROTOCOL = "protocol"; - protected static final String IP = "ip"; - protected static final String TCP_PORT = "tcpPort"; - protected static final String UDP_PORT = "udpPort"; - protected static final String SCTP_PORT = "sctpPort"; - protected static final String ICMP_TYPE = "icmpType"; - protected static final String ICMP_CODE = "icmpCode"; - protected static final String FLOW_LABEL = "flowLabel"; - protected static final String ICMPV6_TYPE = "icmpv6Type"; - protected static final String ICMPV6_CODE = "icmpv6Code"; - protected static final String TARGET_ADDRESS = "targetAddress"; - protected static final String LABEL = "label"; - protected static final String EXT_HDR_FLAGS = "exthdrFlags"; - protected static final String LAMBDA = "lambda"; - protected static final String GRID_TYPE = "gridType"; - protected static final String CHANNEL_SPACING = "channelSpacing"; - protected static final String SPACING_MULIPLIER = "spacingMultiplier"; - protected static final String SLOT_GRANULARITY = "slotGranularity"; - protected static final String OCH_SIGNAL_ID = "ochSignalId"; - protected static final String TUNNEL_ID = "tunnelId"; - protected static final String OCH_SIGNAL_TYPE = "ochSignalType"; - protected static final String ODU_SIGNAL_ID = "oduSignalId"; - protected static final String TRIBUTARY_PORT_NUMBER = "tributaryPortNumber"; - protected static final String TRIBUTARY_SLOT_LEN = "tributarySlotLen"; - protected static final String TRIBUTARY_SLOT_BITMAP = "tributarySlotBitmap"; - protected static final String ODU_SIGNAL_TYPE = "oduSignalType"; - - @Override - public ObjectNode encode(Criterion criterion, CodecContext context) { - EncodeCriterionCodecHelper encoder = new EncodeCriterionCodecHelper(criterion, context); - return encoder.encode(); - } - - @Override - public Criterion decode(ObjectNode json, CodecContext context) { - DecodeCriterionCodecHelper decoder = new DecodeCriterionCodecHelper(json); - return decoder.decode(); - } -} diff --git a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/DecodeConstraintCodecHelper.java b/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/DecodeConstraintCodecHelper.java deleted file mode 100644 index 40c553d9..00000000 --- a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/DecodeConstraintCodecHelper.java +++ /dev/null @@ -1,223 +0,0 @@ -/* - * 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.codec.impl; - -import java.time.Duration; -import java.util.ArrayList; -import java.util.stream.IntStream; - -import org.onlab.util.Bandwidth; -import org.onosproject.net.DeviceId; -import org.onosproject.net.IndexedLambda; -import org.onosproject.net.Link; -import org.onosproject.net.intent.Constraint; -import org.onosproject.net.intent.constraint.AnnotationConstraint; -import org.onosproject.net.intent.constraint.AsymmetricPathConstraint; -import org.onosproject.net.intent.constraint.BandwidthConstraint; -import org.onosproject.net.intent.constraint.LambdaConstraint; -import org.onosproject.net.intent.constraint.LatencyConstraint; -import org.onosproject.net.intent.constraint.LinkTypeConstraint; -import org.onosproject.net.intent.constraint.ObstacleConstraint; -import org.onosproject.net.intent.constraint.WaypointConstraint; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.node.ObjectNode; - -import static org.onlab.util.Tools.nullIsIllegal; - -/** - * Constraint JSON decoder. - */ -public final class DecodeConstraintCodecHelper { - private final ObjectNode json; - - /** - * Constructs a constraint decoder. - * - * @param json object node to decode - */ - public DecodeConstraintCodecHelper(ObjectNode json) { - this.json = json; - } - - /** - * Decodes a link type constraint. - * - * @return link type constraint object. - */ - private Constraint decodeLinkTypeConstraint() { - boolean inclusive = nullIsIllegal(json.get(ConstraintCodec.INCLUSIVE), - ConstraintCodec.INCLUSIVE + ConstraintCodec.MISSING_MEMBER_MESSAGE).asBoolean(); - - JsonNode types = nullIsIllegal(json.get(ConstraintCodec.TYPES), - ConstraintCodec.TYPES + ConstraintCodec.MISSING_MEMBER_MESSAGE); - if (types.size() < 1) { - throw new IllegalArgumentException( - "types array in link constraint must have at least one value"); - } - - ArrayList<Link.Type> typesEntries = new ArrayList<>(types.size()); - IntStream.range(0, types.size()) - .forEach(index -> - typesEntries.add(Link.Type.valueOf(types.get(index).asText()))); - - return new LinkTypeConstraint(inclusive, - typesEntries.toArray(new Link.Type[types.size()])); - } - - /** - * Decodes an annotation constraint. - * - * @return annotation constraint object. - */ - private Constraint decodeAnnotationConstraint() { - String key = nullIsIllegal(json.get(ConstraintCodec.KEY), - ConstraintCodec.KEY + ConstraintCodec.MISSING_MEMBER_MESSAGE) - .asText(); - double threshold = nullIsIllegal(json.get(ConstraintCodec.THRESHOLD), - ConstraintCodec.THRESHOLD + ConstraintCodec.MISSING_MEMBER_MESSAGE) - .asDouble(); - - return new AnnotationConstraint(key, threshold); - } - - /** - * Decodes a lambda constraint. - * - * @return lambda constraint object. - */ - private Constraint decodeLambdaConstraint() { - long lambda = nullIsIllegal(json.get(ConstraintCodec.LAMBDA), - ConstraintCodec.LAMBDA + ConstraintCodec.MISSING_MEMBER_MESSAGE) - .asLong(); - - return new LambdaConstraint(new IndexedLambda(lambda)); - } - - /** - * Decodes a latency constraint. - * - * @return latency constraint object. - */ - private Constraint decodeLatencyConstraint() { - long latencyMillis = nullIsIllegal(json.get(ConstraintCodec.LATENCY_MILLIS), - ConstraintCodec.LATENCY_MILLIS + ConstraintCodec.MISSING_MEMBER_MESSAGE) - .asLong(); - - return new LatencyConstraint(Duration.ofMillis(latencyMillis)); - } - - /** - * Decodes an obstacle constraint. - * - * @return obstacle constraint object. - */ - private Constraint decodeObstacleConstraint() { - JsonNode obstacles = nullIsIllegal(json.get(ConstraintCodec.OBSTACLES), - ConstraintCodec.OBSTACLES + ConstraintCodec.MISSING_MEMBER_MESSAGE); - if (obstacles.size() < 1) { - throw new IllegalArgumentException( - "obstacles array in obstacles constraint must have at least one value"); - } - - ArrayList<DeviceId> obstacleEntries = new ArrayList<>(obstacles.size()); - IntStream.range(0, obstacles.size()) - .forEach(index -> - obstacleEntries.add(DeviceId.deviceId(obstacles.get(index).asText()))); - - return new ObstacleConstraint( - obstacleEntries.toArray(new DeviceId[obstacles.size()])); - } - - /** - * Decodes a waypoint constraint. - * - * @return waypoint constraint object. - */ - private Constraint decodeWaypointConstraint() { - JsonNode waypoints = nullIsIllegal(json.get(ConstraintCodec.WAYPOINTS), - ConstraintCodec.WAYPOINTS + ConstraintCodec.MISSING_MEMBER_MESSAGE); - if (waypoints.size() < 1) { - throw new IllegalArgumentException( - "obstacles array in obstacles constraint must have at least one value"); - } - - ArrayList<DeviceId> waypointEntries = new ArrayList<>(waypoints.size()); - IntStream.range(0, waypoints.size()) - .forEach(index -> - waypointEntries.add(DeviceId.deviceId(waypoints.get(index).asText()))); - - return new WaypointConstraint( - waypointEntries.toArray(new DeviceId[waypoints.size()])); - } - - /** - * Decodes an asymmetric path constraint. - * - * @return asymmetric path constraint object. - */ - private Constraint decodeAsymmetricPathConstraint() { - return new AsymmetricPathConstraint(); - } - - /** - * Decodes a bandwidth constraint. - * - * @return bandwidth constraint object. - */ - private Constraint decodeBandwidthConstraint() { - double bandwidth = nullIsIllegal(json.get(ConstraintCodec.BANDWIDTH), - ConstraintCodec.BANDWIDTH + ConstraintCodec.MISSING_MEMBER_MESSAGE) - .asDouble(); - - return new BandwidthConstraint(Bandwidth.bps(bandwidth)); - } - - /** - * Decodes the given constraint. - * - * @return constraint object. - */ - public Constraint decode() { - final String type = nullIsIllegal(json.get(ConstraintCodec.TYPE), - ConstraintCodec.TYPE + ConstraintCodec.MISSING_MEMBER_MESSAGE) - .asText(); - - if (type.equals(BandwidthConstraint.class.getSimpleName())) { - return decodeBandwidthConstraint(); - } else if (type.equals(LambdaConstraint.class.getSimpleName())) { - return decodeLambdaConstraint(); - } else if (type.equals(LinkTypeConstraint.class.getSimpleName())) { - return decodeLinkTypeConstraint(); - } else if (type.equals(AnnotationConstraint.class.getSimpleName())) { - return decodeAnnotationConstraint(); - } else if (type.equals(LatencyConstraint.class.getSimpleName())) { - return decodeLatencyConstraint(); - } else if (type.equals(ObstacleConstraint.class.getSimpleName())) { - return decodeObstacleConstraint(); - } else if (type.equals(WaypointConstraint.class.getSimpleName())) { - return decodeWaypointConstraint(); - } else if (type.equals(AsymmetricPathConstraint.class.getSimpleName())) { - return decodeAsymmetricPathConstraint(); - } else if (type.equals(LinkTypeConstraint.class.getSimpleName())) { - return decodeLinkTypeConstraint(); - } else if (type.equals(AnnotationConstraint.class.getSimpleName())) { - return decodeAnnotationConstraint(); - } - throw new IllegalArgumentException("Instruction type " - + type + " is not supported"); - } -} diff --git a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/DecodeCriterionCodecHelper.java b/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/DecodeCriterionCodecHelper.java deleted file mode 100644 index 88cc3328..00000000 --- a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/DecodeCriterionCodecHelper.java +++ /dev/null @@ -1,488 +0,0 @@ -/* - * 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.codec.impl; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.node.ObjectNode; -import org.onlab.packet.Ip6Address; -import org.onlab.packet.IpPrefix; -import org.onlab.packet.MacAddress; -import org.onlab.packet.MplsLabel; -import org.onlab.packet.TpPort; -import org.onlab.packet.VlanId; -import org.onlab.util.HexString; -import org.onosproject.net.ChannelSpacing; -import org.onosproject.net.GridType; -import org.onosproject.net.Lambda; -import org.onosproject.net.OchSignalType; -import org.onosproject.net.OduSignalId; -import org.onosproject.net.OduSignalType; -import org.onosproject.net.PortNumber; -import org.onosproject.net.flow.criteria.Criteria; -import org.onosproject.net.flow.criteria.Criterion; - -import java.util.HashMap; -import java.util.Map; - -import static org.onlab.util.Tools.nullIsIllegal; - -/** - * Decode portion of the criterion codec. - */ -public final class DecodeCriterionCodecHelper { - - private final ObjectNode json; - - protected static final String MISSING_MEMBER_MESSAGE = - " member is required in Criterion"; - - private interface CriterionDecoder { - Criterion decodeCriterion(ObjectNode json); - } - private final Map<String, CriterionDecoder> decoderMap; - - /** - * Creates a decode criterion codec object. - * Initializes the lookup map for criterion subclass decoders. - * - * @param json JSON object to decode - */ - public DecodeCriterionCodecHelper(ObjectNode json) { - this.json = json; - decoderMap = new HashMap<>(); - - decoderMap.put(Criterion.Type.IN_PORT.name(), new InPortDecoder()); - decoderMap.put(Criterion.Type.IN_PHY_PORT.name(), new InPhyPortDecoder()); - decoderMap.put(Criterion.Type.METADATA.name(), new MetadataDecoder()); - decoderMap.put(Criterion.Type.ETH_DST.name(), new EthDstDecoder()); - decoderMap.put(Criterion.Type.ETH_SRC.name(), new EthSrcDecoder()); - decoderMap.put(Criterion.Type.ETH_TYPE.name(), new EthTypeDecoder()); - decoderMap.put(Criterion.Type.VLAN_VID.name(), new VlanVidDecoder()); - decoderMap.put(Criterion.Type.VLAN_PCP.name(), new VlanPcpDecoder()); - decoderMap.put(Criterion.Type.IP_DSCP.name(), new IpDscpDecoder()); - decoderMap.put(Criterion.Type.IP_ECN.name(), new IpEcnDecoder()); - decoderMap.put(Criterion.Type.IP_PROTO.name(), new IpProtoDecoder()); - decoderMap.put(Criterion.Type.IPV4_SRC.name(), new IpV4SrcDecoder()); - decoderMap.put(Criterion.Type.IPV4_DST.name(), new IpV4DstDecoder()); - decoderMap.put(Criterion.Type.TCP_SRC.name(), new TcpSrcDecoder()); - decoderMap.put(Criterion.Type.TCP_DST.name(), new TcpDstDecoder()); - decoderMap.put(Criterion.Type.UDP_SRC.name(), new UdpSrcDecoder()); - decoderMap.put(Criterion.Type.UDP_DST.name(), new UdpDstDecoder()); - decoderMap.put(Criterion.Type.SCTP_SRC.name(), new SctpSrcDecoder()); - decoderMap.put(Criterion.Type.SCTP_DST.name(), new SctpDstDecoder()); - decoderMap.put(Criterion.Type.ICMPV4_TYPE.name(), new IcmpV4TypeDecoder()); - decoderMap.put(Criterion.Type.ICMPV4_CODE.name(), new IcmpV4CodeDecoder()); - decoderMap.put(Criterion.Type.IPV6_SRC.name(), new IpV6SrcDecoder()); - decoderMap.put(Criterion.Type.IPV6_DST.name(), new IpV6DstDecoder()); - decoderMap.put(Criterion.Type.IPV6_FLABEL.name(), new IpV6FLabelDecoder()); - decoderMap.put(Criterion.Type.ICMPV6_TYPE.name(), new IcmpV6TypeDecoder()); - decoderMap.put(Criterion.Type.ICMPV6_CODE.name(), new IcmpV6CodeDecoder()); - decoderMap.put(Criterion.Type.IPV6_ND_TARGET.name(), new V6NDTargetDecoder()); - decoderMap.put(Criterion.Type.IPV6_ND_SLL.name(), new V6NDSllDecoder()); - decoderMap.put(Criterion.Type.IPV6_ND_TLL.name(), new V6NDTllDecoder()); - decoderMap.put(Criterion.Type.MPLS_LABEL.name(), new MplsLabelDecoder()); - decoderMap.put(Criterion.Type.IPV6_EXTHDR.name(), new IpV6ExthdrDecoder()); - decoderMap.put(Criterion.Type.OCH_SIGID.name(), new OchSigIdDecoder()); - decoderMap.put(Criterion.Type.OCH_SIGTYPE.name(), new OchSigTypeDecoder()); - decoderMap.put(Criterion.Type.TUNNEL_ID.name(), new TunnelIdDecoder()); - decoderMap.put(Criterion.Type.ODU_SIGID.name(), new OduSigIdDecoder()); - decoderMap.put(Criterion.Type.ODU_SIGTYPE.name(), new OduSigTypeDecoder()); - } - - private class EthTypeDecoder implements CriterionDecoder { - @Override - public Criterion decodeCriterion(ObjectNode json) { - int ethType; - if (json.get(CriterionCodec.ETH_TYPE).isInt()) { - ethType = nullIsIllegal(json.get(CriterionCodec.ETH_TYPE), - CriterionCodec.ETH_TYPE + MISSING_MEMBER_MESSAGE).asInt(); - } else { - ethType = Integer.decode(json.get(CriterionCodec.ETH_TYPE).textValue()); - } - return Criteria.matchEthType(ethType); - } - } - private class EthDstDecoder implements CriterionDecoder { - @Override - public Criterion decodeCriterion(ObjectNode json) { - MacAddress mac = MacAddress.valueOf(nullIsIllegal(json.get(CriterionCodec.MAC), - CriterionCodec.MAC + MISSING_MEMBER_MESSAGE).asText()); - - return Criteria.matchEthDst(mac); - } - } - - private class EthSrcDecoder implements CriterionDecoder { - @Override - public Criterion decodeCriterion(ObjectNode json) { - MacAddress mac = MacAddress.valueOf(nullIsIllegal(json.get(CriterionCodec.MAC), - CriterionCodec.MAC + MISSING_MEMBER_MESSAGE).asText()); - - return Criteria.matchEthSrc(mac); - } - } - - private class InPortDecoder implements CriterionDecoder { - @Override - public Criterion decodeCriterion(ObjectNode json) { - PortNumber port = PortNumber.portNumber(nullIsIllegal(json.get(CriterionCodec.PORT), - CriterionCodec.PORT + MISSING_MEMBER_MESSAGE).asLong()); - - return Criteria.matchInPort(port); - } - } - - private class InPhyPortDecoder implements CriterionDecoder { - @Override - public Criterion decodeCriterion(ObjectNode json) { - PortNumber port = PortNumber.portNumber(nullIsIllegal(json.get(CriterionCodec.PORT), - CriterionCodec.PORT + MISSING_MEMBER_MESSAGE).asLong()); - - return Criteria.matchInPhyPort(port); - } - } - - private class MetadataDecoder implements CriterionDecoder { - @Override - public Criterion decodeCriterion(ObjectNode json) { - long metadata = nullIsIllegal(json.get(CriterionCodec.METADATA), - CriterionCodec.METADATA + MISSING_MEMBER_MESSAGE).asLong(); - - return Criteria.matchMetadata(metadata); - } - } - - private class VlanVidDecoder implements CriterionDecoder { - @Override - public Criterion decodeCriterion(ObjectNode json) { - short vlanId = (short) nullIsIllegal(json.get(CriterionCodec.VLAN_ID), - CriterionCodec.VLAN_ID + MISSING_MEMBER_MESSAGE).asInt(); - - return Criteria.matchVlanId(VlanId.vlanId(vlanId)); - } - } - - private class VlanPcpDecoder implements CriterionDecoder { - @Override - public Criterion decodeCriterion(ObjectNode json) { - byte priority = (byte) nullIsIllegal(json.get(CriterionCodec.PRIORITY), - CriterionCodec.VLAN_ID + MISSING_MEMBER_MESSAGE).asInt(); - - return Criteria.matchVlanPcp(priority); - } - } - - private class IpDscpDecoder implements CriterionDecoder { - @Override - public Criterion decodeCriterion(ObjectNode json) { - byte ipDscp = (byte) nullIsIllegal(json.get(CriterionCodec.IP_DSCP), - CriterionCodec.IP_DSCP + MISSING_MEMBER_MESSAGE).asInt(); - return Criteria.matchIPDscp(ipDscp); - } - } - - private class IpEcnDecoder implements CriterionDecoder { - @Override - public Criterion decodeCriterion(ObjectNode json) { - byte ipEcn = (byte) nullIsIllegal(json.get(CriterionCodec.IP_ECN), - CriterionCodec.IP_ECN + MISSING_MEMBER_MESSAGE).asInt(); - return Criteria.matchIPEcn(ipEcn); - } - } - - private class IpProtoDecoder implements CriterionDecoder { - @Override - public Criterion decodeCriterion(ObjectNode json) { - short proto = (short) nullIsIllegal(json.get(CriterionCodec.PROTOCOL), - CriterionCodec.PROTOCOL + MISSING_MEMBER_MESSAGE).asInt(); - return Criteria.matchIPProtocol(proto); - } - } - - private class IpV4SrcDecoder implements CriterionDecoder { - @Override - public Criterion decodeCriterion(ObjectNode json) { - String ip = nullIsIllegal(json.get(CriterionCodec.IP), - CriterionCodec.IP + MISSING_MEMBER_MESSAGE).asText(); - return Criteria.matchIPSrc(IpPrefix.valueOf(ip)); - } - } - - private class IpV4DstDecoder implements CriterionDecoder { - @Override - public Criterion decodeCriterion(ObjectNode json) { - String ip = nullIsIllegal(json.get(CriterionCodec.IP), - CriterionCodec.IP + MISSING_MEMBER_MESSAGE).asText(); - return Criteria.matchIPDst(IpPrefix.valueOf(ip)); - } - } - - private class IpV6SrcDecoder implements CriterionDecoder { - @Override - public Criterion decodeCriterion(ObjectNode json) { - String ip = nullIsIllegal(json.get(CriterionCodec.IP), - CriterionCodec.IP + MISSING_MEMBER_MESSAGE).asText(); - return Criteria.matchIPv6Src(IpPrefix.valueOf(ip)); - } - } - - private class IpV6DstDecoder implements CriterionDecoder { - @Override - public Criterion decodeCriterion(ObjectNode json) { - String ip = nullIsIllegal(json.get(CriterionCodec.IP), - CriterionCodec.IP + MISSING_MEMBER_MESSAGE).asText(); - return Criteria.matchIPv6Dst(IpPrefix.valueOf(ip)); - } - } - - private class TcpSrcDecoder implements CriterionDecoder { - @Override - public Criterion decodeCriterion(ObjectNode json) { - TpPort tcpPort = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.TCP_PORT), - CriterionCodec.TCP_PORT + MISSING_MEMBER_MESSAGE).asInt()); - return Criteria.matchTcpSrc(tcpPort); - } - } - - private class TcpDstDecoder implements CriterionDecoder { - @Override - public Criterion decodeCriterion(ObjectNode json) { - TpPort tcpPort = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.TCP_PORT), - CriterionCodec.TCP_PORT + MISSING_MEMBER_MESSAGE).asInt()); - return Criteria.matchTcpDst(tcpPort); - } - } - - private class UdpSrcDecoder implements CriterionDecoder { - @Override - public Criterion decodeCriterion(ObjectNode json) { - TpPort udpPort = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.UDP_PORT), - CriterionCodec.UDP_PORT + MISSING_MEMBER_MESSAGE).asInt()); - return Criteria.matchUdpSrc(udpPort); - } - } - - private class UdpDstDecoder implements CriterionDecoder { - @Override - public Criterion decodeCriterion(ObjectNode json) { - TpPort udpPort = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.UDP_PORT), - CriterionCodec.UDP_PORT + MISSING_MEMBER_MESSAGE).asInt()); - return Criteria.matchUdpDst(udpPort); - } - } - - private class SctpSrcDecoder implements CriterionDecoder { - @Override - public Criterion decodeCriterion(ObjectNode json) { - TpPort sctpPort = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.SCTP_PORT), - CriterionCodec.SCTP_PORT + MISSING_MEMBER_MESSAGE).asInt()); - return Criteria.matchSctpSrc(sctpPort); - } - } - - private class SctpDstDecoder implements CriterionDecoder { - @Override - public Criterion decodeCriterion(ObjectNode json) { - TpPort sctpPort = TpPort.tpPort(nullIsIllegal(json.get(CriterionCodec.SCTP_PORT), - CriterionCodec.SCTP_PORT + MISSING_MEMBER_MESSAGE).asInt()); - return Criteria.matchSctpDst(sctpPort); - } - } - - private class IcmpV4TypeDecoder implements CriterionDecoder { - @Override - public Criterion decodeCriterion(ObjectNode json) { - short type = (short) nullIsIllegal(json.get(CriterionCodec.ICMP_TYPE), - CriterionCodec.ICMP_TYPE + MISSING_MEMBER_MESSAGE).asInt(); - return Criteria.matchIcmpType(type); - } - } - - private class IcmpV4CodeDecoder implements CriterionDecoder { - @Override - public Criterion decodeCriterion(ObjectNode json) { - short code = (short) nullIsIllegal(json.get(CriterionCodec.ICMP_CODE), - CriterionCodec.ICMP_CODE + MISSING_MEMBER_MESSAGE).asInt(); - return Criteria.matchIcmpCode(code); - } - } - - private class IpV6FLabelDecoder implements CriterionDecoder { - @Override - public Criterion decodeCriterion(ObjectNode json) { - int flowLabel = nullIsIllegal(json.get(CriterionCodec.FLOW_LABEL), - CriterionCodec.FLOW_LABEL + MISSING_MEMBER_MESSAGE).asInt(); - return Criteria.matchIPv6FlowLabel(flowLabel); - } - } - - private class IcmpV6TypeDecoder implements CriterionDecoder { - @Override - public Criterion decodeCriterion(ObjectNode json) { - short type = (short) nullIsIllegal(json.get(CriterionCodec.ICMPV6_TYPE), - CriterionCodec.ICMPV6_TYPE + MISSING_MEMBER_MESSAGE).asInt(); - return Criteria.matchIcmpv6Type(type); - } - } - - private class IcmpV6CodeDecoder implements CriterionDecoder { - @Override - public Criterion decodeCriterion(ObjectNode json) { - short code = (short) nullIsIllegal(json.get(CriterionCodec.ICMPV6_CODE), - CriterionCodec.ICMPV6_CODE + MISSING_MEMBER_MESSAGE).asInt(); - return Criteria.matchIcmpv6Code(code); - } - } - - private class V6NDTargetDecoder implements CriterionDecoder { - @Override - public Criterion decodeCriterion(ObjectNode json) { - Ip6Address target = Ip6Address.valueOf(nullIsIllegal(json.get(CriterionCodec.TARGET_ADDRESS), - CriterionCodec.TARGET_ADDRESS + MISSING_MEMBER_MESSAGE).asText()); - return Criteria.matchIPv6NDTargetAddress(target); - } - } - - private class V6NDSllDecoder implements CriterionDecoder { - @Override - public Criterion decodeCriterion(ObjectNode json) { - MacAddress mac = MacAddress.valueOf(nullIsIllegal(json.get(CriterionCodec.MAC), - CriterionCodec.MAC + MISSING_MEMBER_MESSAGE).asText()); - return Criteria.matchIPv6NDSourceLinkLayerAddress(mac); - } - } - - private class V6NDTllDecoder implements CriterionDecoder { - @Override - public Criterion decodeCriterion(ObjectNode json) { - MacAddress mac = MacAddress.valueOf(nullIsIllegal(json.get(CriterionCodec.MAC), - CriterionCodec.MAC + MISSING_MEMBER_MESSAGE).asText()); - return Criteria.matchIPv6NDTargetLinkLayerAddress(mac); - } - } - - private class MplsLabelDecoder implements CriterionDecoder { - @Override - public Criterion decodeCriterion(ObjectNode json) { - int label = nullIsIllegal(json.get(CriterionCodec.LABEL), - CriterionCodec.LABEL + MISSING_MEMBER_MESSAGE).asInt(); - return Criteria.matchMplsLabel(MplsLabel.mplsLabel(label)); - } - } - - private class IpV6ExthdrDecoder implements CriterionDecoder { - @Override - public Criterion decodeCriterion(ObjectNode json) { - int exthdrFlags = nullIsIllegal(json.get(CriterionCodec.EXT_HDR_FLAGS), - CriterionCodec.EXT_HDR_FLAGS + MISSING_MEMBER_MESSAGE).asInt(); - return Criteria.matchIPv6ExthdrFlags(exthdrFlags); - } - } - - private class OchSigIdDecoder implements CriterionDecoder { - @Override - public Criterion decodeCriterion(ObjectNode json) { - if (json.get(CriterionCodec.LAMBDA) != null) { - Lambda lambda = Lambda.indexedLambda(nullIsIllegal(json.get(CriterionCodec.LAMBDA), - CriterionCodec.LAMBDA + MISSING_MEMBER_MESSAGE).asInt()); - return Criteria.matchLambda(lambda); - } else { - JsonNode ochSignalId = nullIsIllegal(json.get(CriterionCodec.OCH_SIGNAL_ID), - CriterionCodec.GRID_TYPE + MISSING_MEMBER_MESSAGE); - GridType gridType = - GridType.valueOf( - nullIsIllegal(ochSignalId.get(CriterionCodec.GRID_TYPE), - CriterionCodec.GRID_TYPE + MISSING_MEMBER_MESSAGE).asText()); - ChannelSpacing channelSpacing = - ChannelSpacing.valueOf( - nullIsIllegal(ochSignalId.get(CriterionCodec.CHANNEL_SPACING), - CriterionCodec.CHANNEL_SPACING + MISSING_MEMBER_MESSAGE).asText()); - int spacingMultiplier = nullIsIllegal(ochSignalId.get(CriterionCodec.SPACING_MULIPLIER), - CriterionCodec.SPACING_MULIPLIER + MISSING_MEMBER_MESSAGE).asInt(); - int slotGranularity = nullIsIllegal(ochSignalId.get(CriterionCodec.SLOT_GRANULARITY), - CriterionCodec.SLOT_GRANULARITY + MISSING_MEMBER_MESSAGE).asInt(); - return Criteria.matchLambda( - Lambda.ochSignal(gridType, channelSpacing, - spacingMultiplier, slotGranularity)); - } - } - } - - private class OchSigTypeDecoder implements CriterionDecoder { - @Override - public Criterion decodeCriterion(ObjectNode json) { - OchSignalType ochSignalType = OchSignalType.valueOf(nullIsIllegal(json.get(CriterionCodec.OCH_SIGNAL_TYPE), - CriterionCodec.OCH_SIGNAL_TYPE + MISSING_MEMBER_MESSAGE).asText()); - return Criteria.matchOchSignalType(ochSignalType); - } - } - - private class TunnelIdDecoder implements CriterionDecoder { - @Override - public Criterion decodeCriterion(ObjectNode json) { - long tunnelId = nullIsIllegal(json.get(CriterionCodec.TUNNEL_ID), - CriterionCodec.TUNNEL_ID + MISSING_MEMBER_MESSAGE).asLong(); - return Criteria.matchTunnelId(tunnelId); - } - } - - private class OduSigIdDecoder implements CriterionDecoder { - @Override - public Criterion decodeCriterion(ObjectNode json) { - JsonNode oduSignalId = nullIsIllegal(json.get(CriterionCodec.ODU_SIGNAL_ID), - CriterionCodec.TRIBUTARY_PORT_NUMBER + MISSING_MEMBER_MESSAGE); - - int tributaryPortNumber = nullIsIllegal(oduSignalId.get(CriterionCodec.TRIBUTARY_PORT_NUMBER), - CriterionCodec.TRIBUTARY_PORT_NUMBER + MISSING_MEMBER_MESSAGE).asInt(); - int tributarySlotLen = nullIsIllegal(oduSignalId.get(CriterionCodec.TRIBUTARY_SLOT_LEN), - CriterionCodec.TRIBUTARY_SLOT_LEN + MISSING_MEMBER_MESSAGE).asInt(); - byte[] tributarySlotBitmap = HexString.fromHexString( - nullIsIllegal(oduSignalId.get(CriterionCodec.TRIBUTARY_SLOT_BITMAP), - CriterionCodec.TRIBUTARY_SLOT_BITMAP + MISSING_MEMBER_MESSAGE).asText()); - - return Criteria.matchOduSignalId( - OduSignalId.oduSignalId(tributaryPortNumber, tributarySlotLen, tributarySlotBitmap)); - } - } - - private class OduSigTypeDecoder implements CriterionDecoder { - @Override - public Criterion decodeCriterion(ObjectNode json) { - OduSignalType oduSignalType = OduSignalType.valueOf(nullIsIllegal(json.get(CriterionCodec.ODU_SIGNAL_TYPE), - CriterionCodec.ODU_SIGNAL_TYPE + MISSING_MEMBER_MESSAGE).asText()); - return Criteria.matchOduSignalType(oduSignalType); - } - } - - /** - * Decodes the JSON into a criterion object. - * - * @return Criterion object - * @throws IllegalArgumentException if the JSON is invalid - */ - public Criterion decode() { - String type = json.get(CriterionCodec.TYPE).asText(); - - CriterionDecoder decoder = decoderMap.get(type); - if (decoder != null) { - return decoder.decodeCriterion(json); - } - - throw new IllegalArgumentException("Type " + type + " is unknown"); - } - - -} diff --git a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/DecodeInstructionCodecHelper.java b/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/DecodeInstructionCodecHelper.java deleted file mode 100644 index 14555b3d..00000000 --- a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/DecodeInstructionCodecHelper.java +++ /dev/null @@ -1,264 +0,0 @@ -/* - * 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.codec.impl; - -import static org.onlab.util.Tools.nullIsIllegal; - -import org.onlab.packet.IpAddress; -import org.onlab.packet.MacAddress; -import org.onlab.packet.MplsLabel; -import org.onlab.packet.TpPort; -import org.onlab.packet.VlanId; -import org.onlab.util.HexString; -import org.onosproject.net.ChannelSpacing; -import org.onosproject.net.GridType; -import org.onosproject.net.Lambda; -import org.onosproject.net.OchSignal; -import org.onosproject.net.OduSignalId; -import org.onosproject.net.PortNumber; -import org.onosproject.net.flow.instructions.Instruction; -import org.onosproject.net.flow.instructions.Instructions; -import org.onosproject.net.flow.instructions.L0ModificationInstruction; -import org.onosproject.net.flow.instructions.L1ModificationInstruction; -import org.onosproject.net.flow.instructions.L2ModificationInstruction; -import org.onosproject.net.flow.instructions.L3ModificationInstruction; -import org.onosproject.net.flow.instructions.L4ModificationInstruction; - -import com.fasterxml.jackson.databind.node.ObjectNode; - -/** - * Decoding portion of the instruction codec. - */ -public final class DecodeInstructionCodecHelper { - private final ObjectNode json; - - /** - * Creates a decode instruction codec object. - * - * @param json JSON object to decode - */ - public DecodeInstructionCodecHelper(ObjectNode json) { - this.json = json; - } - - /** - * Decodes a Layer 2 instruction. - * - * @return instruction object decoded from the JSON - * @throws IllegalArgumentException if the JSON is invalid - */ - private Instruction decodeL2() { - String subType = json.get(InstructionCodec.SUBTYPE).asText(); - - if (subType.equals(L2ModificationInstruction.L2SubType.ETH_SRC.name())) { - String mac = nullIsIllegal(json.get(InstructionCodec.MAC), - InstructionCodec.MAC + InstructionCodec.MISSING_MEMBER_MESSAGE).asText(); - return Instructions.modL2Src(MacAddress.valueOf(mac)); - } else if (subType.equals(L2ModificationInstruction.L2SubType.ETH_DST.name())) { - String mac = nullIsIllegal(json.get(InstructionCodec.MAC), - InstructionCodec.MAC + InstructionCodec.MISSING_MEMBER_MESSAGE).asText(); - return Instructions.modL2Dst(MacAddress.valueOf(mac)); - } else if (subType.equals(L2ModificationInstruction.L2SubType.VLAN_ID.name())) { - short vlanId = (short) nullIsIllegal(json.get(InstructionCodec.VLAN_ID), - InstructionCodec.VLAN_ID + InstructionCodec.MISSING_MEMBER_MESSAGE).asInt(); - return Instructions.modVlanId(VlanId.vlanId(vlanId)); - } else if (subType.equals(L2ModificationInstruction.L2SubType.VLAN_PCP.name())) { - byte vlanPcp = (byte) nullIsIllegal(json.get(InstructionCodec.VLAN_PCP), - InstructionCodec.VLAN_PCP + InstructionCodec.MISSING_MEMBER_MESSAGE).asInt(); - return Instructions.modVlanPcp(vlanPcp); - } else if (subType.equals(L2ModificationInstruction.L2SubType.MPLS_LABEL.name())) { - int label = nullIsIllegal(json.get(InstructionCodec.MPLS_LABEL), - InstructionCodec.MPLS_LABEL + InstructionCodec.MISSING_MEMBER_MESSAGE).asInt(); - return Instructions.modMplsLabel(MplsLabel.mplsLabel(label)); - } else if (subType.equals(L2ModificationInstruction.L2SubType.MPLS_PUSH.name())) { - return Instructions.pushMpls(); - } else if (subType.equals(L2ModificationInstruction.L2SubType.MPLS_POP.name())) { - return Instructions.popMpls(); - } else if (subType.equals(L2ModificationInstruction.L2SubType.DEC_MPLS_TTL.name())) { - return Instructions.decMplsTtl(); - } else if (subType.equals(L2ModificationInstruction.L2SubType.VLAN_POP.name())) { - return Instructions.popVlan(); - } else if (subType.equals(L2ModificationInstruction.L2SubType.VLAN_PUSH.name())) { - return Instructions.pushVlan(); - } else if (subType.equals(L2ModificationInstruction.L2SubType.TUNNEL_ID.name())) { - long tunnelId = nullIsIllegal(json.get(InstructionCodec.TUNNEL_ID), - InstructionCodec.TUNNEL_ID + InstructionCodec.MISSING_MEMBER_MESSAGE).asLong(); - return Instructions.modTunnelId(tunnelId); - } - throw new IllegalArgumentException("L2 Instruction subtype " - + subType + " is not supported"); - } - - /** - * Decodes a Layer 3 instruction. - * - * @return instruction object decoded from the JSON - * @throws IllegalArgumentException if the JSON is invalid - */ - private Instruction decodeL3() { - String subType = json.get(InstructionCodec.SUBTYPE).asText(); - - if (subType.equals(L3ModificationInstruction.L3SubType.IPV4_SRC.name())) { - IpAddress ip = IpAddress.valueOf(nullIsIllegal(json.get(InstructionCodec.IP), - InstructionCodec.IP + InstructionCodec.MISSING_MEMBER_MESSAGE).asText()); - return Instructions.modL3Src(ip); - } else if (subType.equals(L3ModificationInstruction.L3SubType.IPV4_DST.name())) { - IpAddress ip = IpAddress.valueOf(nullIsIllegal(json.get(InstructionCodec.IP), - InstructionCodec.IP + InstructionCodec.MISSING_MEMBER_MESSAGE).asText()); - return Instructions.modL3Dst(ip); - } else if (subType.equals(L3ModificationInstruction.L3SubType.IPV6_SRC.name())) { - IpAddress ip = IpAddress.valueOf(nullIsIllegal(json.get(InstructionCodec.IP), - InstructionCodec.IP + InstructionCodec.MISSING_MEMBER_MESSAGE).asText()); - return Instructions.modL3IPv6Src(ip); - } else if (subType.equals(L3ModificationInstruction.L3SubType.IPV6_DST.name())) { - IpAddress ip = IpAddress.valueOf(nullIsIllegal(json.get(InstructionCodec.IP), - InstructionCodec.IP + InstructionCodec.MISSING_MEMBER_MESSAGE).asText()); - return Instructions.modL3IPv6Dst(ip); - } else if (subType.equals(L3ModificationInstruction.L3SubType.IPV6_FLABEL.name())) { - int flowLabel = nullIsIllegal(json.get(InstructionCodec.FLOW_LABEL), - InstructionCodec.FLOW_LABEL + InstructionCodec.MISSING_MEMBER_MESSAGE).asInt(); - return Instructions.modL3IPv6FlowLabel(flowLabel); - } - throw new IllegalArgumentException("L3 Instruction subtype " - + subType + " is not supported"); - } - - /** - * Decodes a Layer 0 instruction. - * - * @return instruction object decoded from the JSON - * @throws IllegalArgumentException if the JSON is invalid - */ - private Instruction decodeL0() { - String subType = json.get(InstructionCodec.SUBTYPE).asText(); - - - if (subType.equals(L0ModificationInstruction.L0SubType.LAMBDA.name())) { - int lambda = nullIsIllegal(json.get(InstructionCodec.LAMBDA), - InstructionCodec.LAMBDA + InstructionCodec.MISSING_MEMBER_MESSAGE).asInt(); - return Instructions.modL0Lambda(Lambda.indexedLambda(lambda)); - } else if (subType.equals(L0ModificationInstruction.L0SubType.OCH.name())) { - String gridTypeString = nullIsIllegal(json.get(InstructionCodec.GRID_TYPE), - InstructionCodec.GRID_TYPE + InstructionCodec.MISSING_MEMBER_MESSAGE).asText(); - GridType gridType = GridType.valueOf(gridTypeString); - if (gridType == null) { - throw new IllegalArgumentException("Unknown grid type " - + gridTypeString); - } - String channelSpacingString = nullIsIllegal(json.get(InstructionCodec.CHANNEL_SPACING), - InstructionCodec.CHANNEL_SPACING + InstructionCodec.MISSING_MEMBER_MESSAGE).asText(); - ChannelSpacing channelSpacing = ChannelSpacing.valueOf(channelSpacingString); - if (channelSpacing == null) { - throw new IllegalArgumentException("Unknown channel spacing " - + channelSpacingString); - } - int spacingMultiplier = nullIsIllegal(json.get(InstructionCodec.SPACING_MULTIPLIER), - InstructionCodec.SPACING_MULTIPLIER + InstructionCodec.MISSING_MEMBER_MESSAGE).asInt(); - int slotGranularity = nullIsIllegal(json.get(InstructionCodec.SLOT_GRANULARITY), - InstructionCodec.SLOT_GRANULARITY + InstructionCodec.MISSING_MEMBER_MESSAGE).asInt(); - return Instructions.modL0Lambda(new OchSignal(gridType, channelSpacing, - spacingMultiplier, slotGranularity)); - } - throw new IllegalArgumentException("L0 Instruction subtype " - + subType + " is not supported"); - } - - /** - * Decodes a Layer 1 instruction. - * - * @return instruction object decoded from the JSON - * @throws IllegalArgumentException if the JSON is invalid - */ - private Instruction decodeL1() { - String subType = json.get(InstructionCodec.SUBTYPE).asText(); - if (subType.equals(L1ModificationInstruction.L1SubType.ODU_SIGID.name())) { - int tributaryPortNumber = nullIsIllegal(json.get(InstructionCodec.TRIBUTARY_PORT_NUMBER), - InstructionCodec.TRIBUTARY_PORT_NUMBER + InstructionCodec.MISSING_MEMBER_MESSAGE).asInt(); - int tributarySlotLen = nullIsIllegal(json.get(InstructionCodec.TRIBUTARY_SLOT_LEN), - InstructionCodec.TRIBUTARY_SLOT_LEN + InstructionCodec.MISSING_MEMBER_MESSAGE).asInt(); - byte[] tributarySlotBitmap = null; - tributarySlotBitmap = HexString.fromHexString( - nullIsIllegal(json.get(InstructionCodec.TRIBUTARY_SLOT_BITMAP), - InstructionCodec.TRIBUTARY_SLOT_BITMAP + InstructionCodec.MISSING_MEMBER_MESSAGE).asText()); - return Instructions.modL1OduSignalId(OduSignalId.oduSignalId(tributaryPortNumber, tributarySlotLen, - tributarySlotBitmap)); - } - throw new IllegalArgumentException("L1 Instruction subtype " - + subType + " is not supported"); - } - - /** - * Decodes a Layer 4 instruction. - * - * @return instruction object decoded from the JSON - * @throws IllegalArgumentException if the JSON is invalid - */ - private Instruction decodeL4() { - String subType = json.get(InstructionCodec.SUBTYPE).asText(); - - if (subType.equals(L4ModificationInstruction.L4SubType.TCP_DST.name())) { - TpPort tcpPort = TpPort.tpPort(nullIsIllegal(json.get(InstructionCodec.TCP_PORT), - InstructionCodec.TCP_PORT + InstructionCodec.MISSING_MEMBER_MESSAGE).asInt()); - return Instructions.modTcpDst(tcpPort); - } else if (subType.equals(L4ModificationInstruction.L4SubType.TCP_SRC.name())) { - TpPort tcpPort = TpPort.tpPort(nullIsIllegal(json.get(InstructionCodec.TCP_PORT), - InstructionCodec.TCP_PORT + InstructionCodec.MISSING_MEMBER_MESSAGE).asInt()); - return Instructions.modTcpSrc(tcpPort); - } else if (subType.equals(L4ModificationInstruction.L4SubType.UDP_DST.name())) { - TpPort udpPort = TpPort.tpPort(nullIsIllegal(json.get(InstructionCodec.UDP_PORT), - InstructionCodec.UDP_PORT + InstructionCodec.MISSING_MEMBER_MESSAGE).asInt()); - return Instructions.modUdpDst(udpPort); - } else if (subType.equals(L4ModificationInstruction.L4SubType.UDP_SRC.name())) { - TpPort udpPort = TpPort.tpPort(nullIsIllegal(json.get(InstructionCodec.UDP_PORT), - InstructionCodec.UDP_PORT + InstructionCodec.MISSING_MEMBER_MESSAGE).asInt()); - return Instructions.modUdpSrc(udpPort); - } - throw new IllegalArgumentException("L4 Instruction subtype " - + subType + " is not supported"); - } - - /** - * Decodes the JSON into an instruction object. - * - * @return Criterion object - * @throws IllegalArgumentException if the JSON is invalid - */ - public Instruction decode() { - String type = json.get(InstructionCodec.TYPE).asText(); - - if (type.equals(Instruction.Type.OUTPUT.name())) { - PortNumber portNumber = - PortNumber.portNumber(nullIsIllegal(json.get(InstructionCodec.PORT), - InstructionCodec.PORT + InstructionCodec.MISSING_MEMBER_MESSAGE).asLong()); - return Instructions.createOutput(portNumber); - } else if (type.equals(Instruction.Type.DROP.name())) { - return Instructions.createDrop(); - } else if (type.equals(Instruction.Type.L0MODIFICATION.name())) { - return decodeL0(); - } else if (type.equals(Instruction.Type.L1MODIFICATION.name())) { - return decodeL1(); - } else if (type.equals(Instruction.Type.L2MODIFICATION.name())) { - return decodeL2(); - } else if (type.equals(Instruction.Type.L3MODIFICATION.name())) { - return decodeL3(); - } else if (type.equals(Instruction.Type.L4MODIFICATION.name())) { - return decodeL4(); - } - throw new IllegalArgumentException("Instruction type " - + type + " is not supported"); - } - -} diff --git a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/DeviceCodec.java b/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/DeviceCodec.java deleted file mode 100644 index f1a4f786..00000000 --- a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/DeviceCodec.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2014-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.codec.impl; - -import com.fasterxml.jackson.databind.node.ObjectNode; - -import org.onlab.packet.ChassisId; -import org.onosproject.codec.CodecContext; -import org.onosproject.net.Annotations; -import org.onosproject.net.DefaultDevice; -import org.onosproject.net.Device; -import org.onosproject.net.Device.Type; -import org.onosproject.net.DeviceId; -import org.onosproject.net.device.DeviceService; -import org.onosproject.net.provider.ProviderId; - -import static com.google.common.base.Preconditions.checkNotNull; -import static org.onosproject.net.DeviceId.deviceId; - -/** - * Device JSON codec. - */ -public final class DeviceCodec extends AnnotatedCodec<Device> { - - // JSON fieldNames - private static final String ID = "id"; - private static final String TYPE = "type"; - private static final String MFR = "mfr"; - private static final String HW = "hw"; - private static final String SW = "sw"; - private static final String SERIAL = "serial"; - private static final String CHASSIS_ID = "chassisId"; - - - @Override - public ObjectNode encode(Device device, CodecContext context) { - checkNotNull(device, "Device cannot be null"); - DeviceService service = context.getService(DeviceService.class); - ObjectNode result = context.mapper().createObjectNode() - .put(ID, device.id().toString()) - .put(TYPE, device.type().name()) - .put("available", service.isAvailable(device.id())) - .put("role", service.getRole(device.id()).toString()) - .put(MFR, device.manufacturer()) - .put(HW, device.hwVersion()) - .put(SW, device.swVersion()) - .put(SERIAL, device.serialNumber()) - .put(CHASSIS_ID, device.chassisId().toString()); - return annotate(result, device, context); - } - - - /** - * {@inheritDoc} - * - * Note: ProviderId is not part of JSON representation. - * Returned object will have random ProviderId set. - */ - @Override - public Device decode(ObjectNode json, CodecContext context) { - if (json == null || !json.isObject()) { - return null; - } - - DeviceId id = deviceId(json.get(ID).asText()); - // TODO: add providerId to JSON if we need to recover them. - ProviderId pid = new ProviderId(id.uri().getScheme(), "DeviceCodec"); - - Type type = Type.valueOf(json.get(TYPE).asText()); - String mfr = json.get(MFR).asText(); - String hw = json.get(HW).asText(); - String sw = json.get(SW).asText(); - String serial = json.get(SERIAL).asText(); - ChassisId chassisId = new ChassisId(json.get(CHASSIS_ID).asText()); - Annotations annotations = extractAnnotations(json, context); - - return new DefaultDevice(pid, id, type, mfr, hw, sw, serial, - chassisId, annotations); - } -} diff --git a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/DriverCodec.java b/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/DriverCodec.java deleted file mode 100644 index 4935d992..00000000 --- a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/DriverCodec.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * 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.codec.impl; - -import org.onosproject.codec.CodecContext; -import org.onosproject.codec.JsonCodec; -import org.onosproject.net.driver.Driver; - -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.node.ObjectNode; - -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * JSON codec for the Driver class. - */ -public final class DriverCodec extends JsonCodec<Driver> { - private static final String PARENT = "parent"; - private static final String NAME = "name"; - private static final String MANUFACTURER = "manufacturer"; - private static final String HW_VERSION = "hwVersion"; - private static final String SW_VERSION = "swVersion"; - private static final String BEHAVIOURS = "behaviours"; - private static final String BEHAVIORS_NAME = "name"; - private static final String BEHAVIORS_IMPLEMENTATION_NAME = "implementationName"; - private static final String PROPERTIES = "properties"; - - @Override - public ObjectNode encode(Driver driver, CodecContext context) { - checkNotNull(driver, "Driver cannot be null"); - - ObjectNode result = context.mapper().createObjectNode() - .put(NAME, driver.name()) - .put(MANUFACTURER, driver.manufacturer()) - .put(HW_VERSION, driver.hwVersion()) - .put(SW_VERSION, driver.swVersion()); - - if (driver.parent() != null) { - result.put(PARENT, driver.parent().name()); - } - - ArrayNode behaviours = context.mapper().createArrayNode(); - driver.behaviours().forEach(behaviour -> { - ObjectNode entry = context.mapper().createObjectNode() - .put(BEHAVIORS_NAME, behaviour.getCanonicalName()) - .put(BEHAVIORS_IMPLEMENTATION_NAME, - driver.implementation(behaviour).getCanonicalName()); - - behaviours.add(entry); - }); - result.set(BEHAVIOURS, behaviours); - - ArrayNode properties = context.mapper().createArrayNode(); - driver.properties().forEach((name, value) -> { - ObjectNode entry = context.mapper().createObjectNode() - .put("name", name) - .put("value", value); - - properties.add(entry); - }); - result.set(PROPERTIES, properties); - - return result; - } -} diff --git a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/EncodeConstraintCodecHelper.java b/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/EncodeConstraintCodecHelper.java deleted file mode 100644 index ec4ee444..00000000 --- a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/EncodeConstraintCodecHelper.java +++ /dev/null @@ -1,201 +0,0 @@ -/* - * 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.codec.impl; - -import org.onosproject.codec.CodecContext; -import org.onosproject.net.DeviceId; -import org.onosproject.net.Link; -import org.onosproject.net.intent.Constraint; -import org.onosproject.net.intent.constraint.AnnotationConstraint; -import org.onosproject.net.intent.constraint.BandwidthConstraint; -import org.onosproject.net.intent.constraint.LambdaConstraint; -import org.onosproject.net.intent.constraint.LatencyConstraint; -import org.onosproject.net.intent.constraint.LinkTypeConstraint; -import org.onosproject.net.intent.constraint.ObstacleConstraint; -import org.onosproject.net.intent.constraint.WaypointConstraint; - -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.node.ObjectNode; - -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * Implementation of encoder for constraint JSON codec. - */ -public final class EncodeConstraintCodecHelper { - - private final Constraint constraint; - private final CodecContext context; - - /** - * Constructs a constraint encoder. - * - * @param constraint constraint to encode - * @param context to use for look ups - */ - public EncodeConstraintCodecHelper(Constraint constraint, CodecContext context) { - this.constraint = constraint; - this.context = context; - } - - /** - * Encodes a latency constraint. - * - * @return JSON ObjectNode representing the constraint - */ - private ObjectNode encodeLatencyConstraint() { - checkNotNull(constraint, "Duration constraint cannot be null"); - final LatencyConstraint latencyConstraint = - (LatencyConstraint) constraint; - return context.mapper().createObjectNode() - .put("latencyMillis", latencyConstraint.latency().toMillis()); - } - - /** - * Encodes an obstacle constraint. - * - * @return JSON ObjectNode representing the constraint - */ - private ObjectNode encodeObstacleConstraint() { - checkNotNull(constraint, "Obstacle constraint cannot be null"); - final ObstacleConstraint obstacleConstraint = - (ObstacleConstraint) constraint; - - final ObjectNode result = context.mapper().createObjectNode(); - final ArrayNode jsonObstacles = result.putArray("obstacles"); - - for (DeviceId did : obstacleConstraint.obstacles()) { - jsonObstacles.add(did.toString()); - } - - return result; - } - - /** - * Encodes a waypoint constraint. - * - * @return JSON ObjectNode representing the constraint - */ - private ObjectNode encodeWaypointConstraint() { - checkNotNull(constraint, "Waypoint constraint cannot be null"); - final WaypointConstraint waypointConstraint = - (WaypointConstraint) constraint; - - final ObjectNode result = context.mapper().createObjectNode(); - final ArrayNode jsonWaypoints = result.putArray("waypoints"); - - for (DeviceId did : waypointConstraint.waypoints()) { - jsonWaypoints.add(did.toString()); - } - - return result; - } - - /** - * Encodes a annotation constraint. - * - * @return JSON ObjectNode representing the constraint - */ - private ObjectNode encodeAnnotationConstraint() { - checkNotNull(constraint, "Annotation constraint cannot be null"); - final AnnotationConstraint annotationConstraint = - (AnnotationConstraint) constraint; - return context.mapper().createObjectNode() - .put("key", annotationConstraint.key()) - .put("threshold", annotationConstraint.threshold()); - } - - /** - * Encodes a bandwidth constraint. - * - * @return JSON ObjectNode representing the constraint - */ - private ObjectNode encodeBandwidthConstraint() { - checkNotNull(constraint, "Bandwidth constraint cannot be null"); - final BandwidthConstraint bandwidthConstraint = - (BandwidthConstraint) constraint; - return context.mapper().createObjectNode() - .put("bandwidth", bandwidthConstraint.bandwidth().bps()); - } - - /** - * Encodes a lambda constraint. - * - * @return JSON ObjectNode representing the constraint - */ - private ObjectNode encodeLambdaConstraint() { - checkNotNull(constraint, "Lambda constraint cannot be null"); - final LambdaConstraint lambdaConstraint = - (LambdaConstraint) constraint; - - return context.mapper().createObjectNode() - .put("lambda", lambdaConstraint.lambda().index()); - } - - /** - * Encodes a link type constraint. - * - * @return JSON ObjectNode representing the constraint - */ - private ObjectNode encodeLinkTypeConstraint() { - checkNotNull(constraint, "Link type constraint cannot be null"); - - final LinkTypeConstraint linkTypeConstraint = - (LinkTypeConstraint) constraint; - - final ObjectNode result = context.mapper().createObjectNode() - .put(ConstraintCodec.INCLUSIVE, linkTypeConstraint.isInclusive()); - - final ArrayNode jsonTypes = result.putArray(ConstraintCodec.TYPES); - - if (linkTypeConstraint.types() != null) { - for (Link.Type type : linkTypeConstraint.types()) { - jsonTypes.add(type.name()); - } - } - - return result; - } - - /** - * Encodes the constraint in JSON. - * - * @return JSON node - */ - public ObjectNode encode() { - final ObjectNode result; - if (constraint instanceof BandwidthConstraint) { - result = encodeBandwidthConstraint(); - } else if (constraint instanceof LambdaConstraint) { - result = encodeLambdaConstraint(); - } else if (constraint instanceof LinkTypeConstraint) { - result = encodeLinkTypeConstraint(); - } else if (constraint instanceof AnnotationConstraint) { - result = encodeAnnotationConstraint(); - } else if (constraint instanceof LatencyConstraint) { - result = encodeLatencyConstraint(); - } else if (constraint instanceof ObstacleConstraint) { - result = encodeObstacleConstraint(); - } else if (constraint instanceof WaypointConstraint) { - result = encodeWaypointConstraint(); - } else { - result = context.mapper().createObjectNode(); - } - - result.put(ConstraintCodec.TYPE, constraint.getClass().getSimpleName()); - return result; - } -} diff --git a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/EncodeCriterionCodecHelper.java b/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/EncodeCriterionCodecHelper.java deleted file mode 100644 index 1852ee29..00000000 --- a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/EncodeCriterionCodecHelper.java +++ /dev/null @@ -1,426 +0,0 @@ -/* - * 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.codec.impl; - -import com.fasterxml.jackson.databind.node.ObjectNode; -import org.onlab.util.HexString; -import org.onosproject.codec.CodecContext; -import org.onosproject.net.OchSignal; -import org.onosproject.net.OduSignalId; -import org.onosproject.net.flow.criteria.Criterion; -import org.onosproject.net.flow.criteria.EthCriterion; -import org.onosproject.net.flow.criteria.EthTypeCriterion; -import org.onosproject.net.flow.criteria.IPCriterion; -import org.onosproject.net.flow.criteria.IPDscpCriterion; -import org.onosproject.net.flow.criteria.IPEcnCriterion; -import org.onosproject.net.flow.criteria.IPProtocolCriterion; -import org.onosproject.net.flow.criteria.IPv6ExthdrFlagsCriterion; -import org.onosproject.net.flow.criteria.IPv6FlowLabelCriterion; -import org.onosproject.net.flow.criteria.IPv6NDLinkLayerAddressCriterion; -import org.onosproject.net.flow.criteria.IPv6NDTargetAddressCriterion; -import org.onosproject.net.flow.criteria.IcmpCodeCriterion; -import org.onosproject.net.flow.criteria.IcmpTypeCriterion; -import org.onosproject.net.flow.criteria.Icmpv6CodeCriterion; -import org.onosproject.net.flow.criteria.Icmpv6TypeCriterion; -import org.onosproject.net.flow.criteria.MetadataCriterion; -import org.onosproject.net.flow.criteria.MplsCriterion; -import org.onosproject.net.flow.criteria.OchSignalCriterion; -import org.onosproject.net.flow.criteria.OchSignalTypeCriterion; -import org.onosproject.net.flow.criteria.OduSignalIdCriterion; -import org.onosproject.net.flow.criteria.OduSignalTypeCriterion; -import org.onosproject.net.flow.criteria.PortCriterion; -import org.onosproject.net.flow.criteria.SctpPortCriterion; -import org.onosproject.net.flow.criteria.TcpPortCriterion; -import org.onosproject.net.flow.criteria.TunnelIdCriterion; -import org.onosproject.net.flow.criteria.UdpPortCriterion; -import org.onosproject.net.flow.criteria.VlanIdCriterion; -import org.onosproject.net.flow.criteria.VlanPcpCriterion; - -import java.util.EnumMap; - -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * Encode portion of the criterion codec. - */ -public final class EncodeCriterionCodecHelper { - - private final Criterion criterion; - private final CodecContext context; - - private final EnumMap<Criterion.Type, CriterionTypeFormatter> formatMap; - - /** - * Creates an encoder object for a criterion. - * Initializes the formatter lookup map for the criterion subclasses. - * - * @param criterion Criterion to encode - * @param context context of the JSON encoding - */ - public EncodeCriterionCodecHelper(Criterion criterion, CodecContext context) { - this.criterion = criterion; - this.context = context; - - formatMap = new EnumMap<>(Criterion.Type.class); - - formatMap.put(Criterion.Type.IN_PORT, new FormatInPort()); - formatMap.put(Criterion.Type.IN_PHY_PORT, new FormatInPort()); - formatMap.put(Criterion.Type.METADATA, new FormatMetadata()); - formatMap.put(Criterion.Type.ETH_DST, new FormatEth()); - formatMap.put(Criterion.Type.ETH_SRC, new FormatEth()); - formatMap.put(Criterion.Type.ETH_TYPE, new FormatEthType()); - formatMap.put(Criterion.Type.VLAN_VID, new FormatVlanVid()); - formatMap.put(Criterion.Type.VLAN_PCP, new FormatVlanPcp()); - formatMap.put(Criterion.Type.IP_DSCP, new FormatIpDscp()); - formatMap.put(Criterion.Type.IP_ECN, new FormatIpEcn()); - formatMap.put(Criterion.Type.IP_PROTO, new FormatIpProto()); - formatMap.put(Criterion.Type.IPV4_SRC, new FormatIp()); - formatMap.put(Criterion.Type.IPV4_DST, new FormatIp()); - formatMap.put(Criterion.Type.TCP_SRC, new FormatTcp()); - formatMap.put(Criterion.Type.TCP_DST, new FormatTcp()); - formatMap.put(Criterion.Type.UDP_SRC, new FormatUdp()); - formatMap.put(Criterion.Type.UDP_DST, new FormatUdp()); - formatMap.put(Criterion.Type.SCTP_SRC, new FormatSctp()); - formatMap.put(Criterion.Type.SCTP_DST, new FormatSctp()); - formatMap.put(Criterion.Type.ICMPV4_TYPE, new FormatIcmpV4Type()); - formatMap.put(Criterion.Type.ICMPV4_CODE, new FormatIcmpV4Code()); - formatMap.put(Criterion.Type.IPV6_SRC, new FormatIp()); - formatMap.put(Criterion.Type.IPV6_DST, new FormatIp()); - formatMap.put(Criterion.Type.IPV6_FLABEL, new FormatIpV6FLabel()); - formatMap.put(Criterion.Type.ICMPV6_TYPE, new FormatIcmpV6Type()); - formatMap.put(Criterion.Type.ICMPV6_CODE, new FormatIcmpV6Code()); - formatMap.put(Criterion.Type.IPV6_ND_TARGET, new FormatV6NDTarget()); - formatMap.put(Criterion.Type.IPV6_ND_SLL, new FormatV6NDTll()); - formatMap.put(Criterion.Type.IPV6_ND_TLL, new FormatV6NDTll()); - formatMap.put(Criterion.Type.MPLS_LABEL, new FormatMplsLabel()); - formatMap.put(Criterion.Type.IPV6_EXTHDR, new FormatIpV6Exthdr()); - formatMap.put(Criterion.Type.OCH_SIGID, new FormatOchSigId()); - formatMap.put(Criterion.Type.OCH_SIGTYPE, new FormatOchSigType()); - formatMap.put(Criterion.Type.TUNNEL_ID, new FormatTunnelId()); - formatMap.put(Criterion.Type.DUMMY, new FormatDummyType()); - formatMap.put(Criterion.Type.ODU_SIGID, new FormatOduSignalId()); - formatMap.put(Criterion.Type.ODU_SIGTYPE, new FormatOduSignalType()); - // Currently unimplemented - formatMap.put(Criterion.Type.ARP_OP, new FormatUnknown()); - formatMap.put(Criterion.Type.ARP_SPA, new FormatUnknown()); - formatMap.put(Criterion.Type.ARP_TPA, new FormatUnknown()); - formatMap.put(Criterion.Type.ARP_SHA, new FormatUnknown()); - formatMap.put(Criterion.Type.ARP_THA, new FormatUnknown()); - formatMap.put(Criterion.Type.MPLS_TC, new FormatUnknown()); - formatMap.put(Criterion.Type.MPLS_BOS, new FormatUnknown()); - formatMap.put(Criterion.Type.PBB_ISID, new FormatUnknown()); - formatMap.put(Criterion.Type.UNASSIGNED_40, new FormatUnknown()); - formatMap.put(Criterion.Type.PBB_UCA, new FormatUnknown()); - formatMap.put(Criterion.Type.TCP_FLAGS, new FormatUnknown()); - formatMap.put(Criterion.Type.ACTSET_OUTPUT, new FormatUnknown()); - formatMap.put(Criterion.Type.PACKET_TYPE, new FormatUnknown()); - formatMap.put(Criterion.Type.EXTENSION, new FormatUnknown()); - } - - private interface CriterionTypeFormatter { - ObjectNode encodeCriterion(ObjectNode root, Criterion criterion); - } - - private static class FormatUnknown implements CriterionTypeFormatter { - @Override - public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) { - return root; - } - } - - private static class FormatInPort implements CriterionTypeFormatter { - @Override - public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) { - final PortCriterion portCriterion = (PortCriterion) criterion; - return root.put(CriterionCodec.PORT, portCriterion.port().toLong()); - } - } - - private static class FormatMetadata implements CriterionTypeFormatter { - @Override - public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) { - final MetadataCriterion metadataCriterion = - (MetadataCriterion) criterion; - return root.put(CriterionCodec.METADATA, metadataCriterion.metadata()); - } - } - - private static class FormatEth implements CriterionTypeFormatter { - @Override - public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) { - final EthCriterion ethCriterion = (EthCriterion) criterion; - return root.put(CriterionCodec.MAC, ethCriterion.mac().toString()); - } - } - - private static class FormatEthType implements CriterionTypeFormatter { - @Override - public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) { - final EthTypeCriterion ethTypeCriterion = - (EthTypeCriterion) criterion; - return root.put(CriterionCodec.ETH_TYPE, "0x" - + Integer.toHexString(ethTypeCriterion.ethType().toShort() & 0xffff)); - } - } - - private static class FormatVlanVid implements CriterionTypeFormatter { - @Override - public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) { - final VlanIdCriterion vlanIdCriterion = - (VlanIdCriterion) criterion; - return root.put(CriterionCodec.VLAN_ID, vlanIdCriterion.vlanId().toShort()); - } - } - - private static class FormatVlanPcp implements CriterionTypeFormatter { - @Override - public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) { - final VlanPcpCriterion vlanPcpCriterion = - (VlanPcpCriterion) criterion; - return root.put(CriterionCodec.PRIORITY, vlanPcpCriterion.priority()); - } - } - - private static class FormatIpDscp implements CriterionTypeFormatter { - @Override - public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) { - final IPDscpCriterion ipDscpCriterion = - (IPDscpCriterion) criterion; - return root.put(CriterionCodec.IP_DSCP, ipDscpCriterion.ipDscp()); - } - } - - private static class FormatIpEcn implements CriterionTypeFormatter { - @Override - public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) { - final IPEcnCriterion ipEcnCriterion = - (IPEcnCriterion) criterion; - return root.put(CriterionCodec.IP_ECN, ipEcnCriterion.ipEcn()); - } - } - - private static class FormatIpProto implements CriterionTypeFormatter { - @Override - public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) { - final IPProtocolCriterion iPProtocolCriterion = - (IPProtocolCriterion) criterion; - return root.put(CriterionCodec.PROTOCOL, iPProtocolCriterion.protocol()); - } - } - - private static class FormatIp implements CriterionTypeFormatter { - @Override - public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) { - final IPCriterion iPCriterion = (IPCriterion) criterion; - return root.put(CriterionCodec.IP, iPCriterion.ip().toString()); - } - } - - private static class FormatTcp implements CriterionTypeFormatter { - @Override - public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) { - final TcpPortCriterion tcpPortCriterion = - (TcpPortCriterion) criterion; - return root.put(CriterionCodec.TCP_PORT, tcpPortCriterion.tcpPort().toInt()); - } - } - - private static class FormatUdp implements CriterionTypeFormatter { - @Override - public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) { - final UdpPortCriterion udpPortCriterion = - (UdpPortCriterion) criterion; - return root.put(CriterionCodec.UDP_PORT, udpPortCriterion.udpPort().toInt()); - } - } - - private static class FormatSctp implements CriterionTypeFormatter { - @Override - public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) { - final SctpPortCriterion sctpPortCriterion = - (SctpPortCriterion) criterion; - return root.put(CriterionCodec.SCTP_PORT, sctpPortCriterion.sctpPort().toInt()); - } - } - - private static class FormatIcmpV4Type implements CriterionTypeFormatter { - @Override - public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) { - final IcmpTypeCriterion icmpTypeCriterion = - (IcmpTypeCriterion) criterion; - return root.put(CriterionCodec.ICMP_TYPE, icmpTypeCriterion.icmpType()); - } - } - - private static class FormatIcmpV4Code implements CriterionTypeFormatter { - @Override - public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) { - final IcmpCodeCriterion icmpCodeCriterion = - (IcmpCodeCriterion) criterion; - return root.put(CriterionCodec.ICMP_CODE, icmpCodeCriterion.icmpCode()); - } - } - - private static class FormatIpV6FLabel implements CriterionTypeFormatter { - @Override - public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) { - final IPv6FlowLabelCriterion ipv6FlowLabelCriterion = - (IPv6FlowLabelCriterion) criterion; - return root.put(CriterionCodec.FLOW_LABEL, ipv6FlowLabelCriterion.flowLabel()); - } - } - - private static class FormatIcmpV6Type implements CriterionTypeFormatter { - @Override - public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) { - final Icmpv6TypeCriterion icmpv6TypeCriterion = - (Icmpv6TypeCriterion) criterion; - return root.put(CriterionCodec.ICMPV6_TYPE, icmpv6TypeCriterion.icmpv6Type()); - } - } - - private static class FormatIcmpV6Code implements CriterionTypeFormatter { - @Override - public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) { - final Icmpv6CodeCriterion icmpv6CodeCriterion = - (Icmpv6CodeCriterion) criterion; - return root.put(CriterionCodec.ICMPV6_CODE, icmpv6CodeCriterion.icmpv6Code()); - } - } - - private static class FormatV6NDTarget implements CriterionTypeFormatter { - @Override - public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) { - final IPv6NDTargetAddressCriterion ipv6NDTargetAddressCriterion - = (IPv6NDTargetAddressCriterion) criterion; - return root.put(CriterionCodec.TARGET_ADDRESS, ipv6NDTargetAddressCriterion.targetAddress().toString()); - } - } - - private static class FormatV6NDTll implements CriterionTypeFormatter { - @Override - public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) { - final IPv6NDLinkLayerAddressCriterion ipv6NDLinkLayerAddressCriterion - = (IPv6NDLinkLayerAddressCriterion) criterion; - return root.put(CriterionCodec.MAC, ipv6NDLinkLayerAddressCriterion.mac().toString()); - } - } - - private static class FormatMplsLabel implements CriterionTypeFormatter { - @Override - public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) { - final MplsCriterion mplsCriterion = - (MplsCriterion) criterion; - return root.put(CriterionCodec.LABEL, mplsCriterion.label().toInt()); - } - } - - private static class FormatIpV6Exthdr implements CriterionTypeFormatter { - @Override - public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) { - final IPv6ExthdrFlagsCriterion exthdrCriterion = - (IPv6ExthdrFlagsCriterion) criterion; - return root.put(CriterionCodec.EXT_HDR_FLAGS, exthdrCriterion.exthdrFlags()); - } - } - - private static class FormatOchSigId implements CriterionTypeFormatter { - @Override - public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) { - OchSignal ochSignal = ((OchSignalCriterion) criterion).lambda(); - ObjectNode child = root.putObject(CriterionCodec.OCH_SIGNAL_ID); - - child.put(CriterionCodec.GRID_TYPE, ochSignal.gridType().name()); - child.put(CriterionCodec.CHANNEL_SPACING, ochSignal.channelSpacing().name()); - child.put(CriterionCodec.SPACING_MULIPLIER, ochSignal.spacingMultiplier()); - child.put(CriterionCodec.SLOT_GRANULARITY, ochSignal.slotGranularity()); - - return root; - } - } - - private static class FormatOchSigType implements CriterionTypeFormatter { - @Override - public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) { - final OchSignalTypeCriterion ochSignalTypeCriterion = - (OchSignalTypeCriterion) criterion; - return root.put(CriterionCodec.OCH_SIGNAL_TYPE, ochSignalTypeCriterion.signalType().name()); - } - } - - private static class FormatTunnelId implements CriterionTypeFormatter { - @Override - public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) { - final TunnelIdCriterion tunnelIdCriterion = - (TunnelIdCriterion) criterion; - return root.put(CriterionCodec.TUNNEL_ID, tunnelIdCriterion.tunnelId()); - } - } - - private static class FormatOduSignalId implements CriterionTypeFormatter { - @Override - public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) { - OduSignalId oduSignalId = ((OduSignalIdCriterion) criterion).oduSignalId(); - ObjectNode child = root.putObject(CriterionCodec.ODU_SIGNAL_ID); - - child.put(CriterionCodec.TRIBUTARY_PORT_NUMBER, oduSignalId.tributaryPortNumber()); - child.put(CriterionCodec.TRIBUTARY_SLOT_LEN, oduSignalId.tributarySlotLength()); - child.put(CriterionCodec.TRIBUTARY_SLOT_BITMAP, HexString.toHexString(oduSignalId.tributarySlotBitmap())); - - return root; - } - } - - - private static class FormatOduSignalType implements CriterionTypeFormatter { - @Override - public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) { - final OduSignalTypeCriterion oduSignalTypeCriterion = - (OduSignalTypeCriterion) criterion; - return root.put(CriterionCodec.ODU_SIGNAL_TYPE, oduSignalTypeCriterion.signalType().name()); - } - } - - private class FormatDummyType implements CriterionTypeFormatter { - - @Override - public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) { - checkNotNull(criterion, "Criterion cannot be null"); - - return root.put(CriterionCodec.TYPE, criterion.type().toString()); - - } - } - - /** - * Encodes a criterion into a JSON node. - * - * @return encoded JSON object for the given criterion - */ - public ObjectNode encode() { - final ObjectNode result = context.mapper().createObjectNode() - .put(CriterionCodec.TYPE, criterion.type().toString()); - - CriterionTypeFormatter formatter = - checkNotNull( - formatMap.get(criterion.type()), - "No formatter found for criterion type " - + criterion.type().toString()); - - return formatter.encodeCriterion(result, criterion); - } - -} diff --git a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/EncodeInstructionCodecHelper.java b/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/EncodeInstructionCodecHelper.java deleted file mode 100644 index 2ec301db..00000000 --- a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/EncodeInstructionCodecHelper.java +++ /dev/null @@ -1,281 +0,0 @@ -/* - * 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.codec.impl; - -import org.onlab.util.HexString; -import org.onosproject.codec.CodecContext; -import org.onosproject.net.OchSignal; -import org.onosproject.net.OduSignalId; -import org.onosproject.net.flow.instructions.Instruction; -import org.onosproject.net.flow.instructions.Instructions; -import org.onosproject.net.flow.instructions.L0ModificationInstruction; -import org.onosproject.net.flow.instructions.L1ModificationInstruction; -import org.onosproject.net.flow.instructions.L2ModificationInstruction; -import org.onosproject.net.flow.instructions.L3ModificationInstruction; -import org.onosproject.net.flow.instructions.L4ModificationInstruction; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.fasterxml.jackson.databind.node.ObjectNode; - -/** - * JSON encoding of Instructions. - */ -public final class EncodeInstructionCodecHelper { - protected static final Logger log = LoggerFactory.getLogger(EncodeInstructionCodecHelper.class); - private final Instruction instruction; - private final CodecContext context; - - /** - * Creates an instruction object encoder. - * - * @param instruction instruction to encode - * @param context codec context for the encoding - */ - public EncodeInstructionCodecHelper(Instruction instruction, CodecContext context) { - this.instruction = instruction; - this.context = context; - } - - - /** - * Encode an L0 modification instruction. - * - * @param result json node that the instruction attributes are added to - */ - private void encodeL0(ObjectNode result) { - L0ModificationInstruction instruction = - (L0ModificationInstruction) this.instruction; - result.put(InstructionCodec.SUBTYPE, instruction.subtype().name()); - - switch (instruction.subtype()) { - case LAMBDA: - final L0ModificationInstruction.ModLambdaInstruction modLambdaInstruction = - (L0ModificationInstruction.ModLambdaInstruction) instruction; - result.put(InstructionCodec.LAMBDA, modLambdaInstruction.lambda()); - break; - - case OCH: - L0ModificationInstruction.ModOchSignalInstruction ochSignalInstruction = - (L0ModificationInstruction.ModOchSignalInstruction) instruction; - OchSignal ochSignal = ochSignalInstruction.lambda(); - result.put(InstructionCodec.GRID_TYPE, ochSignal.gridType().name()); - result.put(InstructionCodec.CHANNEL_SPACING, ochSignal.channelSpacing().name()); - result.put(InstructionCodec.SPACING_MULTIPLIER, ochSignal.spacingMultiplier()); - result.put(InstructionCodec.SLOT_GRANULARITY, ochSignal.slotGranularity()); - break; - - default: - log.info("Cannot convert L0 subtype of {}", instruction.subtype()); - } - } - - /** - * Encode an L1 modification instruction. - * - * @param result json node that the instruction attributes are added to - * @param instruction The L1 instruction - * @param context context of the request - */ - private void encodeL1(ObjectNode result) { - L1ModificationInstruction instruction = - (L1ModificationInstruction) this.instruction; - result.put(InstructionCodec.SUBTYPE, instruction.subtype().name()); - - switch (instruction.subtype()) { - case ODU_SIGID: - final L1ModificationInstruction.ModOduSignalIdInstruction oduSignalIdInstruction = - (L1ModificationInstruction.ModOduSignalIdInstruction) instruction; - OduSignalId oduSignalId = oduSignalIdInstruction.oduSignalId(); - - ObjectNode child = result.putObject("oduSignalId"); - - child.put(InstructionCodec.TRIBUTARY_PORT_NUMBER, oduSignalId.tributaryPortNumber()); - child.put(InstructionCodec.TRIBUTARY_SLOT_LEN, oduSignalId.tributarySlotLength()); - child.put(InstructionCodec.TRIBUTARY_SLOT_BITMAP, HexString.toHexString(oduSignalId.tributarySlotBitmap())); - break; - default: - log.info("Cannot convert L1 subtype of {}", instruction.subtype()); - break; - } - } - - /** - * Encode an L2 modification instruction. - * - * @param result json node that the instruction attributes are added to - */ - private void encodeL2(ObjectNode result) { - L2ModificationInstruction instruction = - (L2ModificationInstruction) this.instruction; - result.put(InstructionCodec.SUBTYPE, instruction.subtype().name()); - - switch (instruction.subtype()) { - case ETH_SRC: - case ETH_DST: - final L2ModificationInstruction.ModEtherInstruction modEtherInstruction = - (L2ModificationInstruction.ModEtherInstruction) instruction; - result.put(InstructionCodec.MAC, modEtherInstruction.mac().toString()); - break; - - case VLAN_ID: - final L2ModificationInstruction.ModVlanIdInstruction modVlanIdInstruction = - (L2ModificationInstruction.ModVlanIdInstruction) instruction; - result.put(InstructionCodec.VLAN_ID, modVlanIdInstruction.vlanId().toShort()); - break; - - case VLAN_PCP: - final L2ModificationInstruction.ModVlanPcpInstruction modVlanPcpInstruction = - (L2ModificationInstruction.ModVlanPcpInstruction) instruction; - result.put(InstructionCodec.VLAN_PCP, modVlanPcpInstruction.vlanPcp()); - break; - - case MPLS_LABEL: - final L2ModificationInstruction.ModMplsLabelInstruction modMplsLabelInstruction = - (L2ModificationInstruction.ModMplsLabelInstruction) instruction; - result.put(InstructionCodec.MPLS_LABEL, modMplsLabelInstruction.mplsLabel().toInt()); - break; - - case MPLS_PUSH: - final L2ModificationInstruction.PushHeaderInstructions pushHeaderInstructions = - (L2ModificationInstruction.PushHeaderInstructions) instruction; - - result.put(InstructionCodec.ETHERNET_TYPE, - pushHeaderInstructions.ethernetType().toShort()); - break; - - case TUNNEL_ID: - final L2ModificationInstruction.ModTunnelIdInstruction modTunnelIdInstruction = - (L2ModificationInstruction.ModTunnelIdInstruction) instruction; - result.put(InstructionCodec.TUNNEL_ID, modTunnelIdInstruction.tunnelId()); - break; - - default: - log.info("Cannot convert L2 subtype of {}", instruction.subtype()); - break; - } - } - - /** - * Encode an L3 modification instruction. - * - * @param result json node that the instruction attributes are added to - */ - private void encodeL3(ObjectNode result) { - L3ModificationInstruction instruction = - (L3ModificationInstruction) this.instruction; - result.put(InstructionCodec.SUBTYPE, instruction.subtype().name()); - switch (instruction.subtype()) { - case IPV4_SRC: - case IPV4_DST: - case IPV6_SRC: - case IPV6_DST: - final L3ModificationInstruction.ModIPInstruction modIPInstruction = - (L3ModificationInstruction.ModIPInstruction) instruction; - result.put(InstructionCodec.IP, modIPInstruction.ip().toString()); - break; - - case IPV6_FLABEL: - final L3ModificationInstruction.ModIPv6FlowLabelInstruction - modFlowLabelInstruction = - (L3ModificationInstruction.ModIPv6FlowLabelInstruction) instruction; - result.put(InstructionCodec.FLOW_LABEL, modFlowLabelInstruction.flowLabel()); - break; - - default: - log.info("Cannot convert L3 subtype of {}", instruction.subtype()); - break; - } - } - - /** - * Encode a L4 modification instruction. - * - * @param result json node that the instruction attributes are added to - */ - private void encodeL4(ObjectNode result) { - L4ModificationInstruction instruction = - (L4ModificationInstruction) this.instruction; - result.put(InstructionCodec.SUBTYPE, instruction.subtype().name()); - switch (instruction.subtype()) { - case TCP_DST: - case TCP_SRC: - final L4ModificationInstruction.ModTransportPortInstruction modTcpPortInstruction = - (L4ModificationInstruction.ModTransportPortInstruction) instruction; - result.put(InstructionCodec.TCP_PORT, modTcpPortInstruction.port().toInt()); - break; - - case UDP_DST: - case UDP_SRC: - final L4ModificationInstruction.ModTransportPortInstruction modUdpPortInstruction = - (L4ModificationInstruction.ModTransportPortInstruction) instruction; - result.put(InstructionCodec.UDP_PORT, modUdpPortInstruction.port().toInt()); - break; - - default: - log.info("Cannot convert L4 subtype of {}", instruction.subtype()); - break; - } - } - - /** - * Encodes the given instruction into JSON. - * - * @return JSON object node representing the instruction - */ - public ObjectNode encode() { - final ObjectNode result = context.mapper().createObjectNode() - .put(InstructionCodec.TYPE, instruction.type().toString()); - - switch (instruction.type()) { - case OUTPUT: - final Instructions.OutputInstruction outputInstruction = - (Instructions.OutputInstruction) instruction; - result.put(InstructionCodec.PORT, outputInstruction.port().toLong()); - break; - - case DROP: - case NOACTION: - break; - - case L0MODIFICATION: - encodeL0(result); - break; - - case L1MODIFICATION: - encodeL1(result); - break; - - case L2MODIFICATION: - encodeL2(result); - break; - - case L3MODIFICATION: - encodeL3(result); - break; - - case L4MODIFICATION: - encodeL4(result); - break; - - default: - log.info("Cannot convert instruction type of {}", instruction.type()); - break; - } - return result; - } - -} diff --git a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/EthernetCodec.java b/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/EthernetCodec.java deleted file mode 100644 index f56bca46..00000000 --- a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/EthernetCodec.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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.codec.impl; - -import org.onlab.packet.Ethernet; -import org.onosproject.codec.CodecContext; -import org.onosproject.codec.JsonCodec; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.fasterxml.jackson.databind.node.ObjectNode; - -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * Ethernet codec. - */ -public final class EthernetCodec extends JsonCodec<Ethernet> { - - protected static final Logger log = LoggerFactory.getLogger(CriterionCodec.class); - - @Override - public ObjectNode encode(Ethernet ethernet, CodecContext context) { - checkNotNull(ethernet, "Ethernet cannot be null"); - - final ObjectNode result = context.mapper().createObjectNode() - .put("vlanId", ethernet.getVlanID()) - .put("etherType", ethernet.getEtherType()) - .put("priorityCode", ethernet.getPriorityCode()) - .put("pad", ethernet.isPad()); - - if (ethernet.getDestinationMAC() != null) { - result.put("destMac", - ethernet.getDestinationMAC().toString()); - } - - if (ethernet.getSourceMAC() != null) { - result.put("srcMac", - ethernet.getSourceMAC().toString()); - } - - return result; - } - -} diff --git a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/FlowEntryCodec.java b/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/FlowEntryCodec.java deleted file mode 100644 index 3f581bed..00000000 --- a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/FlowEntryCodec.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2014-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.codec.impl; - -import org.onosproject.codec.CodecContext; -import org.onosproject.codec.JsonCodec; -import org.onosproject.core.CoreService; -import org.onosproject.net.flow.FlowEntry; -import org.onosproject.net.flow.TrafficSelector; -import org.onosproject.net.flow.TrafficTreatment; - -import com.fasterxml.jackson.databind.node.ObjectNode; - -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * Flow entry JSON codec. - */ -public final class FlowEntryCodec extends JsonCodec<FlowEntry> { - - @Override - public ObjectNode encode(FlowEntry flowEntry, CodecContext context) { - checkNotNull(flowEntry, "Flow entry cannot be null"); - - CoreService service = context.getService(CoreService.class); - - final ObjectNode result = context.mapper().createObjectNode() - .put("id", Long.toString(flowEntry.id().value())) - .put("tableId", flowEntry.tableId()) - .put("appId", service.getAppId(flowEntry.appId()).name()) - .put("groupId", flowEntry.groupId().id()) - .put("priority", flowEntry.priority()) - .put("timeout", flowEntry.timeout()) - .put("isPermanent", flowEntry.isPermanent()) - .put("deviceId", flowEntry.deviceId().toString()) - .put("state", flowEntry.state().toString()) - .put("life", flowEntry.life()) - .put("packets", flowEntry.packets()) - .put("bytes", flowEntry.bytes()) - .put("lastSeen", flowEntry.lastSeen()); - - if (flowEntry.treatment() != null) { - final JsonCodec<TrafficTreatment> treatmentCodec = - context.codec(TrafficTreatment.class); - result.set("treatment", treatmentCodec.encode(flowEntry.treatment(), context)); - } - - if (flowEntry.selector() != null) { - final JsonCodec<TrafficSelector> selectorCodec = - context.codec(TrafficSelector.class); - result.set("selector", selectorCodec.encode(flowEntry.selector(), context)); - } - - return result; - } - -} - diff --git a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/FlowRuleCodec.java b/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/FlowRuleCodec.java deleted file mode 100644 index 6c02841e..00000000 --- a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/FlowRuleCodec.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * 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.codec.impl; - -import org.onosproject.codec.CodecContext; -import org.onosproject.codec.JsonCodec; -import org.onosproject.core.CoreService; -import org.onosproject.net.DeviceId; -import org.onosproject.net.flow.DefaultFlowRule; -import org.onosproject.net.flow.FlowRule; -import org.onosproject.net.flow.TrafficSelector; -import org.onosproject.net.flow.TrafficTreatment; - -import com.fasterxml.jackson.databind.node.ObjectNode; - -import static org.onlab.util.Tools.nullIsIllegal; - -/** - * Flow rule JSON codec. - */ -public final class FlowRuleCodec extends JsonCodec<FlowRule> { - - private static final String PRIORITY = "priority"; - private static final String TIMEOUT = "timeout"; - private static final String IS_PERMANENT = "isPermanent"; - private static final String DEVICE_ID = "deviceId"; - private static final String TREATMENT = "treatment"; - private static final String SELECTOR = "selector"; - private static final String MISSING_MEMBER_MESSAGE = - " member is required in FlowRule"; - public static final String REST_APP_ID = "org.onosproject.rest"; - - - @Override - public FlowRule decode(ObjectNode json, CodecContext context) { - if (json == null || !json.isObject()) { - return null; - } - - FlowRule.Builder resultBuilder = new DefaultFlowRule.Builder(); - - CoreService coreService = context.getService(CoreService.class); - resultBuilder.fromApp(coreService - .registerApplication(REST_APP_ID)); - - int priority = nullIsIllegal(json.get(PRIORITY), - PRIORITY + MISSING_MEMBER_MESSAGE).asInt(); - resultBuilder.withPriority(priority); - - boolean isPermanent = nullIsIllegal(json.get(IS_PERMANENT), - IS_PERMANENT + MISSING_MEMBER_MESSAGE).asBoolean(); - if (isPermanent) { - resultBuilder.makePermanent(); - } else { - resultBuilder.makeTemporary(nullIsIllegal(json.get(TIMEOUT), - TIMEOUT - + MISSING_MEMBER_MESSAGE - + " if the flow is temporary").asInt()); - } - - DeviceId deviceId = DeviceId.deviceId(nullIsIllegal(json.get(DEVICE_ID), - DEVICE_ID + MISSING_MEMBER_MESSAGE).asText()); - resultBuilder.forDevice(deviceId); - - ObjectNode treatmentJson = get(json, TREATMENT); - if (treatmentJson != null) { - JsonCodec<TrafficTreatment> treatmentCodec = - context.codec(TrafficTreatment.class); - resultBuilder.withTreatment(treatmentCodec.decode(treatmentJson, context)); - } - - ObjectNode selectorJson = get(json, SELECTOR); - if (selectorJson != null) { - JsonCodec<TrafficSelector> selectorCodec = - context.codec(TrafficSelector.class); - resultBuilder.withSelector(selectorCodec.decode(selectorJson, context)); - } - - return resultBuilder.build(); - } -} diff --git a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/GroupBucketCodec.java b/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/GroupBucketCodec.java deleted file mode 100644 index c710514f..00000000 --- a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/GroupBucketCodec.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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.codec.impl; - -import org.onosproject.codec.CodecContext; -import org.onosproject.codec.JsonCodec; -import org.onosproject.net.flow.TrafficTreatment; -import org.onosproject.net.group.GroupBucket; - -import com.fasterxml.jackson.databind.node.ObjectNode; - -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * Group bucket JSON codec. - */ -public class GroupBucketCodec extends JsonCodec<GroupBucket> { - - private static final String TYPE = "type"; - private static final String TREATMENT = "treatment"; - private static final String WEIGHT = "weight"; - private static final String WATCH_PORT = "watchPort"; - private static final String WATCH_GROUP = "watchGroup"; - private static final String PACKETS = "packets"; - private static final String BYTES = "bytes"; - - @Override - public ObjectNode encode(GroupBucket bucket, CodecContext context) { - checkNotNull(bucket, "Driver cannot be null"); - - ObjectNode result = context.mapper().createObjectNode() - .put(TYPE, bucket.type().toString()) - .put(WEIGHT, bucket.weight()) - .put(PACKETS, bucket.packets()) - .put(BYTES, bucket.bytes()); - - if (bucket.watchPort() != null) { - result.put(WATCH_PORT, bucket.watchPort().toString()); - } - - if (bucket.watchGroup() != null) { - result.put(WATCH_GROUP, bucket.watchGroup().toString()); - } - - if (bucket.treatment() != null) { - result.set(TREATMENT, context.codec(TrafficTreatment.class).encode(bucket.treatment(), context)); - } - - return result; - } -} diff --git a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/GroupCodec.java b/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/GroupCodec.java deleted file mode 100644 index a2f33cee..00000000 --- a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/GroupCodec.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * 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.codec.impl; - -import org.onosproject.codec.CodecContext; -import org.onosproject.codec.JsonCodec; -import org.onosproject.net.group.Group; -import org.onosproject.net.group.GroupBucket; - -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.node.ObjectNode; - -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * Group JSON codec. - */ -public final class GroupCodec extends JsonCodec<Group> { - // JSON field names - private static final String ID = "id"; - private static final String STATE = "state"; - private static final String LIFE = "life"; - private static final String PACKETS = "packets"; - private static final String BYTES = "bytes"; - private static final String REFERENCE_COUNT = "referenceCount"; - private static final String TYPE = "type"; - private static final String DEVICE_ID = "deviceId"; - private static final String APP_ID = "appId"; - private static final String APP_COOKIE = "appCookie"; - private static final String GIVEN_GROUP_ID = "givenGroupId"; - private static final String BUCKETS = "buckets"; - - @Override - public ObjectNode encode(Group group, CodecContext context) { - checkNotNull(group, "Group cannot be null"); - ObjectNode result = context.mapper().createObjectNode() - .put(ID, group.id().toString()) - .put(STATE, group.state().toString()) - .put(LIFE, group.life()) - .put(PACKETS, group.packets()) - .put(BYTES, group.bytes()) - .put(REFERENCE_COUNT, group.referenceCount()) - .put(TYPE, group.type().toString()) - .put(DEVICE_ID, group.deviceId().toString()); - - if (group.appId() != null) { - result.put(APP_ID, group.appId().toString()); - } - - if (group.appCookie() != null) { - result.put(APP_COOKIE, group.appCookie().toString()); - } - - if (group.givenGroupId() != null) { - result.put(GIVEN_GROUP_ID, group.givenGroupId()); - } - - ArrayNode buckets = context.mapper().createArrayNode(); - group.buckets().buckets().forEach(bucket -> { - ObjectNode bucketJson = context.codec(GroupBucket.class).encode(bucket, context); - buckets.add(bucketJson); - }); - result.set(BUCKETS, buckets); - return result; - } -} diff --git a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/HostCodec.java b/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/HostCodec.java deleted file mode 100644 index a2402728..00000000 --- a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/HostCodec.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2014-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.codec.impl; - -import org.onlab.packet.IpAddress; -import org.onosproject.codec.CodecContext; -import org.onosproject.codec.JsonCodec; -import org.onosproject.net.Host; -import org.onosproject.net.HostLocation; - -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.node.ObjectNode; - -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * Host JSON codec. - */ -public final class HostCodec extends AnnotatedCodec<Host> { - - @Override - public ObjectNode encode(Host host, CodecContext context) { - checkNotNull(host, "Host cannot be null"); - final JsonCodec<HostLocation> locationCodec = - context.codec(HostLocation.class); - final ObjectNode result = context.mapper().createObjectNode() - .put("id", host.id().toString()) - .put("mac", host.mac().toString()) - .put("vlan", host.vlan().toString()); - - final ArrayNode jsonIpAddresses = result.putArray("ipAddresses"); - for (final IpAddress ipAddress : host.ipAddresses()) { - jsonIpAddresses.add(ipAddress.toString()); - } - result.set("ipAddresses", jsonIpAddresses); - result.set("location", locationCodec.encode(host.location(), context)); - - return annotate(result, host, context); - } - -} - diff --git a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/HostLocationCodec.java b/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/HostLocationCodec.java deleted file mode 100644 index f8f616d0..00000000 --- a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/HostLocationCodec.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2014-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.codec.impl; - -import org.onosproject.codec.CodecContext; -import org.onosproject.codec.JsonCodec; -import org.onosproject.net.HostLocation; - -import com.fasterxml.jackson.databind.node.ObjectNode; - -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * Host JSON codec. - */ -public final class HostLocationCodec extends JsonCodec<HostLocation> { - - @Override - public ObjectNode encode(HostLocation hostLocation, CodecContext context) { - checkNotNull(hostLocation, "Host location cannot be null"); - return context.mapper().createObjectNode() - .put("elementId", hostLocation.elementId().toString()) - .put("port", hostLocation.port().toString()); - } - -} diff --git a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/HostToHostIntentCodec.java b/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/HostToHostIntentCodec.java deleted file mode 100644 index 597ab55c..00000000 --- a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/HostToHostIntentCodec.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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.codec.impl; - -import org.onosproject.codec.CodecContext; -import org.onosproject.codec.JsonCodec; -import org.onosproject.net.HostId; -import org.onosproject.net.intent.ConnectivityIntent; -import org.onosproject.net.intent.HostToHostIntent; - -import com.fasterxml.jackson.databind.node.ObjectNode; - -import static com.google.common.base.Preconditions.checkNotNull; -import static org.onlab.util.Tools.nullIsIllegal; - -/** - * Host to host intent codec. - */ -public final class HostToHostIntentCodec extends JsonCodec<HostToHostIntent> { - - private static final String ONE = "one"; - private static final String TWO = "two"; - - @Override - public ObjectNode encode(HostToHostIntent intent, CodecContext context) { - checkNotNull(intent, "Host to host intent cannot be null"); - - final JsonCodec<ConnectivityIntent> connectivityIntentCodec = - context.codec(ConnectivityIntent.class); - final ObjectNode result = connectivityIntentCodec.encode(intent, context); - - final String one = intent.one().toString(); - final String two = intent.two().toString(); - result.put(ONE, one); - result.put(TWO, two); - - return result; - } - - @Override - public HostToHostIntent decode(ObjectNode json, CodecContext context) { - HostToHostIntent.Builder builder = HostToHostIntent.builder(); - - IntentCodec.intentAttributes(json, context, builder); - ConnectivityIntentCodec.intentAttributes(json, context, builder); - - String one = nullIsIllegal(json.get(ONE), - ONE + IntentCodec.MISSING_MEMBER_MESSAGE).asText(); - builder.one(HostId.hostId(one)); - - String two = nullIsIllegal(json.get(TWO), - TWO + IntentCodec.MISSING_MEMBER_MESSAGE).asText(); - builder.two(HostId.hostId(two)); - - return builder.build(); - } -} diff --git a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/InstructionCodec.java b/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/InstructionCodec.java deleted file mode 100644 index d7307ad3..00000000 --- a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/InstructionCodec.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * 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.codec.impl; - -import org.onosproject.codec.CodecContext; -import org.onosproject.codec.JsonCodec; -import org.onosproject.net.flow.instructions.Instruction; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.fasterxml.jackson.databind.node.ObjectNode; - -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * Instruction codec. - */ -public final class InstructionCodec extends JsonCodec<Instruction> { - - protected static final Logger log = LoggerFactory.getLogger(InstructionCodec.class); - - protected static final String TYPE = "type"; - protected static final String SUBTYPE = "subtype"; - protected static final String PORT = "port"; - protected static final String MAC = "mac"; - protected static final String VLAN_ID = "vlanId"; - protected static final String VLAN_PCP = "vlanPcp"; - protected static final String MPLS_LABEL = "label"; - protected static final String IP = "ip"; - protected static final String FLOW_LABEL = "flowLabel"; - protected static final String LAMBDA = "lambda"; - protected static final String GRID_TYPE = "gridType"; - protected static final String CHANNEL_SPACING = "channelSpacing"; - protected static final String SPACING_MULTIPLIER = "spacingMultiplier"; - protected static final String SLOT_GRANULARITY = "slotGranularity"; - protected static final String ETHERNET_TYPE = "ethernetType"; - protected static final String TUNNEL_ID = "tunnelId"; - protected static final String TCP_PORT = "tcpPort"; - protected static final String UDP_PORT = "udpPort"; - protected static final String TRIBUTARY_PORT_NUMBER = "tributaryPortNumber"; - protected static final String TRIBUTARY_SLOT_LEN = "tributarySlotLength"; - protected static final String TRIBUTARY_SLOT_BITMAP = "tributarySlotBitmap"; - - protected static final String MISSING_MEMBER_MESSAGE = - " member is required in Instruction"; - - - @Override - public ObjectNode encode(Instruction instruction, CodecContext context) { - checkNotNull(instruction, "Instruction cannot be null"); - - return new EncodeInstructionCodecHelper(instruction, context).encode(); - } - - @Override - public Instruction decode(ObjectNode json, CodecContext context) { - if (json == null || !json.isObject()) { - return null; - } - - return new DecodeInstructionCodecHelper(json).decode(); - } -} diff --git a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/IntentCodec.java b/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/IntentCodec.java deleted file mode 100644 index 8613a964..00000000 --- a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/IntentCodec.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright 2014-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.codec.impl; - -import org.onosproject.codec.CodecContext; -import org.onosproject.codec.JsonCodec; -import org.onosproject.core.CoreService; -import org.onosproject.net.NetworkResource; -import org.onosproject.net.intent.HostToHostIntent; -import org.onosproject.net.intent.Intent; -import org.onosproject.net.intent.IntentService; -import org.onosproject.net.intent.IntentState; -import org.onosproject.net.intent.PointToPointIntent; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.node.ObjectNode; -import com.google.common.net.UrlEscapers; - -import static com.google.common.base.Preconditions.checkNotNull; -import static org.onlab.util.Tools.nullIsIllegal; - -/** - * Intent JSON codec. - */ -public final class IntentCodec extends JsonCodec<Intent> { - - protected static final String TYPE = "type"; - protected static final String ID = "id"; - protected static final String APP_ID = "appId"; - protected static final String STATE = "state"; - protected static final String PRIORITY = "priority"; - protected static final String RESOURCES = "resources"; - protected static final String MISSING_MEMBER_MESSAGE = - " member is required in Intent"; - - @Override - public ObjectNode encode(Intent intent, CodecContext context) { - checkNotNull(intent, "Intent cannot be null"); - - final ObjectNode result = context.mapper().createObjectNode() - .put(TYPE, intent.getClass().getSimpleName()) - .put(ID, intent.id().toString()) - .put(APP_ID, UrlEscapers.urlPathSegmentEscaper() - .escape(intent.appId().name())); - - final ArrayNode jsonResources = result.putArray(RESOURCES); - - for (final NetworkResource resource : intent.resources()) { - jsonResources.add(resource.toString()); - } - - IntentService service = context.getService(IntentService.class); - IntentState state = service.getIntentState(intent.key()); - if (state != null) { - result.put(STATE, state.toString()); - } - - return result; - } - - @Override - public Intent decode(ObjectNode json, CodecContext context) { - checkNotNull(json, "JSON cannot be null"); - - String type = nullIsIllegal(json.get(TYPE), - TYPE + MISSING_MEMBER_MESSAGE).asText(); - - if (type.equals(PointToPointIntent.class.getSimpleName())) { - return context.codec(PointToPointIntent.class).decode(json, context); - } else if (type.equals(HostToHostIntent.class.getSimpleName())) { - return context.codec(HostToHostIntent.class).decode(json, context); - } - - throw new IllegalArgumentException("Intent type " - + type + " is not supported"); - } - - /** - * Extracts base intent specific attributes from a JSON object - * and adds them to a builder. - * - * @param json root JSON object - * @param context code context - * @param builder builder to use for storing the attributes - */ - public static void intentAttributes(ObjectNode json, CodecContext context, - Intent.Builder builder) { - String appId = nullIsIllegal(json.get(IntentCodec.APP_ID), - IntentCodec.APP_ID + IntentCodec.MISSING_MEMBER_MESSAGE).asText(); - CoreService service = context.getService(CoreService.class); - builder.appId(service.getAppId(appId)); - - JsonNode priorityJson = json.get(IntentCodec.PRIORITY); - if (priorityJson != null) { - builder.priority(priorityJson.asInt()); - } - } -} diff --git a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/LinkCodec.java b/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/LinkCodec.java deleted file mode 100644 index 14ee9b7c..00000000 --- a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/LinkCodec.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright 2014-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.codec.impl; - -import com.fasterxml.jackson.databind.node.ObjectNode; - -import org.onosproject.codec.CodecContext; -import org.onosproject.codec.JsonCodec; -import org.onosproject.net.Annotations; -import org.onosproject.net.ConnectPoint; -import org.onosproject.net.DefaultLink; -import org.onosproject.net.Link; -import org.onosproject.net.Link.Type; -import org.onosproject.net.provider.ProviderId; - -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * Link JSON codec. - */ -public final class LinkCodec extends AnnotatedCodec<Link> { - - // JSON field names - private static final String SRC = "src"; - private static final String DST = "dst"; - private static final String TYPE = "type"; - private static final String STATE = "state"; - - @Override - public ObjectNode encode(Link link, CodecContext context) { - checkNotNull(link, "Link cannot be null"); - JsonCodec<ConnectPoint> codec = context.codec(ConnectPoint.class); - ObjectNode result = context.mapper().createObjectNode(); - result.set(SRC, codec.encode(link.src(), context)); - result.set(DST, codec.encode(link.dst(), context)); - result.put(TYPE, link.type().toString()); - if (link.state() != null) { - result.put(STATE, link.state().toString()); - } - return annotate(result, link, context); - } - - - /** - * {@inheritDoc} - * - * Note: ProviderId is not part of JSON representation. - * Returned object will have random ProviderId set. - */ - @Override - public Link decode(ObjectNode json, CodecContext context) { - if (json == null || !json.isObject()) { - return null; - } - - JsonCodec<ConnectPoint> codec = context.codec(ConnectPoint.class); - // TODO: add providerId to JSON if we need to recover them. - ProviderId pid = new ProviderId("json", "LinkCodec"); - - ConnectPoint src = codec.decode(get(json, SRC), context); - ConnectPoint dst = codec.decode(get(json, DST), context); - Type type = Type.valueOf(json.get(TYPE).asText()); - Annotations annotations = extractAnnotations(json, context); - - return new DefaultLink(pid, src, dst, type, annotations); - } -} diff --git a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/LoadCodec.java b/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/LoadCodec.java deleted file mode 100644 index 0e55592d..00000000 --- a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/LoadCodec.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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.codec.impl; - -import org.onosproject.codec.CodecContext; -import org.onosproject.codec.JsonCodec; -import org.onosproject.net.statistic.Load; - -import com.fasterxml.jackson.databind.node.ObjectNode; - -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * Codec for the Load class. - */ -public class LoadCodec extends JsonCodec<Load> { - - private static final String RATE = "rate"; - private static final String LATEST = "latest"; - private static final String VALID = "valid"; - private static final String TIME = "time"; - - @Override - public ObjectNode encode(Load load, CodecContext context) { - checkNotNull(load, "Load cannot be null"); - return context.mapper().createObjectNode() - .put(RATE, load.rate()) - .put(LATEST, load.latest()) - .put(VALID, load.isValid()) - .put(TIME, load.time()); - } -} diff --git a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/PathCodec.java b/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/PathCodec.java deleted file mode 100644 index 58b48529..00000000 --- a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/PathCodec.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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.codec.impl; - -import org.onosproject.codec.CodecContext; -import org.onosproject.codec.JsonCodec; -import org.onosproject.net.Link; -import org.onosproject.net.Path; - -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.node.ObjectNode; - -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * Path JSON codec. - */ -public final class PathCodec extends AnnotatedCodec<Path> { - @Override - public ObjectNode encode(Path path, CodecContext context) { - checkNotNull(path, "Path cannot be null"); - JsonCodec<Link> codec = context.codec(Link.class); - ObjectNode result = context.mapper() - .createObjectNode() - .put("cost", path.cost()); - ArrayNode jsonLinks = result.putArray("links"); - - for (Link link : path.links()) { - jsonLinks.add(codec.encode(link, context)); - } - - return annotate(result, path, context); - } -} diff --git a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/PointToPointIntentCodec.java b/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/PointToPointIntentCodec.java deleted file mode 100644 index 20df4890..00000000 --- a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/PointToPointIntentCodec.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * 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.codec.impl; - -import org.onosproject.codec.CodecContext; -import org.onosproject.codec.JsonCodec; -import org.onosproject.net.ConnectPoint; -import org.onosproject.net.intent.ConnectivityIntent; -import org.onosproject.net.intent.PointToPointIntent; - -import com.fasterxml.jackson.databind.node.ObjectNode; - -import static com.google.common.base.Preconditions.checkNotNull; -import static org.onlab.util.Tools.nullIsIllegal; - -/** - * Point to point intent codec. - */ -public final class PointToPointIntentCodec extends JsonCodec<PointToPointIntent> { - - private static final String INGRESS_POINT = "ingressPoint"; - private static final String EGRESS_POINT = "egressPoint"; - - @Override - public ObjectNode encode(PointToPointIntent intent, CodecContext context) { - checkNotNull(intent, "Point to point intent cannot be null"); - - final JsonCodec<ConnectivityIntent> connectivityIntentCodec = - context.codec(ConnectivityIntent.class); - final ObjectNode result = connectivityIntentCodec.encode(intent, context); - - final JsonCodec<ConnectPoint> connectPointCodec = - context.codec(ConnectPoint.class); - final ObjectNode ingress = - connectPointCodec.encode(intent.ingressPoint(), context); - final ObjectNode egress = - connectPointCodec.encode(intent.egressPoint(), context); - - result.set(INGRESS_POINT, ingress); - result.set(EGRESS_POINT, egress); - - return result; - } - - - @Override - public PointToPointIntent decode(ObjectNode json, CodecContext context) { - PointToPointIntent.Builder builder = PointToPointIntent.builder(); - - IntentCodec.intentAttributes(json, context, builder); - ConnectivityIntentCodec.intentAttributes(json, context, builder); - - ObjectNode ingressJson = nullIsIllegal(get(json, INGRESS_POINT), - INGRESS_POINT + IntentCodec.MISSING_MEMBER_MESSAGE); - ConnectPoint ingress = context.codec(ConnectPoint.class) - .decode(ingressJson, context); - builder.ingressPoint(ingress); - - ObjectNode egressJson = nullIsIllegal(get(json, EGRESS_POINT), - EGRESS_POINT + IntentCodec.MISSING_MEMBER_MESSAGE); - ConnectPoint egress = context.codec(ConnectPoint.class) - .decode(egressJson, context); - builder.egressPoint(egress); - - return builder.build(); - } -} diff --git a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/PortCodec.java b/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/PortCodec.java deleted file mode 100644 index c6f2ac76..00000000 --- a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/PortCodec.java +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright 2014-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.codec.impl; - -import com.fasterxml.jackson.databind.node.ObjectNode; - -import org.onlab.packet.ChassisId; -import org.onosproject.codec.CodecContext; -import org.onosproject.net.Annotations; -import org.onosproject.net.DefaultAnnotations; -import org.onosproject.net.DefaultPort; -import org.onosproject.net.Device; -import org.onosproject.net.DeviceId; -import org.onosproject.net.Port; -import org.onosproject.net.Port.Type; -import org.onosproject.net.PortNumber; -import org.onosproject.net.provider.ProviderId; - -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * Device port JSON codec. - */ -public final class PortCodec extends AnnotatedCodec<Port> { - - // JSON field names - private static final String ELEMENT = "element"; // DeviceId - private static final String PORT_NAME = "port"; - private static final String IS_ENABLED = "isEnabled"; - private static final String TYPE = "type"; - private static final String PORT_SPEED = "portSpeed"; - - // Special port name alias - private static final String PORT_NAME_LOCAL = "local"; - - @Override - public ObjectNode encode(Port port, CodecContext context) { - checkNotNull(port, "Port cannot be null"); - ObjectNode result = context.mapper().createObjectNode() - .put(ELEMENT, port.element().id().toString()) - .put(PORT_NAME, portName(port.number())) - .put(IS_ENABLED, port.isEnabled()) - .put(TYPE, port.type().toString().toLowerCase()) - .put(PORT_SPEED, port.portSpeed()); - return annotate(result, port, context); - } - - private String portName(PortNumber port) { - return port.equals(PortNumber.LOCAL) ? PORT_NAME_LOCAL : port.toString(); - } - - private static PortNumber portNumber(String portName) { - if (portName.equalsIgnoreCase(PORT_NAME_LOCAL)) { - return PortNumber.LOCAL; - } - - return PortNumber.portNumber(portName); - } - - - /** - * {@inheritDoc} - * - * Note: Result of {@link Port#element()} returned Port object, - * is not a full Device object. - * Only it's DeviceId can be used. - */ - @Override - public Port decode(ObjectNode json, CodecContext context) { - if (json == null || !json.isObject()) { - return null; - } - - DeviceId did = DeviceId.deviceId(json.get(ELEMENT).asText()); - Device device = new DummyDevice(did); - PortNumber number = portNumber(json.get(PORT_NAME).asText()); - boolean isEnabled = json.get(IS_ENABLED).asBoolean(); - Type type = Type.valueOf(json.get(TYPE).asText().toUpperCase()); - long portSpeed = json.get(PORT_SPEED).asLong(); - Annotations annotations = extractAnnotations(json, context); - - return new DefaultPort(device, number, isEnabled, type, portSpeed, annotations); - } - - - /** - * Dummy Device which only holds DeviceId. - */ - private static final class DummyDevice implements Device { - - private final DeviceId did; - - /** - * Constructs Dummy Device which only holds DeviceId. - * - * @param did device Id - */ - public DummyDevice(DeviceId did) { - this.did = did; - } - - @Override - public Annotations annotations() { - return DefaultAnnotations.EMPTY; - } - - @Override - public ProviderId providerId() { - return new ProviderId(did.uri().getScheme(), "PortCodec"); - } - - @Override - public DeviceId id() { - return did; - } - - @Override - public Type type() { - return Type.SWITCH; - } - - @Override - public String manufacturer() { - return "dummy"; - } - - @Override - public String hwVersion() { - return "0"; - } - - @Override - public String swVersion() { - return "0"; - } - - @Override - public String serialNumber() { - return "0"; - } - - @Override - public ChassisId chassisId() { - return new ChassisId(); - } - } -} diff --git a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/PortStatisticsCodec.java b/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/PortStatisticsCodec.java deleted file mode 100644 index e8b3c4c6..00000000 --- a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/PortStatisticsCodec.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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.codec.impl; - -import org.onosproject.codec.CodecContext; -import org.onosproject.codec.JsonCodec; -import org.onosproject.net.device.PortStatistics; - -import com.fasterxml.jackson.databind.node.ObjectNode; - -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * Port statistics entry JSON codec. - */ -public final class PortStatisticsCodec extends JsonCodec<PortStatistics> { - - @Override - public ObjectNode encode(PortStatistics entry, CodecContext context) { - checkNotNull(entry, "Port Statistics cannot be null"); - - final ObjectNode result = context.mapper().createObjectNode() - .put("port", entry.port()) - .put("packetsReceived", entry.packetsReceived()) - .put("packetsSent", entry.packetsSent()) - .put("bytesReceived", entry.bytesReceived()) - .put("bytesSent", entry.bytesSent()) - .put("packetsRxDropped", entry.packetsRxDropped()) - .put("packetsTxDropped", entry.packetsTxDropped()) - .put("packetsRxErrors", entry.packetsRxErrors()) - .put("packetsTxErrors", entry.packetsTxErrors()) - .put("durationSec", entry.durationSec()); - - return result; - } - -} - diff --git a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/TableStatisticsEntryCodec.java b/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/TableStatisticsEntryCodec.java deleted file mode 100644 index 7834ceb1..00000000 --- a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/TableStatisticsEntryCodec.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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.codec.impl; - -import org.onosproject.codec.CodecContext; -import org.onosproject.codec.JsonCodec; -import org.onosproject.net.flow.TableStatisticsEntry; - -import com.fasterxml.jackson.databind.node.ObjectNode; - -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * Table statistics entry JSON codec. - */ -public final class TableStatisticsEntryCodec extends JsonCodec<TableStatisticsEntry> { - - @Override - public ObjectNode encode(TableStatisticsEntry entry, CodecContext context) { - checkNotNull(entry, "Table Statistics entry cannot be null"); - - final ObjectNode result = context.mapper().createObjectNode() - .put("tableId", entry.tableId()) - .put("deviceId", entry.deviceId().toString()) - .put("activeEntries", entry.activeFlowEntries()) - .put("packetsLookedUp", entry.packetsLookedup()) - .put("packetsMatched", entry.packetsMatched()); - - return result; - } - -} - diff --git a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/TopologyClusterCodec.java b/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/TopologyClusterCodec.java deleted file mode 100644 index dc4c79a7..00000000 --- a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/TopologyClusterCodec.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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.codec.impl; - -import org.onosproject.codec.CodecContext; -import org.onosproject.codec.JsonCodec; -import org.onosproject.net.topology.TopologyCluster; - -import com.fasterxml.jackson.databind.node.ObjectNode; - -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * Topology cluster JSON codec. - */ -public final class TopologyClusterCodec extends JsonCodec<TopologyCluster> { - - @Override - public ObjectNode encode(TopologyCluster cluster, CodecContext context) { - checkNotNull(cluster, "Cluster cannot be null"); - - return context.mapper().createObjectNode() - .put("id", cluster.id().index()) - .put("deviceCount", cluster.deviceCount()) - .put("linkCount", cluster.linkCount()) - .put("root", cluster.root().toString()); - } -} diff --git a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/TopologyCodec.java b/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/TopologyCodec.java deleted file mode 100644 index f6529eb5..00000000 --- a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/TopologyCodec.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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.codec.impl; - -import org.onosproject.codec.CodecContext; -import org.onosproject.codec.JsonCodec; -import org.onosproject.net.topology.Topology; - -import com.fasterxml.jackson.databind.node.ObjectNode; - -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * Topology JSON codec. - */ -public final class TopologyCodec extends JsonCodec<Topology> { - - @Override - public ObjectNode encode(Topology topology, CodecContext context) { - checkNotNull(topology, "Topology cannot be null"); - - return context.mapper().createObjectNode() - .put("time", topology.time()) - .put("devices", topology.deviceCount()) - .put("links", topology.linkCount()) - .put("clusters", topology.clusterCount()); - } -} diff --git a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/TrafficSelectorCodec.java b/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/TrafficSelectorCodec.java deleted file mode 100644 index 24ebef1a..00000000 --- a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/TrafficSelectorCodec.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2014-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.codec.impl; - -import java.util.stream.IntStream; - -import org.onosproject.codec.CodecContext; -import org.onosproject.codec.JsonCodec; -import org.onosproject.net.flow.DefaultTrafficSelector; -import org.onosproject.net.flow.TrafficSelector; -import org.onosproject.net.flow.criteria.Criterion; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.node.ObjectNode; - -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * Traffic selector codec. - */ -public final class TrafficSelectorCodec extends JsonCodec<TrafficSelector> { - private static final String CRITERIA = "criteria"; - - @Override - public ObjectNode encode(TrafficSelector selector, CodecContext context) { - checkNotNull(selector, "Traffic selector cannot be null"); - - final ObjectNode result = context.mapper().createObjectNode(); - final ArrayNode jsonCriteria = result.putArray(CRITERIA); - - if (selector.criteria() != null) { - final JsonCodec<Criterion> criterionCodec = - context.codec(Criterion.class); - for (final Criterion criterion : selector.criteria()) { - jsonCriteria.add(criterionCodec.encode(criterion, context)); - } - } - - return result; - } - - @Override - public TrafficSelector decode(ObjectNode json, CodecContext context) { - final JsonCodec<Criterion> criterionCodec = - context.codec(Criterion.class); - - JsonNode criteriaJson = json.get(CRITERIA); - TrafficSelector.Builder builder = DefaultTrafficSelector.builder(); - if (criteriaJson != null) { - IntStream.range(0, criteriaJson.size()) - .forEach(i -> builder.add( - criterionCodec.decode(get(criteriaJson, i), - context))); - } - return builder.build(); - } -} diff --git a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/TrafficTreatmentCodec.java b/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/TrafficTreatmentCodec.java deleted file mode 100644 index 0d7fb420..00000000 --- a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/TrafficTreatmentCodec.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2014-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.codec.impl; - -import java.util.stream.IntStream; - -import org.onosproject.codec.CodecContext; -import org.onosproject.codec.JsonCodec; -import org.onosproject.net.flow.DefaultTrafficTreatment; -import org.onosproject.net.flow.TrafficTreatment; -import org.onosproject.net.flow.instructions.Instruction; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.node.ObjectNode; - -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * Traffic treatment codec. - */ -public final class TrafficTreatmentCodec extends JsonCodec<TrafficTreatment> { - private static final String INSTRUCTIONS = "instructions"; - - @Override - public ObjectNode encode(TrafficTreatment treatment, CodecContext context) { - checkNotNull(treatment, "Traffic treatment cannot be null"); - - final ObjectNode result = context.mapper().createObjectNode(); - final ArrayNode jsonInstructions = result.putArray(INSTRUCTIONS); - - final JsonCodec<Instruction> instructionCodec = - context.codec(Instruction.class); - - for (final Instruction instruction : treatment.immediate()) { - jsonInstructions.add(instructionCodec.encode(instruction, context)); - } - - final ArrayNode jsonDeferred = result.putArray("deferred"); - - for (final Instruction instruction : treatment.deferred()) { - jsonDeferred.add(instructionCodec.encode(instruction, context)); - } - - return result; - } - - @Override - public TrafficTreatment decode(ObjectNode json, CodecContext context) { - final JsonCodec<Instruction> instructionsCodec = - context.codec(Instruction.class); - - JsonNode instructionsJson = json.get(INSTRUCTIONS); - TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder(); - if (instructionsJson != null) { - IntStream.range(0, instructionsJson.size()) - .forEach(i -> builder.add( - instructionsCodec.decode(get(instructionsJson, i), - context))); - } - return builder.build(); - } -} diff --git a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/package-info.java b/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/package-info.java deleted file mode 100644 index b3113e97..00000000 --- a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2014-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. - */ - -/** - * Implementations of the codec broker and built-in entity JSON codecs. - */ -package org.onosproject.codec.impl; diff --git a/framework/src/onos/core/common/src/main/java/org/onosproject/common/DefaultTopology.java b/framework/src/onos/core/common/src/main/java/org/onosproject/common/DefaultTopology.java deleted file mode 100644 index c5263ed7..00000000 --- a/framework/src/onos/core/common/src/main/java/org/onosproject/common/DefaultTopology.java +++ /dev/null @@ -1,650 +0,0 @@ -/* - * Copyright 2014-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.common; - -import com.google.common.base.Function; -import com.google.common.base.Supplier; -import com.google.common.base.Suppliers; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.ImmutableSetMultimap; -import com.google.common.collect.ImmutableSetMultimap.Builder; -import org.onlab.graph.DijkstraGraphSearch; -import org.onlab.graph.DisjointPathPair; -import org.onlab.graph.GraphPathSearch; -import org.onlab.graph.GraphPathSearch.Result; -import org.onlab.graph.SrlgGraphSearch; -import org.onlab.graph.SuurballeGraphSearch; -import org.onlab.graph.TarjanGraphSearch; -import org.onlab.graph.TarjanGraphSearch.SccResult; -import org.onosproject.net.AbstractModel; -import org.onosproject.net.ConnectPoint; -import org.onosproject.net.DefaultDisjointPath; -import org.onosproject.net.DefaultPath; -import org.onosproject.net.DeviceId; -import org.onosproject.net.DisjointPath; -import org.onosproject.net.Link; -import org.onosproject.net.Path; -import org.onosproject.net.provider.ProviderId; -import org.onosproject.net.topology.ClusterId; -import org.onosproject.net.topology.DefaultTopologyCluster; -import org.onosproject.net.topology.DefaultTopologyVertex; -import org.onosproject.net.topology.GraphDescription; -import org.onosproject.net.topology.HopCountLinkWeight; -import org.onosproject.net.topology.LinkWeight; -import org.onosproject.net.topology.Topology; -import org.onosproject.net.topology.TopologyCluster; -import org.onosproject.net.topology.TopologyEdge; -import org.onosproject.net.topology.TopologyGraph; -import org.onosproject.net.topology.TopologyVertex; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.stream.Collectors; - -import static com.google.common.base.MoreObjects.toStringHelper; -import static com.google.common.base.Preconditions.checkArgument; -import static org.onlab.graph.GraphPathSearch.ALL_PATHS; -import static org.onlab.util.Tools.isNullOrEmpty; -import static org.onosproject.core.CoreService.CORE_PROVIDER_ID; -import static org.onosproject.net.Link.State.INACTIVE; -import static org.onosproject.net.Link.Type.INDIRECT; - -/** - * Default implementation of the topology descriptor. This carries the backing - * topology data. - */ -public class DefaultTopology extends AbstractModel implements Topology { - - private static final Logger log = LoggerFactory.getLogger(DefaultTopology.class); - - private static final DijkstraGraphSearch<TopologyVertex, TopologyEdge> DIJKSTRA = new DijkstraGraphSearch<>(); - private static final TarjanGraphSearch<TopologyVertex, TopologyEdge> TARJAN = new TarjanGraphSearch<>(); - private static final SuurballeGraphSearch<TopologyVertex, TopologyEdge> SUURBALLE = new SuurballeGraphSearch<>(); - - private static LinkWeight defaultLinkWeight = null; - private static GraphPathSearch<TopologyVertex, TopologyEdge> defaultGraphPathSearch = null; - - private final long time; - private final long creationTime; - private final long computeCost; - private final TopologyGraph graph; - - private final LinkWeight hopCountWeight; - - private final Supplier<SccResult<TopologyVertex, TopologyEdge>> clusterResults; - private final Supplier<ImmutableMap<ClusterId, TopologyCluster>> clusters; - private final Supplier<ImmutableSet<ConnectPoint>> infrastructurePoints; - private final Supplier<ImmutableSetMultimap<ClusterId, ConnectPoint>> broadcastSets; - private final Function<ConnectPoint, Boolean> broadcastFunction; - private final Supplier<ClusterIndexes> clusterIndexes; - - /** - * Sets the default link-weight to be used when computing paths. If null is - * specified, the builtin default link-weight measuring hop-counts will be - * used. - * - * @param linkWeight new default link-weight - */ - public static void setDefaultLinkWeight(LinkWeight linkWeight) { - log.info("Setting new default link-weight function to {}", linkWeight); - defaultLinkWeight = linkWeight; - } - - /** - * Sets the default lpath search algorighm to be used when computing paths. - * If null is specified, the builtin default Dijkstra will be used. - * - * @param graphPathSearch new default algorithm - */ - public static void setDefaultGraphPathSearch(GraphPathSearch<TopologyVertex, TopologyEdge> graphPathSearch) { - log.info("Setting new default graph path algorithm to {}", graphPathSearch); - defaultGraphPathSearch = graphPathSearch; - } - - - /** - * Creates a topology descriptor attributed to the specified provider. - * - * @param providerId identity of the provider - * @param description data describing the new topology - * @param broadcastFunction broadcast point function - */ - public DefaultTopology(ProviderId providerId, GraphDescription description, - Function<ConnectPoint, Boolean> broadcastFunction) { - super(providerId); - this.broadcastFunction = broadcastFunction; - this.time = description.timestamp(); - this.creationTime = description.creationTime(); - - // Build the graph - this.graph = new DefaultTopologyGraph(description.vertexes(), - description.edges()); - - this.clusterResults = Suppliers.memoize(() -> searchForClusters()); - this.clusters = Suppliers.memoize(() -> buildTopologyClusters()); - - this.clusterIndexes = Suppliers.memoize(() -> buildIndexes()); - - this.hopCountWeight = new HopCountLinkWeight(graph.getVertexes().size()); - this.broadcastSets = Suppliers.memoize(() -> buildBroadcastSets()); - this.infrastructurePoints = Suppliers.memoize(() -> findInfrastructurePoints()); - this.computeCost = Math.max(0, System.nanoTime() - time); - } - - /** - * Creates a topology descriptor attributed to the specified provider. - * - * @param providerId identity of the provider - * @param description data describing the new topology - */ - public DefaultTopology(ProviderId providerId, GraphDescription description) { - this(providerId, description, null); - } - - @Override - public long time() { - return time; - } - - @Override - public long creationTime() { - return creationTime; - } - - @Override - public long computeCost() { - return computeCost; - } - - @Override - public int clusterCount() { - return clusters.get().size(); - } - - @Override - public int deviceCount() { - return graph.getVertexes().size(); - } - - @Override - public int linkCount() { - return graph.getEdges().size(); - } - - private ImmutableMap<DeviceId, TopologyCluster> clustersByDevice() { - return clusterIndexes.get().clustersByDevice; - } - - private ImmutableSetMultimap<TopologyCluster, DeviceId> devicesByCluster() { - return clusterIndexes.get().devicesByCluster; - } - - private ImmutableSetMultimap<TopologyCluster, Link> linksByCluster() { - return clusterIndexes.get().linksByCluster; - } - - /** - * Returns the backing topology graph. - * - * @return topology graph - */ - public TopologyGraph getGraph() { - return graph; - } - - /** - * Returns the set of topology clusters. - * - * @return set of clusters - */ - public Set<TopologyCluster> getClusters() { - return ImmutableSet.copyOf(clusters.get().values()); - } - - /** - * Returns the specified topology cluster. - * - * @param clusterId cluster identifier - * @return topology cluster - */ - public TopologyCluster getCluster(ClusterId clusterId) { - return clusters.get().get(clusterId); - } - - /** - * Returns the topology cluster that contains the given device. - * - * @param deviceId device identifier - * @return topology cluster - */ - public TopologyCluster getCluster(DeviceId deviceId) { - return clustersByDevice().get(deviceId); - } - - /** - * Returns the set of cluster devices. - * - * @param cluster topology cluster - * @return cluster devices - */ - public Set<DeviceId> getClusterDevices(TopologyCluster cluster) { - return devicesByCluster().get(cluster); - } - - /** - * Returns the set of cluster links. - * - * @param cluster topology cluster - * @return cluster links - */ - public Set<Link> getClusterLinks(TopologyCluster cluster) { - return linksByCluster().get(cluster); - } - - /** - * Indicates whether the given point is an infrastructure link end-point. - * - * @param connectPoint connection point - * @return true if infrastructure - */ - public boolean isInfrastructure(ConnectPoint connectPoint) { - return infrastructurePoints.get().contains(connectPoint); - } - - /** - * Indicates whether the given point is part of a broadcast set. - * - * @param connectPoint connection point - * @return true if in broadcast set - */ - public boolean isBroadcastPoint(ConnectPoint connectPoint) { - if (broadcastFunction != null) { - return broadcastFunction.apply(connectPoint); - } - - // Any non-infrastructure, i.e. edge points are assumed to be OK. - if (!isInfrastructure(connectPoint)) { - return true; - } - - // Find the cluster to which the device belongs. - TopologyCluster cluster = clustersByDevice().get(connectPoint.deviceId()); - checkArgument(cluster != null, "No cluster found for device %s", connectPoint.deviceId()); - - // If the broadcast set is null or empty, or if the point explicitly - // belongs to it, return true. - Set<ConnectPoint> points = broadcastSets.get().get(cluster.id()); - return isNullOrEmpty(points) || points.contains(connectPoint); - } - - /** - * Returns the size of the cluster broadcast set. - * - * @param clusterId cluster identifier - * @return size of the cluster broadcast set - */ - public int broadcastSetSize(ClusterId clusterId) { - return broadcastSets.get().get(clusterId).size(); - } - - /** - * Returns the set of the cluster broadcast points. - * - * @param clusterId cluster identifier - * @return set of cluster broadcast points - */ - public Set<ConnectPoint> broadcastPoints(ClusterId clusterId) { - return broadcastSets.get().get(clusterId); - } - - /** - * Returns the set of pre-computed shortest paths between source and - * destination devices. - * - * @param src source device - * @param dst destination device - * @return set of shortest paths - */ - public Set<Path> getPaths(DeviceId src, DeviceId dst) { - return getPaths(src, dst, linkWeight()); - } - - /** - * Computes on-demand the set of shortest paths between source and - * destination devices. - * - * @param src source device - * @param dst destination device - * @param weight link weight function - * @return set of shortest paths - */ - public Set<Path> getPaths(DeviceId src, DeviceId dst, LinkWeight weight) { - DefaultTopologyVertex srcV = new DefaultTopologyVertex(src); - DefaultTopologyVertex dstV = new DefaultTopologyVertex(dst); - Set<TopologyVertex> vertices = graph.getVertexes(); - if (!vertices.contains(srcV) || !vertices.contains(dstV)) { - // src or dst not part of the current graph - return ImmutableSet.of(); - } - - GraphPathSearch.Result<TopologyVertex, TopologyEdge> result = - graphPathSearch().search(graph, srcV, dstV, weight, ALL_PATHS); - ImmutableSet.Builder<Path> builder = ImmutableSet.builder(); - for (org.onlab.graph.Path<TopologyVertex, TopologyEdge> path : result.paths()) { - builder.add(networkPath(path)); - } - return builder.build(); - } - - /** - * /** - * Returns the set of pre-computed shortest disjoint path pairs between source and - * destination devices. - * - * @param src source device - * @param dst destination device - * @return set of shortest disjoint path pairs - */ - public Set<DisjointPath> getDisjointPaths(DeviceId src, DeviceId dst) { - return getDisjointPaths(src, dst, linkWeight()); - } - - /** - * Computes on-demand the set of shortest disjoint path pairs between source and - * destination devices. - * - * @param src source device - * @param dst destination device - * @param weight link weight function - * @return set of disjoint shortest path pairs - */ - public Set<DisjointPath> getDisjointPaths(DeviceId src, DeviceId dst, LinkWeight weight) { - DefaultTopologyVertex srcV = new DefaultTopologyVertex(src); - DefaultTopologyVertex dstV = new DefaultTopologyVertex(dst); - Set<TopologyVertex> vertices = graph.getVertexes(); - if (!vertices.contains(srcV) || !vertices.contains(dstV)) { - // src or dst not part of the current graph - return ImmutableSet.of(); - } - - GraphPathSearch.Result<TopologyVertex, TopologyEdge> result = - SUURBALLE.search(graph, srcV, dstV, weight, ALL_PATHS); - ImmutableSet.Builder<DisjointPath> builder = ImmutableSet.builder(); - for (org.onlab.graph.Path<TopologyVertex, TopologyEdge> path : result.paths()) { - builder.add(networkDisjointPath((org.onlab.graph.DisjointPathPair<TopologyVertex, TopologyEdge>) path)); - } - return builder.build(); - } - - /** - * Computes on-demand the set of shortest disjoint risk groups path pairs between source and - * destination devices. - * - * @param src source device - * @param dst destination device - * @param weight edge weight object - * @param riskProfile map representing risk groups for each edge - * @return set of shortest disjoint paths - */ - private Set<DisjointPath> disjointPaths(DeviceId src, DeviceId dst, LinkWeight weight, - Map<TopologyEdge, Object> riskProfile) { - DefaultTopologyVertex srcV = new DefaultTopologyVertex(src); - DefaultTopologyVertex dstV = new DefaultTopologyVertex(dst); - - Set<TopologyVertex> vertices = graph.getVertexes(); - if (!vertices.contains(srcV) || !vertices.contains(dstV)) { - // src or dst not part of the current graph - return ImmutableSet.of(); - } - - SrlgGraphSearch<TopologyVertex, TopologyEdge> srlg = new SrlgGraphSearch<>(riskProfile); - GraphPathSearch.Result<TopologyVertex, TopologyEdge> result = - srlg.search(graph, srcV, dstV, weight, ALL_PATHS); - ImmutableSet.Builder<DisjointPath> builder = ImmutableSet.builder(); - for (org.onlab.graph.Path<TopologyVertex, TopologyEdge> path : result.paths()) { - builder.add(networkDisjointPath((org.onlab.graph.DisjointPathPair<TopologyVertex, TopologyEdge>) path)); - } - return builder.build(); - } - - /** - * Computes on-demand the set of shortest disjoint risk groups path pairs between source and - * destination devices. - * - * @param src source device - * @param dst destination device - * @param weight edge weight object - * @param riskProfile map representing risk groups for each link - * @return set of shortest disjoint paths - */ - public Set<DisjointPath> getDisjointPaths(DeviceId src, DeviceId dst, LinkWeight weight, - Map<Link, Object> riskProfile) { - Map<TopologyEdge, Object> riskProfile2 = new HashMap<>(); - for (Link l : riskProfile.keySet()) { - riskProfile2.put(new TopologyEdge() { - Link cur = l; - - public Link link() { - return cur; - } - - public TopologyVertex src() { - return () -> src; - } - - public TopologyVertex dst() { - return () -> dst; - } - }, riskProfile.get(l)); - } - return disjointPaths(src, dst, weight, riskProfile2); - } - - /** - * Computes on-demand the set of shortest disjoint risk groups path pairs between source and - * destination devices. - * - * @param src source device - * @param dst destination device - * @param riskProfile map representing risk groups for each link - * @return set of shortest disjoint paths - */ - public Set<DisjointPath> getDisjointPaths(DeviceId src, DeviceId dst, Map<Link, Object> riskProfile) { - return getDisjointPaths(src, dst, linkWeight(), riskProfile); - } - - // Converts graph path to a network path with the same cost. - private Path networkPath(org.onlab.graph.Path<TopologyVertex, TopologyEdge> path) { - List<Link> links = path.edges().stream().map(TopologyEdge::link).collect(Collectors.toList()); - return new DefaultPath(CORE_PROVIDER_ID, links, path.cost()); - } - - private DisjointPath networkDisjointPath(DisjointPathPair<TopologyVertex, TopologyEdge> path) { - return new DefaultDisjointPath(CORE_PROVIDER_ID, - (DefaultPath) networkPath(path.primary()), - (DefaultPath) networkPath(path.secondary())); - } - - // Searches for SCC clusters in the network topology graph using Tarjan - // algorithm. - private SccResult<TopologyVertex, TopologyEdge> searchForClusters() { - return TARJAN.search(graph, new NoIndirectLinksWeight()); - } - - // Builds the topology clusters and returns the id-cluster bindings. - private ImmutableMap<ClusterId, TopologyCluster> buildTopologyClusters() { - ImmutableMap.Builder<ClusterId, TopologyCluster> clusterBuilder = ImmutableMap.builder(); - SccResult<TopologyVertex, TopologyEdge> results = clusterResults.get(); - - // Extract both vertexes and edges from the results; the lists form - // pairs along the same index. - List<Set<TopologyVertex>> clusterVertexes = results.clusterVertexes(); - List<Set<TopologyEdge>> clusterEdges = results.clusterEdges(); - - // Scan over the lists and create a cluster from the results. - for (int i = 0, n = results.clusterCount(); i < n; i++) { - Set<TopologyVertex> vertexSet = clusterVertexes.get(i); - Set<TopologyEdge> edgeSet = clusterEdges.get(i); - - ClusterId cid = ClusterId.clusterId(i); - DefaultTopologyCluster cluster = new DefaultTopologyCluster(cid, - vertexSet.size(), - edgeSet.size(), - findRoot(vertexSet)); - clusterBuilder.put(cid, cluster); - } - return clusterBuilder.build(); - } - - // Finds the vertex whose device id is the lexicographical minimum in the - // specified set. - private TopologyVertex findRoot(Set<TopologyVertex> vertexSet) { - TopologyVertex minVertex = null; - for (TopologyVertex vertex : vertexSet) { - if ((minVertex == null) || (minVertex.deviceId() - .toString().compareTo(minVertex.deviceId().toString()) < 0)) { - minVertex = vertex; - } - } - return minVertex; - } - - // Processes a map of broadcast sets for each cluster. - private ImmutableSetMultimap<ClusterId, ConnectPoint> buildBroadcastSets() { - Builder<ClusterId, ConnectPoint> builder = ImmutableSetMultimap.builder(); - for (TopologyCluster cluster : clusters.get().values()) { - addClusterBroadcastSet(cluster, builder); - } - return builder.build(); - } - - // Finds all broadcast points for the cluster. These are those connection - // points which lie along the shortest paths between the cluster root and - // all other devices within the cluster. - private void addClusterBroadcastSet(TopologyCluster cluster, Builder<ClusterId, ConnectPoint> builder) { - // Use the graph root search results to build the broadcast set. - Result<TopologyVertex, TopologyEdge> result = DIJKSTRA.search(graph, cluster.root(), null, hopCountWeight, 1); - for (Map.Entry<TopologyVertex, Set<TopologyEdge>> entry : result.parents().entrySet()) { - TopologyVertex vertex = entry.getKey(); - - // Ignore any parents that lead outside the cluster. - if (clustersByDevice().get(vertex.deviceId()) != cluster) { - continue; - } - - // Ignore any back-link sets that are empty. - Set<TopologyEdge> parents = entry.getValue(); - if (parents.isEmpty()) { - continue; - } - - // Use the first back-link source and destinations to add to the - // broadcast set. - Link link = parents.iterator().next().link(); - builder.put(cluster.id(), link.src()); - builder.put(cluster.id(), link.dst()); - } - } - - // Collects and returns an set of all infrastructure link end-points. - private ImmutableSet<ConnectPoint> findInfrastructurePoints() { - ImmutableSet.Builder<ConnectPoint> builder = ImmutableSet.builder(); - for (TopologyEdge edge : graph.getEdges()) { - builder.add(edge.link().src()); - builder.add(edge.link().dst()); - } - return builder.build(); - } - - // Builds cluster-devices, cluster-links and device-cluster indexes. - private ClusterIndexes buildIndexes() { - // Prepare the index builders - ImmutableMap.Builder<DeviceId, TopologyCluster> clusterBuilder = - ImmutableMap.builder(); - ImmutableSetMultimap.Builder<TopologyCluster, DeviceId> devicesBuilder = - ImmutableSetMultimap.builder(); - ImmutableSetMultimap.Builder<TopologyCluster, Link> linksBuilder = - ImmutableSetMultimap.builder(); - - // Now scan through all the clusters - for (TopologyCluster cluster : clusters.get().values()) { - int i = cluster.id().index(); - - // Scan through all the cluster vertexes. - for (TopologyVertex vertex : clusterResults.get().clusterVertexes().get(i)) { - devicesBuilder.put(cluster, vertex.deviceId()); - clusterBuilder.put(vertex.deviceId(), cluster); - } - - // Scan through all the cluster edges. - for (TopologyEdge edge : clusterResults.get().clusterEdges().get(i)) { - linksBuilder.put(cluster, edge.link()); - } - } - - // Finalize all indexes. - return new ClusterIndexes(clusterBuilder.build(), - devicesBuilder.build(), - linksBuilder.build()); - } - - private GraphPathSearch<TopologyVertex, TopologyEdge> graphPathSearch() { - return defaultGraphPathSearch != null ? defaultGraphPathSearch : DIJKSTRA; - } - - private LinkWeight linkWeight() { - return defaultLinkWeight != null ? defaultLinkWeight : hopCountWeight; - } - - // Link weight for preventing traversal over indirect links. - private static class NoIndirectLinksWeight implements LinkWeight { - @Override - public double weight(TopologyEdge edge) { - return (edge.link().state() == INACTIVE) - || (edge.link().type() == INDIRECT) ? -1 : 1; - } - } - - static final class ClusterIndexes { - final ImmutableMap<DeviceId, TopologyCluster> clustersByDevice; - final ImmutableSetMultimap<TopologyCluster, DeviceId> devicesByCluster; - final ImmutableSetMultimap<TopologyCluster, Link> linksByCluster; - - public ClusterIndexes(ImmutableMap<DeviceId, TopologyCluster> clustersByDevice, - ImmutableSetMultimap<TopologyCluster, DeviceId> devicesByCluster, - ImmutableSetMultimap<TopologyCluster, Link> linksByCluster) { - this.clustersByDevice = clustersByDevice; - this.devicesByCluster = devicesByCluster; - this.linksByCluster = linksByCluster; - } - } - - @Override - public String toString() { - return toStringHelper(this) - .add("time", time) - .add("creationTime", creationTime) - .add("computeCost", computeCost) - .add("clusters", clusterCount()) - .add("devices", deviceCount()) - .add("links", linkCount()).toString(); - } -} diff --git a/framework/src/onos/core/common/src/main/java/org/onosproject/common/DefaultTopologyGraph.java b/framework/src/onos/core/common/src/main/java/org/onosproject/common/DefaultTopologyGraph.java deleted file mode 100644 index b06065e7..00000000 --- a/framework/src/onos/core/common/src/main/java/org/onosproject/common/DefaultTopologyGraph.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2014 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.common; - -import org.onlab.graph.AdjacencyListsGraph; -import org.onosproject.net.topology.TopologyEdge; -import org.onosproject.net.topology.TopologyGraph; -import org.onosproject.net.topology.TopologyVertex; - -import java.util.Set; - -/** - * Default implementation of an immutable topology graph based on a generic - * implementation of adjacency lists graph. - */ -public class DefaultTopologyGraph - extends AdjacencyListsGraph<TopologyVertex, TopologyEdge> - implements TopologyGraph { - - /** - * Creates a topology graph comprising of the specified vertexes and edges. - * - * @param vertexes set of graph vertexes - * @param edges set of graph edges - */ - public DefaultTopologyGraph(Set<TopologyVertex> vertexes, Set<TopologyEdge> edges) { - super(vertexes, edges); - } - -} diff --git a/framework/src/onos/core/common/src/main/java/org/onosproject/common/app/ApplicationArchive.java b/framework/src/onos/core/common/src/main/java/org/onosproject/common/app/ApplicationArchive.java deleted file mode 100644 index 37cdbdfc..00000000 --- a/framework/src/onos/core/common/src/main/java/org/onosproject/common/app/ApplicationArchive.java +++ /dev/null @@ -1,437 +0,0 @@ -/* - * 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.common.app; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Lists; -import com.google.common.io.ByteStreams; -import com.google.common.io.Files; -import org.apache.commons.configuration.ConfigurationException; -import org.apache.commons.configuration.HierarchicalConfiguration; -import org.apache.commons.configuration.XMLConfiguration; -import org.onlab.util.Tools; -import org.onosproject.app.ApplicationDescription; -import org.onosproject.app.ApplicationEvent; -import org.onosproject.app.ApplicationException; -import org.onosproject.app.ApplicationStoreDelegate; -import org.onosproject.app.DefaultApplicationDescription; -import org.onosproject.core.ApplicationRole; -import org.onosproject.core.Version; -import org.onosproject.security.AppPermission; -import org.onosproject.security.Permission; -import org.onosproject.store.AbstractStore; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.nio.charset.Charset; -import java.nio.file.NoSuchFileException; -import java.util.List; -import java.util.Locale; -import java.util.Set; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; - -import static com.google.common.base.Preconditions.checkState; -import static com.google.common.io.ByteStreams.toByteArray; -import static com.google.common.io.Files.createParentDirs; -import static com.google.common.io.Files.write; - -/** - * Facility for reading application archive stream and managing application - * directory structure. - */ -public class ApplicationArchive - extends AbstractStore<ApplicationEvent, ApplicationStoreDelegate> { - - private static Logger log = LoggerFactory.getLogger(ApplicationArchive.class); - - // Magic strings to search for at the beginning of the archive stream - private static final String XML_MAGIC = "<?xml "; - - // Magic strings to search for and how deep to search it into the archive stream - private static final String APP_MAGIC = "<app "; - private static final int APP_MAGIC_DEPTH = 1024; - - private static final String NAME = "[@name]"; - private static final String ORIGIN = "[@origin]"; - private static final String VERSION = "[@version]"; - private static final String FEATURES_REPO = "[@featuresRepo]"; - private static final String FEATURES = "[@features]"; - private static final String APPS = "[@apps]"; - private static final String DESCRIPTION = "description"; - - private static final String ROLE = "security.role"; - private static final String APP_PERMISSIONS = "security.permissions.app-perm"; - private static final String NET_PERMISSIONS = "security.permissions.net-perm"; - private static final String JAVA_PERMISSIONS = "security.permissions.java-perm"; - - private static final String OAR = ".oar"; - private static final String APP_XML = "app.xml"; - private static final String M2_PREFIX = "m2"; - - private static final String ROOT = "../"; - private static final String M2_ROOT = "system/"; - private static final String APPS_ROOT = "apps/"; - - private File root = new File(ROOT); - private File appsDir = new File(root, APPS_ROOT); - private File m2Dir = new File(M2_ROOT); - - /** - * Sets the root directory where apps directory is contained. - * - * @param root top-level directory path - */ - protected void setRootPath(String root) { - this.root = new File(root); - this.appsDir = new File(this.root, APPS_ROOT); - this.m2Dir = new File(M2_ROOT); - } - - /** - * Returns the root directory where apps directory is contained. - * - * @return top-level directory path - */ - public String getRootPath() { - return root.getPath(); - } - - /** - * Returns the set of installed application names. - * - * @return installed application names - */ - public Set<String> getApplicationNames() { - ImmutableSet.Builder<String> names = ImmutableSet.builder(); - File[] files = appsDir.listFiles(File::isDirectory); - if (files != null) { - for (File file : files) { - names.add(file.getName()); - } - } - return names.build(); - } - - /** - * Returns the timestamp in millis since start of epoch, of when the - * specified application was last modified or changed state. - * - * @param appName application name - * @return number of millis since start of epoch - */ - public long getUpdateTime(String appName) { - return appFile(appName, APP_XML).lastModified(); - } - - /** - * Loads the application descriptor from the specified application archive - * stream and saves the stream in the appropriate application archive - * directory. - * - * @param appName application name - * @return application descriptor - * @throws org.onosproject.app.ApplicationException if unable to read application description - */ - public ApplicationDescription getApplicationDescription(String appName) { - try { - XMLConfiguration cfg = new XMLConfiguration(); - cfg.setAttributeSplittingDisabled(true); - cfg.setDelimiterParsingDisabled(true); - cfg.load(appFile(appName, APP_XML)); - return loadAppDescription(cfg); - } catch (Exception e) { - throw new ApplicationException("Unable to get app description", e); - } - } - - /** - * Loads the application descriptor from the specified application archive - * stream and saves the stream in the appropriate application archive - * directory. - * - * @param stream application archive stream - * @return application descriptor - * @throws org.onosproject.app.ApplicationException if unable to read the - * archive stream or store - * the application archive - */ - public synchronized ApplicationDescription saveApplication(InputStream stream) { - try (InputStream ais = stream) { - byte[] cache = toByteArray(ais); - InputStream bis = new ByteArrayInputStream(cache); - - boolean plainXml = isPlainXml(cache); - ApplicationDescription desc = plainXml ? - parsePlainAppDescription(bis) : parseZippedAppDescription(bis); - checkState(!appFile(desc.name(), APP_XML).exists(), - "Application %s already installed", desc.name()); - - if (plainXml) { - expandPlainApplication(cache, desc); - } else { - bis.reset(); - expandZippedApplication(bis, desc); - - bis.reset(); - saveApplication(bis, desc); - } - - installArtifacts(desc); - return desc; - } catch (IOException e) { - throw new ApplicationException("Unable to save application", e); - } - } - - // Indicates whether the stream encoded in the given bytes is plain XML. - private boolean isPlainXml(byte[] bytes) { - return substring(bytes, XML_MAGIC.length()).equals(XML_MAGIC) || - substring(bytes, APP_MAGIC_DEPTH).contains(APP_MAGIC); - } - - // Returns the substring of maximum possible length from the specified bytes. - private String substring(byte[] bytes, int length) { - return new String(bytes, 0, Math.min(bytes.length, length), Charset.forName("UTF-8")); - } - - /** - * Purges the application archive directory. - * - * @param appName application name - */ - public synchronized void purgeApplication(String appName) { - File appDir = new File(appsDir, appName); - try { - Tools.removeDirectory(appDir); - } catch (IOException e) { - throw new ApplicationException("Unable to purge application " + appName, e); - } - if (appDir.exists()) { - throw new ApplicationException("Unable to purge application " + appName); - } - } - - /** - * Returns application archive stream for the specified application. This - * will be either the application ZIP file or the application XML file. - * - * @param appName application name - * @return application archive stream - */ - public synchronized InputStream getApplicationInputStream(String appName) { - try { - File appFile = appFile(appName, appName + OAR); - return new FileInputStream(appFile.exists() ? appFile : appFile(appName, APP_XML)); - } catch (FileNotFoundException e) { - throw new ApplicationException("Application " + appName + " not found"); - } - } - - // Scans the specified ZIP stream for app.xml entry and parses it producing - // an application descriptor. - private ApplicationDescription parseZippedAppDescription(InputStream stream) - throws IOException { - try (ZipInputStream zis = new ZipInputStream(stream)) { - ZipEntry entry; - while ((entry = zis.getNextEntry()) != null) { - if (entry.getName().equals(APP_XML)) { - byte[] data = ByteStreams.toByteArray(zis); - return parsePlainAppDescription(new ByteArrayInputStream(data)); - } - zis.closeEntry(); - } - } - throw new IOException("Unable to locate " + APP_XML); - } - - // Scans the specified XML stream and parses it producing an application descriptor. - private ApplicationDescription parsePlainAppDescription(InputStream stream) - throws IOException { - XMLConfiguration cfg = new XMLConfiguration(); - cfg.setAttributeSplittingDisabled(true); - cfg.setDelimiterParsingDisabled(true); - try { - cfg.load(stream); - return loadAppDescription(cfg); - } catch (ConfigurationException e) { - throw new IOException("Unable to parse " + APP_XML, e); - } - } - - private ApplicationDescription loadAppDescription(XMLConfiguration cfg) { - String name = cfg.getString(NAME); - Version version = Version.version(cfg.getString(VERSION)); - String desc = cfg.getString(DESCRIPTION); - String origin = cfg.getString(ORIGIN); - ApplicationRole role = getRole(cfg.getString(ROLE)); - Set<Permission> perms = getPermissions(cfg); - String featRepo = cfg.getString(FEATURES_REPO); - URI featuresRepo = featRepo != null ? URI.create(featRepo) : null; - List<String> features = ImmutableList.copyOf(cfg.getString(FEATURES).split(",")); - - String apps = cfg.getString(APPS, ""); - List<String> requiredApps = apps.isEmpty() ? - ImmutableList.of() : ImmutableList.copyOf(apps.split(",")); - - return new DefaultApplicationDescription(name, version, desc, origin, role, - perms, featuresRepo, features, - requiredApps); - } - - // Expands the specified ZIP stream into app-specific directory. - private void expandZippedApplication(InputStream stream, ApplicationDescription desc) - throws IOException { - ZipInputStream zis = new ZipInputStream(stream); - ZipEntry entry; - File appDir = new File(appsDir, desc.name()); - while ((entry = zis.getNextEntry()) != null) { - if (!entry.isDirectory()) { - byte[] data = ByteStreams.toByteArray(zis); - zis.closeEntry(); - File file = new File(appDir, entry.getName()); - createParentDirs(file); - write(data, file); - } - } - zis.close(); - } - - // Saves the specified XML stream into app-specific directory. - private void expandPlainApplication(byte[] stream, ApplicationDescription desc) - throws IOException { - File file = appFile(desc.name(), APP_XML); - checkState(!file.getParentFile().exists(), "Application already installed"); - createParentDirs(file); - write(stream, file); - } - - - // Saves the specified ZIP stream into a file under app-specific directory. - private void saveApplication(InputStream stream, ApplicationDescription desc) - throws IOException { - Files.write(toByteArray(stream), appFile(desc.name(), desc.name() + OAR)); - } - - // Installs application artifacts into M2 repository. - private void installArtifacts(ApplicationDescription desc) throws IOException { - try { - Tools.copyDirectory(appFile(desc.name(), M2_PREFIX), m2Dir); - } catch (NoSuchFileException e) { - log.debug("Application {} has no M2 artifacts", desc.name()); - } - } - - /** - * Marks the app as active by creating token file in the app directory. - * - * @param appName application name - * @return true if file was created - */ - protected boolean setActive(String appName) { - try { - return appFile(appName, "active").createNewFile() && updateTime(appName); - } catch (IOException e) { - throw new ApplicationException("Unable to mark app as active", e); - } - } - - /** - * Clears the app as active by deleting token file in the app directory. - * - * @param appName application name - * @return true if file was deleted - */ - protected boolean clearActive(String appName) { - return appFile(appName, "active").delete() && updateTime(appName); - } - - /** - * Updates the time-stamp of the app descriptor file. - * - * @param appName application name - * @return true if the app descriptor was updated - */ - protected boolean updateTime(String appName) { - return appFile(appName, APP_XML).setLastModified(System.currentTimeMillis()); - } - - /** - * Indicates whether the app was marked as active by checking for token file. - * - * @param appName application name - * @return true if the app is marked as active - */ - protected boolean isActive(String appName) { - return appFile(appName, "active").exists(); - } - - - // Returns the name of the file located under the specified app directory. - private File appFile(String appName, String fileName) { - return new File(new File(appsDir, appName), fileName); - } - - // Returns the set of Permissions specified in the app.xml file - private ImmutableSet<Permission> getPermissions(XMLConfiguration cfg) { - List<Permission> permissionList = Lists.newArrayList(); - - for (Object o : cfg.getList(APP_PERMISSIONS)) { - String name = (String) o; - permissionList.add(new Permission(AppPermission.class.getName(), name)); - } - for (Object o : cfg.getList(NET_PERMISSIONS)) { - //TODO: TO BE FLESHED OUT WHEN NETWORK PERMISSIONS ARE SUPPORTED - break; - } - - List<HierarchicalConfiguration> fields = - cfg.configurationsAt(JAVA_PERMISSIONS); - for (HierarchicalConfiguration sub : fields) { - String classname = sub.getString("classname"); - String name = sub.getString("name"); - String actions = sub.getString("actions"); - - if (classname != null && name != null) { - permissionList.add(new Permission(classname, name, actions)); - } - } - return ImmutableSet.copyOf(permissionList); - } - - // - // Returns application role type - public ApplicationRole getRole(String value) { - if (value == null) { - return ApplicationRole.UNSPECIFIED; - } else { - try { - return ApplicationRole.valueOf(value.toUpperCase(Locale.ENGLISH)); - } catch (IllegalArgumentException e) { - log.debug("Unknown role value: %s", value); - return ApplicationRole.UNSPECIFIED; - } - } - } -} diff --git a/framework/src/onos/core/common/src/main/java/org/onosproject/common/app/package-info.java b/framework/src/onos/core/common/src/main/java/org/onosproject/common/app/package-info.java deleted file mode 100644 index 898bad7b..00000000 --- a/framework/src/onos/core/common/src/main/java/org/onosproject/common/app/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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. - */ - -/** - * Common facilities for construction of application management subsystem. - */ -package org.onosproject.common.app;
\ No newline at end of file diff --git a/framework/src/onos/core/common/src/main/java/org/onosproject/common/package-info.java b/framework/src/onos/core/common/src/main/java/org/onosproject/common/package-info.java deleted file mode 100644 index 8cd9b8c4..00000000 --- a/framework/src/onos/core/common/src/main/java/org/onosproject/common/package-info.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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. - */ - -/** - * Miscellaneous common facilities used for construction of various core and - * app subsystems. - */ -package org.onosproject.common;
\ No newline at end of file |