Esin Karaman | 971fb7f | 2017-12-28 13:44:52 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 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 | */ |
| 17 | |
| 18 | package org.onosproject.drivers.bmv2.api.runtime; |
| 19 | |
| 20 | import com.google.common.base.MoreObjects; |
| 21 | import com.google.common.base.Objects; |
| 22 | |
| 23 | import static com.google.common.base.Preconditions.checkNotNull; |
| 24 | |
| 25 | /** |
| 26 | * The class that represents a multicast node in BMv2 PRE. |
| 27 | */ |
| 28 | public class Bmv2PreNode { |
| 29 | //replication id |
| 30 | private final Integer rid; |
| 31 | private final String portMap; |
| 32 | private Integer l1Handle; |
| 33 | |
| 34 | public Bmv2PreNode(Integer rid, String portMap) { |
| 35 | this.rid = checkNotNull(rid, "rid argument can not be null"); |
| 36 | this.portMap = checkNotNull(portMap, "portMap argument can not be null"); |
| 37 | } |
| 38 | |
| 39 | public static Bmv2PreNodeBuilder builder() { |
| 40 | return new Bmv2PreNodeBuilder(); |
| 41 | } |
| 42 | |
| 43 | public Integer rid() { |
| 44 | return rid; |
| 45 | } |
| 46 | |
| 47 | public String portMap() { |
| 48 | return portMap; |
| 49 | } |
| 50 | |
| 51 | public Integer l1Handle() { |
| 52 | return l1Handle; |
| 53 | } |
| 54 | |
| 55 | public void setL1Handle(Integer l1Handle) { |
| 56 | this.l1Handle = l1Handle; |
| 57 | } |
| 58 | |
| 59 | @Override |
| 60 | public int hashCode() { |
| 61 | return Objects.hashCode(rid, portMap, l1Handle); |
| 62 | } |
| 63 | |
| 64 | @Override |
| 65 | public boolean equals(Object obj) { |
| 66 | if (this == obj) { |
| 67 | return true; |
| 68 | } |
| 69 | if (obj == null || getClass() != obj.getClass()) { |
| 70 | return false; |
| 71 | } |
| 72 | final Bmv2PreNode other = (Bmv2PreNode) obj; |
| 73 | return Objects.equal(this.rid, other.rid) |
| 74 | && Objects.equal(this.portMap, other.portMap); |
| 75 | } |
| 76 | |
| 77 | @Override |
| 78 | public String toString() { |
| 79 | return MoreObjects.toStringHelper(this) |
| 80 | .add("rid", rid) |
| 81 | .add("portMap", portMap) |
| 82 | .add("l1Handle", l1Handle) |
| 83 | .toString(); |
| 84 | } |
| 85 | |
| 86 | public static final class Bmv2PreNodeBuilder { |
| 87 | //replication id |
| 88 | private Integer rid; |
| 89 | private String portMap; |
| 90 | private Integer l1Handle; |
| 91 | |
| 92 | private Bmv2PreNodeBuilder() { |
| 93 | } |
| 94 | |
| 95 | public Bmv2PreNodeBuilder withRid(Integer rid) { |
| 96 | this.rid = rid; |
| 97 | return this; |
| 98 | } |
| 99 | |
| 100 | public Bmv2PreNodeBuilder withPortMap(String portMap) { |
| 101 | this.portMap = portMap; |
| 102 | return this; |
| 103 | } |
| 104 | |
| 105 | public Bmv2PreNodeBuilder withL1Handle(Integer l1Handle) { |
| 106 | this.l1Handle = l1Handle; |
| 107 | return this; |
| 108 | } |
| 109 | |
| 110 | public Bmv2PreNode build() { |
| 111 | Bmv2PreNode bmv2PreNode = new Bmv2PreNode(rid, portMap); |
| 112 | bmv2PreNode.setL1Handle(l1Handle); |
| 113 | return bmv2PreNode; |
| 114 | } |
| 115 | } |
| 116 | } |