Committed by
Ray Milkey
[ONOS-3116] Port Chain implementation for SFC
Change-Id: I4a5fd9076c19ba502652d68e3b2cca14b269359a
Showing
1 changed file
with
201 additions
and
0 deletions
| 1 | +/* | ||
| 2 | + * Copyright 2015 Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | +package org.onosproject.vtnrsc; | ||
| 17 | + | ||
| 18 | +import static com.google.common.base.MoreObjects.toStringHelper; | ||
| 19 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
| 20 | + | ||
| 21 | +import java.util.List; | ||
| 22 | +import java.util.Objects; | ||
| 23 | + | ||
| 24 | +import com.google.common.collect.ImmutableList; | ||
| 25 | + | ||
| 26 | +/** | ||
| 27 | + * Implementation of port chain. | ||
| 28 | + */ | ||
| 29 | +public final class DefaultPortChain implements PortChain { | ||
| 30 | + | ||
| 31 | + private final PortChainId portChainId; | ||
| 32 | + private final TenantId tenantId; | ||
| 33 | + private final String name; | ||
| 34 | + private final String description; | ||
| 35 | + private final List<PortPairGroupId> portPairGroupList; | ||
| 36 | + private final List<FlowClassifierId> flowClassifierList; | ||
| 37 | + | ||
| 38 | + /** | ||
| 39 | + * Default constructor to create port chain. | ||
| 40 | + * | ||
| 41 | + * @param portChainId port chain id | ||
| 42 | + * @param tenantId tenant id | ||
| 43 | + * @param name name of port chain | ||
| 44 | + * @param description description of port chain | ||
| 45 | + * @param portPairGroupList port pair group list | ||
| 46 | + * @param flowClassifierList flow classifier list | ||
| 47 | + */ | ||
| 48 | + private DefaultPortChain(PortChainId portChainId, TenantId tenantId, | ||
| 49 | + String name, String description, | ||
| 50 | + List<PortPairGroupId> portPairGroupList, | ||
| 51 | + List<FlowClassifierId> flowClassifierList) { | ||
| 52 | + | ||
| 53 | + this.portChainId = portChainId; | ||
| 54 | + this.tenantId = tenantId; | ||
| 55 | + this.name = name; | ||
| 56 | + this.description = description; | ||
| 57 | + this.portPairGroupList = portPairGroupList; | ||
| 58 | + this.flowClassifierList = flowClassifierList; | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + @Override | ||
| 62 | + public PortChainId portChainId() { | ||
| 63 | + return portChainId; | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + @Override | ||
| 67 | + public TenantId tenantId() { | ||
| 68 | + return tenantId; | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + @Override | ||
| 72 | + public String name() { | ||
| 73 | + return name; | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + @Override | ||
| 77 | + public String description() { | ||
| 78 | + return description; | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + @Override | ||
| 82 | + public List<PortPairGroupId> portPairGroups() { | ||
| 83 | + return ImmutableList.copyOf(portPairGroupList); | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + @Override | ||
| 87 | + public List<FlowClassifierId> flowClassifiers() { | ||
| 88 | + return ImmutableList.copyOf(flowClassifierList); | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + @Override | ||
| 92 | + public int hashCode() { | ||
| 93 | + return Objects.hash(portChainId, tenantId, name, description, | ||
| 94 | + portPairGroupList, flowClassifierList); | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + @Override | ||
| 98 | + public boolean equals(Object obj) { | ||
| 99 | + if (this == obj) { | ||
| 100 | + return true; | ||
| 101 | + } | ||
| 102 | + if (obj instanceof DefaultPortChain) { | ||
| 103 | + DefaultPortChain that = (DefaultPortChain) obj; | ||
| 104 | + return Objects.equals(portChainId, that.portChainId) && | ||
| 105 | + Objects.equals(tenantId, that.tenantId) && | ||
| 106 | + Objects.equals(name, that.name) && | ||
| 107 | + Objects.equals(description, that.description) && | ||
| 108 | + Objects.equals(portPairGroupList, that.portPairGroupList) && | ||
| 109 | + Objects.equals(flowClassifierList, that.flowClassifierList); | ||
| 110 | + } | ||
| 111 | + return false; | ||
| 112 | + } | ||
| 113 | + | ||
| 114 | + @Override | ||
| 115 | + public boolean exactMatch(PortChain portChain) { | ||
| 116 | + return this.equals(portChain) && | ||
| 117 | + Objects.equals(this.portChainId, portChain.portChainId()) && | ||
| 118 | + Objects.equals(this.tenantId, portChain.tenantId()); | ||
| 119 | + } | ||
| 120 | + | ||
| 121 | + @Override | ||
| 122 | + public String toString() { | ||
| 123 | + return toStringHelper(this) | ||
| 124 | + .add("id", portChainId.toString()) | ||
| 125 | + .add("tenantId", tenantId.toString()) | ||
| 126 | + .add("name", name) | ||
| 127 | + .add("description", description) | ||
| 128 | + .add("portPairGroupList", portPairGroupList) | ||
| 129 | + .add("flowClassifier", flowClassifierList) | ||
| 130 | + .toString(); | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | + /** | ||
| 134 | + * To create an instance of the builder. | ||
| 135 | + * | ||
| 136 | + * @return instance of builder | ||
| 137 | + */ | ||
| 138 | + public static Builder builder() { | ||
| 139 | + return new Builder(); | ||
| 140 | + } | ||
| 141 | + | ||
| 142 | + /** | ||
| 143 | + * Builder class for Port chain. | ||
| 144 | + */ | ||
| 145 | + public static final class Builder implements PortChain.Builder { | ||
| 146 | + | ||
| 147 | + private PortChainId portChainId; | ||
| 148 | + private TenantId tenantId; | ||
| 149 | + private String name; | ||
| 150 | + private String description; | ||
| 151 | + private List<PortPairGroupId> portPairGroupList; | ||
| 152 | + private List<FlowClassifierId> flowClassifierList; | ||
| 153 | + | ||
| 154 | + @Override | ||
| 155 | + public Builder setId(PortChainId portChainId) { | ||
| 156 | + this.portChainId = portChainId; | ||
| 157 | + return this; | ||
| 158 | + } | ||
| 159 | + | ||
| 160 | + @Override | ||
| 161 | + public Builder setTenantId(TenantId tenantId) { | ||
| 162 | + this.tenantId = tenantId; | ||
| 163 | + return this; | ||
| 164 | + } | ||
| 165 | + | ||
| 166 | + @Override | ||
| 167 | + public Builder setName(String name) { | ||
| 168 | + this.name = name; | ||
| 169 | + return this; | ||
| 170 | + } | ||
| 171 | + | ||
| 172 | + @Override | ||
| 173 | + public Builder setDescription(String description) { | ||
| 174 | + this.description = description; | ||
| 175 | + return this; | ||
| 176 | + } | ||
| 177 | + | ||
| 178 | + @Override | ||
| 179 | + public Builder setPortPairGroups(List<PortPairGroupId> portPairGroups) { | ||
| 180 | + this.portPairGroupList = portPairGroups; | ||
| 181 | + return this; | ||
| 182 | + } | ||
| 183 | + | ||
| 184 | + @Override | ||
| 185 | + public Builder setFlowClassifiers(List<FlowClassifierId> flowClassifiers) { | ||
| 186 | + this.flowClassifierList = flowClassifiers; | ||
| 187 | + return this; | ||
| 188 | + } | ||
| 189 | + | ||
| 190 | + @Override | ||
| 191 | + public PortChain build() { | ||
| 192 | + | ||
| 193 | + checkNotNull(portChainId, "Port chain id cannot be null"); | ||
| 194 | + checkNotNull(tenantId, "Tenant id cannot be null"); | ||
| 195 | + checkNotNull(portPairGroupList, "Port pair groups cannot be null"); | ||
| 196 | + | ||
| 197 | + return new DefaultPortChain(portChainId, tenantId, name, description, | ||
| 198 | + portPairGroupList, flowClassifierList); | ||
| 199 | + } | ||
| 200 | + } | ||
| 201 | +} |
-
Please register or login to post a comment