blob: 2aed2235b18c80e2ffa7f690c6e6736355d515fb [file] [log] [blame]
Phaneendra Mandac6120542016-04-18 13:57:16 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Phaneendra Mandac6120542016-04-18 13:57:16 +05303 *
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 */
16package org.onosproject.vtnrsc;
17
18import static com.google.common.base.MoreObjects.toStringHelper;
19
20import java.util.Map;
21import java.util.Objects;
22
23import com.google.common.collect.ImmutableMap;
24
25/**
26 * Implementation of ServiceFunctionGroup class.
27 */
28public final class ServiceFunctionGroup {
29
30 private final String name;
31 private final String description;
32 private final Map<PortPairId, Integer> portPairLoadMap;
33
34 /**
35 * Creates an instance of service function group.
36 *
37 * @param name name of port pair
38 * @param description description of port pair
39 * @param portPairLoadMap map of port pair id and its load
40 */
41 public ServiceFunctionGroup(String name, String description,
42 Map<PortPairId, Integer> portPairLoadMap) {
43 this.name = name;
44 this.description = description;
45 this.portPairLoadMap = portPairLoadMap;
46 }
47
48 /**
49 * Returns name of service function group.
50 *
51 * @return name of service function group
52 */
53 public String name() {
54 return name;
55 }
56
57 /**
58 * Returns description of service function group.
59 *
60 * @return description of service function group.
61 */
62 public String description() {
63 return description;
64 }
65
66 /**
67 * Returns port pair load map.
68 *
69 * @return port pair load map
70 */
71 public Map<PortPairId, Integer> portPairLoadMap() {
72 return ImmutableMap.copyOf(portPairLoadMap);
73 }
74
75 @Override
76 public int hashCode() {
77 return Objects.hash(name, description, portPairLoadMap);
78 }
79
80 @Override
81 public boolean equals(Object obj) {
82 if (this == obj) {
83 return true;
84 }
85 if (obj instanceof ServiceFunctionGroup) {
86 ServiceFunctionGroup that = (ServiceFunctionGroup) obj;
87 return Objects.equals(name, that.name()) &&
88 Objects.equals(description, that.description()) &&
89 Objects.equals(portPairLoadMap, that.portPairLoadMap());
90 }
91 return false;
92 }
93
94 @Override
95 public String toString() {
96 return toStringHelper(this)
97 .add("name", name)
98 .add("description", description)
99 .add("portPairLoadMap", portPairLoadMap)
100 .toString();
101 }
102}