[ONOS-6964][ONOS-6966] Add pipeconf codec and pipeconf view
Change-Id: Ie60a5451bcc24a27ede655c8230d82998ea4f3be
diff --git a/core/common/src/main/java/org/onosproject/codec/impl/CodecManager.java b/core/common/src/main/java/org/onosproject/codec/impl/CodecManager.java
index cd39d47..7a88366 100644
--- a/core/common/src/main/java/org/onosproject/codec/impl/CodecManager.java
+++ b/core/common/src/main/java/org/onosproject/codec/impl/CodecManager.java
@@ -85,6 +85,15 @@
import org.onosproject.net.meter.Meter;
import org.onosproject.net.meter.MeterRequest;
import org.onosproject.net.packet.PacketRequest;
+import org.onosproject.net.pi.model.PiActionModel;
+import org.onosproject.net.pi.model.PiActionParamModel;
+import org.onosproject.net.pi.model.PiHeaderFieldTypeModel;
+import org.onosproject.net.pi.model.PiHeaderModel;
+import org.onosproject.net.pi.model.PiHeaderTypeModel;
+import org.onosproject.net.pi.model.PiPipeconf;
+import org.onosproject.net.pi.model.PiPipelineModel;
+import org.onosproject.net.pi.model.PiTableMatchFieldModel;
+import org.onosproject.net.pi.model.PiTableModel;
import org.onosproject.net.region.Region;
import org.onosproject.net.statistic.Load;
import org.onosproject.net.topology.Topology;
@@ -176,6 +185,15 @@
registerCodec(FilteredConnectPoint.class, new FilteredConnectPointCodec());
registerCodec(TransportEndpointDescription.class, new TransportEndpointDescriptionCodec());
registerCodec(PacketRequest.class, new PacketRequestCodec());
+ registerCodec(PiActionModel.class, new PiActionModelCodec());
+ registerCodec(PiHeaderModel.class, new PiHeaderModelCodec());
+ registerCodec(PiPipelineModel.class, new PiPipelineModelCodec());
+ registerCodec(PiPipeconf.class, new PiPipeconfCodec());
+ registerCodec(PiTableModel.class, new PiTableModelCodec());
+ registerCodec(PiTableMatchFieldModel.class, new PiTableMatchFieldModelCodec());
+ registerCodec(PiHeaderFieldTypeModel.class, new PiHeaderFieldTypeModelCodec());
+ registerCodec(PiHeaderTypeModel.class, new PiHeaderTypeModelCodec());
+ registerCodec(PiActionParamModel.class, new PiActionParamModelCodec());
log.info("Started");
}
diff --git a/core/common/src/main/java/org/onosproject/codec/impl/PiActionModelCodec.java b/core/common/src/main/java/org/onosproject/codec/impl/PiActionModelCodec.java
new file mode 100644
index 0000000..10cef43
--- /dev/null
+++ b/core/common/src/main/java/org/onosproject/codec/impl/PiActionModelCodec.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.onosproject.codec.CodecContext;
+import org.onosproject.codec.JsonCodec;
+import org.onosproject.net.pi.model.PiActionModel;
+import org.onosproject.net.pi.model.PiActionParamModel;
+
+/**
+ * Codec for PiActionModel.
+ */
+public class PiActionModelCodec extends JsonCodec<PiActionModel> {
+ private static final String NAME = "name";
+ private static final String PARAMS = "params";
+
+ @Override
+ public ObjectNode encode(PiActionModel action, CodecContext context) {
+ ObjectNode result = context.mapper().createObjectNode();
+ result.put(NAME, action.name());
+ ArrayNode params = result.putArray(PARAMS);
+ action.params().forEach(param -> {
+ ObjectNode paramData = context.encode(param, PiActionParamModel.class);
+ params.add(paramData);
+ });
+ return result;
+ }
+}
diff --git a/core/common/src/main/java/org/onosproject/codec/impl/PiActionParamModelCodec.java b/core/common/src/main/java/org/onosproject/codec/impl/PiActionParamModelCodec.java
new file mode 100644
index 0000000..ac553fe
--- /dev/null
+++ b/core/common/src/main/java/org/onosproject/codec/impl/PiActionParamModelCodec.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.pi.model.PiActionParamModel;
+
+/**
+ * Codec for PiActionParamModel.
+ */
+public class PiActionParamModelCodec extends JsonCodec<PiActionParamModel> {
+
+ private static final String NAME = "name";
+ private static final String BIT_WIDTH = "bitWidth";
+
+ @Override
+ public ObjectNode encode(PiActionParamModel param, CodecContext context) {
+ ObjectNode result = context.mapper().createObjectNode();
+ result.put(NAME, param.name());
+ result.put(BIT_WIDTH, param.bitWidth());
+ return result;
+ }
+}
diff --git a/core/common/src/main/java/org/onosproject/codec/impl/PiHeaderFieldTypeModelCodec.java b/core/common/src/main/java/org/onosproject/codec/impl/PiHeaderFieldTypeModelCodec.java
new file mode 100644
index 0000000..09a1566
--- /dev/null
+++ b/core/common/src/main/java/org/onosproject/codec/impl/PiHeaderFieldTypeModelCodec.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.pi.model.PiHeaderFieldTypeModel;
+
+/**
+ * Codec for PiHeaderFieldTypeModel.
+ */
+public class PiHeaderFieldTypeModelCodec extends JsonCodec<PiHeaderFieldTypeModel> {
+ private static final String NAME = "name";
+ private static final String BIT_WIDTH = "bitWidth";
+
+ @Override
+ public ObjectNode encode(PiHeaderFieldTypeModel headerFieldType, CodecContext context) {
+ ObjectNode result = context.mapper().createObjectNode();
+ result.put(NAME, headerFieldType.name());
+ result.put(BIT_WIDTH, headerFieldType.bitWidth());
+ return result;
+ }
+}
diff --git a/core/common/src/main/java/org/onosproject/codec/impl/PiHeaderModelCodec.java b/core/common/src/main/java/org/onosproject/codec/impl/PiHeaderModelCodec.java
new file mode 100644
index 0000000..7bcd134
--- /dev/null
+++ b/core/common/src/main/java/org/onosproject/codec/impl/PiHeaderModelCodec.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.pi.model.PiHeaderModel;
+import org.onosproject.net.pi.model.PiHeaderTypeModel;
+
+/**
+ * Codec for PiHeaderModel.
+ */
+public class PiHeaderModelCodec extends JsonCodec<PiHeaderModel> {
+ private static final String NAME = "name";
+ private static final String TYPE = "type";
+ private static final String IS_META = "isMetadata";
+ private static final String INDEX = "index";
+
+ @Override
+ public ObjectNode encode(PiHeaderModel header, CodecContext context) {
+ ObjectNode result = context.mapper().createObjectNode();
+ ObjectNode headerTypeData = context.encode(header.type(), PiHeaderTypeModel.class);
+ result.put(NAME, header.name());
+ result.set(TYPE, headerTypeData);
+ result.put(IS_META, header.isMetadata());
+ result.put(INDEX, header.index());
+ return result;
+ }
+}
diff --git a/core/common/src/main/java/org/onosproject/codec/impl/PiHeaderTypeModelCodec.java b/core/common/src/main/java/org/onosproject/codec/impl/PiHeaderTypeModelCodec.java
new file mode 100644
index 0000000..1065a94
--- /dev/null
+++ b/core/common/src/main/java/org/onosproject/codec/impl/PiHeaderTypeModelCodec.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.onosproject.codec.CodecContext;
+import org.onosproject.codec.JsonCodec;
+import org.onosproject.net.pi.model.PiHeaderFieldTypeModel;
+import org.onosproject.net.pi.model.PiHeaderTypeModel;
+
+/**
+ * Codec for PiHeaderTypeModel.
+ */
+public class PiHeaderTypeModelCodec extends JsonCodec<PiHeaderTypeModel> {
+ private static final String NAME = "name";
+ private static final String FIELDS = "fields";
+
+ @Override
+ public ObjectNode encode(PiHeaderTypeModel headerType, CodecContext context) {
+ ObjectNode result = context.mapper().createObjectNode();
+ result.put(NAME, headerType.name());
+ ArrayNode fields = result.putArray(FIELDS);
+
+ headerType.fields().forEach(field -> {
+ fields.add(context.encode(field, PiHeaderFieldTypeModel.class));
+ });
+
+ return result;
+ }
+}
diff --git a/core/common/src/main/java/org/onosproject/codec/impl/PiPipeconfCodec.java b/core/common/src/main/java/org/onosproject/codec/impl/PiPipeconfCodec.java
new file mode 100644
index 0000000..a719741
--- /dev/null
+++ b/core/common/src/main/java/org/onosproject/codec/impl/PiPipeconfCodec.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.common.collect.Lists;
+import org.onosproject.codec.CodecContext;
+import org.onosproject.codec.JsonCodec;
+import org.onosproject.net.pi.model.PiPipeconf;
+
+/**
+ * Codec for PiPipeconf.
+ */
+public class PiPipeconfCodec extends JsonCodec<PiPipeconf> {
+
+ private static final String ID = "id";
+ private static final String BEHAVIORS = "behaviors";
+ private static final String EXTENSIONS = "extensions";
+
+ @Override
+ public ObjectNode encode(PiPipeconf pipeconf, CodecContext context) {
+ ObjectNode result = context.mapper().createObjectNode();
+ result.put(ID, pipeconf.id().id());
+ ArrayNode behaviors = result.putArray(BEHAVIORS);
+ pipeconf.behaviours().forEach(behavior -> {
+ behaviors.add(behavior.getSimpleName());
+ });
+ ArrayNode extensions = result.putArray(EXTENSIONS);
+ Lists.newArrayList(PiPipeconf.ExtensionType.values()).forEach(extension -> {
+ if (pipeconf.extension(extension).isPresent()) {
+ extensions.add(extension.toString());
+ }
+ });
+ return result;
+ }
+}
diff --git a/core/common/src/main/java/org/onosproject/codec/impl/PiPipelineModelCodec.java b/core/common/src/main/java/org/onosproject/codec/impl/PiPipelineModelCodec.java
new file mode 100644
index 0000000..6b42c8d
--- /dev/null
+++ b/core/common/src/main/java/org/onosproject/codec/impl/PiPipelineModelCodec.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.onosproject.codec.CodecContext;
+import org.onosproject.codec.JsonCodec;
+import org.onosproject.net.pi.model.PiActionModel;
+import org.onosproject.net.pi.model.PiHeaderModel;
+import org.onosproject.net.pi.model.PiPipelineModel;
+import org.onosproject.net.pi.model.PiTableModel;
+
+/**
+ * Codec for PiPipelineModel.
+ */
+public class PiPipelineModelCodec extends JsonCodec<PiPipelineModel> {
+ private static final String HEADERS = "headers";
+ private static final String ACTIONS = "actions";
+ private static final String TABLES = "tables";
+
+ @Override
+ public ObjectNode encode(PiPipelineModel pipeline, CodecContext context) {
+ ObjectNode result = context.mapper().createObjectNode();
+ ArrayNode headers = result.putArray(HEADERS);
+ pipeline.headers().stream()
+ .map(header -> context.encode(header, PiHeaderModel.class))
+ .forEach(headers::add);
+ ArrayNode actions = result.putArray(ACTIONS);
+ pipeline.actions().stream()
+ .map(action -> context.encode(action, PiActionModel.class))
+ .forEach(actions::add);
+ ArrayNode tables = result.putArray(TABLES);
+ pipeline.tables().stream()
+ .map(table -> context.encode(table, PiTableModel.class))
+ .forEach(tables::add);
+ return result;
+ }
+}
diff --git a/core/common/src/main/java/org/onosproject/codec/impl/PiTableMatchFieldModelCodec.java b/core/common/src/main/java/org/onosproject/codec/impl/PiTableMatchFieldModelCodec.java
new file mode 100644
index 0000000..a94bcba
--- /dev/null
+++ b/core/common/src/main/java/org/onosproject/codec/impl/PiTableMatchFieldModelCodec.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.pi.model.PiHeaderFieldTypeModel;
+import org.onosproject.net.pi.model.PiHeaderModel;
+import org.onosproject.net.pi.model.PiTableMatchFieldModel;
+
+/**
+ * Codec for PiTableMatchFieldModel.
+ */
+public class PiTableMatchFieldModelCodec extends JsonCodec<PiTableMatchFieldModel> {
+ private static final String MATCH_TYPE = "matchType";
+ private static final String HEADER = "header";
+ private static final String FIELD = "field";
+ @Override
+ public ObjectNode encode(PiTableMatchFieldModel tableMatchField, CodecContext context) {
+ ObjectNode result = context.mapper().createObjectNode();
+ result.put(MATCH_TYPE, tableMatchField.matchType().toString());
+ PiHeaderModel header = tableMatchField.field().header();
+ PiHeaderFieldTypeModel field = tableMatchField.field().type();
+ ObjectNode headerData = context.encode(header, PiHeaderModel.class);
+ ObjectNode headerFieldData = context.encode(field, PiHeaderFieldTypeModel.class);
+ result.set(HEADER, headerData);
+ result.set(FIELD, headerFieldData);
+ return result;
+ }
+}
diff --git a/core/common/src/main/java/org/onosproject/codec/impl/PiTableModelCodec.java b/core/common/src/main/java/org/onosproject/codec/impl/PiTableModelCodec.java
new file mode 100644
index 0000000..052e083
--- /dev/null
+++ b/core/common/src/main/java/org/onosproject/codec/impl/PiTableModelCodec.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.onosproject.codec.CodecContext;
+import org.onosproject.codec.JsonCodec;
+import org.onosproject.net.pi.model.PiTableMatchFieldModel;
+import org.onosproject.net.pi.model.PiTableModel;
+
+/**
+ * Codec for PiTableModel.
+ */
+public class PiTableModelCodec extends JsonCodec<PiTableModel> {
+ private static final String NAME = "name";
+ private static final String MAX_SIZE = "maxSize";
+ private static final String HAS_COUNTERS = "hasCounters";
+ private static final String SUPPORT_AGING = "supportAging";
+ private static final String ACTIONS = "actions";
+ private static final String MATCH_FIELDS = "matchFields";
+
+
+ @Override
+ public ObjectNode encode(PiTableModel table, CodecContext context) {
+
+ ObjectNode result = context.mapper().createObjectNode();
+
+ result.put(NAME, table.name());
+ result.put(MAX_SIZE, table.maxSize());
+ result.put(HAS_COUNTERS, table.hasCounters());
+ result.put(SUPPORT_AGING, table.supportsAging());
+
+ ArrayNode matchFields = result.putArray(MATCH_FIELDS);
+ table.matchFields().forEach(matchField -> {
+ ObjectNode matchFieldData =
+ context.encode(matchField, PiTableMatchFieldModel.class);
+ matchFields.add(matchFieldData);
+ });
+
+ ArrayNode actions = result.putArray(ACTIONS);
+ table.actions().forEach(action -> {
+ actions.add(action.name());
+ });
+
+ return result;
+ }
+}