[ONOS-3116] Port Chain implementation for SFC

Change-Id: I4a5fd9076c19ba502652d68e3b2cca14b269359a
diff --git a/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultPortChain.java b/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultPortChain.java
new file mode 100644
index 0000000..89b94b3
--- /dev/null
+++ b/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultPortChain.java
@@ -0,0 +1,201 @@
+/*
+ * 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.vtnrsc;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.util.List;
+import java.util.Objects;
+
+import com.google.common.collect.ImmutableList;
+
+/**
+ * Implementation of port chain.
+ */
+public final class DefaultPortChain implements PortChain {
+
+    private final PortChainId portChainId;
+    private final TenantId tenantId;
+    private final String name;
+    private final String description;
+    private final List<PortPairGroupId> portPairGroupList;
+    private final List<FlowClassifierId> flowClassifierList;
+
+    /**
+     * Default constructor to create port chain.
+     *
+     * @param portChainId port chain id
+     * @param tenantId tenant id
+     * @param name name of port chain
+     * @param description description of port chain
+     * @param portPairGroupList port pair group list
+     * @param flowClassifierList flow classifier list
+     */
+    private DefaultPortChain(PortChainId portChainId, TenantId tenantId,
+                             String name, String description,
+                             List<PortPairGroupId> portPairGroupList,
+                             List<FlowClassifierId> flowClassifierList) {
+
+        this.portChainId = portChainId;
+        this.tenantId = tenantId;
+        this.name = name;
+        this.description = description;
+        this.portPairGroupList = portPairGroupList;
+        this.flowClassifierList = flowClassifierList;
+    }
+
+    @Override
+    public PortChainId portChainId() {
+        return portChainId;
+    }
+
+    @Override
+    public TenantId tenantId() {
+        return tenantId;
+    }
+
+    @Override
+    public String name() {
+        return name;
+    }
+
+    @Override
+    public String description() {
+        return description;
+    }
+
+    @Override
+    public List<PortPairGroupId> portPairGroups() {
+        return  ImmutableList.copyOf(portPairGroupList);
+    }
+
+    @Override
+    public List<FlowClassifierId> flowClassifiers() {
+        return ImmutableList.copyOf(flowClassifierList);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(portChainId, tenantId, name, description,
+                            portPairGroupList, flowClassifierList);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj instanceof DefaultPortChain) {
+            DefaultPortChain that = (DefaultPortChain) obj;
+            return Objects.equals(portChainId, that.portChainId) &&
+                    Objects.equals(tenantId, that.tenantId) &&
+                    Objects.equals(name, that.name) &&
+                    Objects.equals(description, that.description) &&
+                    Objects.equals(portPairGroupList, that.portPairGroupList) &&
+                    Objects.equals(flowClassifierList, that.flowClassifierList);
+        }
+        return false;
+    }
+
+    @Override
+    public boolean exactMatch(PortChain portChain) {
+        return this.equals(portChain) &&
+                Objects.equals(this.portChainId, portChain.portChainId()) &&
+                Objects.equals(this.tenantId, portChain.tenantId());
+    }
+
+    @Override
+    public String toString() {
+        return toStringHelper(this)
+                .add("id", portChainId.toString())
+                .add("tenantId", tenantId.toString())
+                .add("name", name)
+                .add("description", description)
+                .add("portPairGroupList", portPairGroupList)
+                .add("flowClassifier", flowClassifierList)
+                .toString();
+    }
+
+    /**
+     * To create an instance of the builder.
+     *
+     * @return instance of builder
+     */
+    public static Builder builder() {
+        return new Builder();
+    }
+
+    /**
+     * Builder class for Port chain.
+     */
+    public static final class Builder implements PortChain.Builder {
+
+        private PortChainId portChainId;
+        private TenantId tenantId;
+        private String name;
+        private String description;
+        private List<PortPairGroupId> portPairGroupList;
+        private List<FlowClassifierId> flowClassifierList;
+
+        @Override
+        public Builder setId(PortChainId portChainId) {
+            this.portChainId = portChainId;
+            return this;
+        }
+
+        @Override
+        public Builder setTenantId(TenantId tenantId) {
+            this.tenantId = tenantId;
+            return this;
+        }
+
+        @Override
+        public Builder setName(String name) {
+            this.name = name;
+            return this;
+        }
+
+        @Override
+        public Builder setDescription(String description) {
+            this.description = description;
+            return this;
+        }
+
+        @Override
+        public Builder setPortPairGroups(List<PortPairGroupId> portPairGroups) {
+            this.portPairGroupList = portPairGroups;
+            return this;
+        }
+
+        @Override
+        public Builder setFlowClassifiers(List<FlowClassifierId> flowClassifiers) {
+            this.flowClassifierList = flowClassifiers;
+            return this;
+        }
+
+        @Override
+        public PortChain build() {
+
+            checkNotNull(portChainId, "Port chain id cannot be null");
+            checkNotNull(tenantId, "Tenant id cannot be null");
+            checkNotNull(portPairGroupList, "Port pair groups cannot be null");
+
+            return new DefaultPortChain(portChainId, tenantId, name, description,
+                                        portPairGroupList, flowClassifierList);
+        }
+    }
+}