blob: 7fe1a902367b717da0e7ee640712972cd94135b2 [file] [log] [blame]
Andrea Campanella545edb42018-03-20 16:37:29 -07001/*
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 */
16package org.onosproject.mcast.api;
17
18import com.google.common.annotations.Beta;
19import com.google.common.base.Objects;
20import org.onlab.packet.IpAddress;
21
22import java.util.Optional;
23
24import static com.google.common.base.MoreObjects.toStringHelper;
25import static com.google.common.base.Preconditions.checkNotNull;
26
27/**
28 * An entity representing a multicast route consisting of a source ip
29 * and a multicast group address.
30 */
31@Beta
32public class McastRoute {
33
34 /**
35 * Possible route types.
36 */
37 public enum Type {
38 /**
39 * Route originates from PIM.
40 */
41 PIM,
42
43 /**
44 * Route originates from IGMP.
45 */
46 IGMP,
47
48 /**
49 * Route originates from other config (ie. REST, CLI).
50 */
51 STATIC
52 }
53
54 private final IpAddress source;
55 private final IpAddress group;
56 private final Type type;
57
58 /**
59 * Creates the McastRoute object. The source Ip can be null if this route is intent for ASM.
Andrea Campanella0ddf9b82018-04-27 15:54:42 +020060 *
Andrea Campanella545edb42018-03-20 16:37:29 -070061 * @param source source Ip. Null if ASM route. Will translate in Optional.empty.
Andrea Campanella0ddf9b82018-04-27 15:54:42 +020062 * @param group the multicast group
63 * @param type the route type.
Andrea Campanella545edb42018-03-20 16:37:29 -070064 */
65 public McastRoute(IpAddress source, IpAddress group, Type type) {
66 checkNotNull(group, "Multicast route must specify a group address");
67 this.source = source;
68 this.group = group;
69 this.type = type;
70 }
71
72 /**
73 * Fetches the source address of this route.
74 *
75 * @return an optional ip address.
76 */
77 public Optional<IpAddress> source() {
78 return Optional.ofNullable(source);
79 }
80
81 /**
82 * Fetches the group address of this route.
83 *
84 * @return an ip address
85 */
86 public IpAddress group() {
87 return group;
88 }
89
90
91 /**
92 * Type of this route.
93 *
94 * @return type
95 */
96 public Type type() {
97 return type;
98 }
99
100 @Override
101 public String toString() {
102 return toStringHelper(this)
103 .add("source", source)
104 .add("group", group)
105 .add("type", type())
106 .toString();
107 }
108
109 @Override
110 public boolean equals(Object o) {
111 if (this == o) {
112 return true;
113 }
114 if (o == null || getClass() != o.getClass()) {
115 return false;
116 }
117 McastRoute that = (McastRoute) o;
118 return Objects.equal(source, that.source) &&
119 Objects.equal(group, that.group) &&
120 Objects.equal(type, that.type());
121 }
122
123 @Override
124 public int hashCode() {
125 return Objects.hashCode(source, group, type);
126 }
127
128}