blob: 47ab12b2eb42782295b59bae1cc5ea6c492495b6 [file] [log] [blame]
alshabib2ce0c732015-10-02 11:20:39 +02001/*
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 */
16package org.onosproject.net.mcast;
17
18import com.google.common.annotations.Beta;
19import com.google.common.base.Objects;
20import org.onlab.packet.IpPrefix;
21
22import static com.google.common.base.MoreObjects.toStringHelper;
23
24/**
25 * An entity representing a multicast route consisting of a source
26 * and a multicast group address.
27 */
28@Beta
29public class McastRoute {
30
31 public enum Type {
32 /**
33 * Route originates from PIM.
34 */
35 PIM,
36
37 /**
38 * Route originates from IGMP.
39 */
40 IGMP,
41
42 /**
43 * Route originates from other config (ie. REST, CLI).
44 */
45 STATIC
46 }
47
48 private final IpPrefix source;
49 private final IpPrefix group;
50 private final Type type;
51
52 public McastRoute(IpPrefix source, IpPrefix group, Type type) {
53 this.source = source;
54 this.group = group;
55 this.type = type;
56 }
57
58 /**
59 * Fetches the source address of this route.
60 *
61 * @return an ip address
62 */
63 public IpPrefix source() {
64 return source;
65 }
66
67 /**
68 * Fetches the group address of this route.
69 *
70 * @return an ip address
71 */
72 public IpPrefix group() {
73 return group;
74 }
75
76 /**
77 * Obtains how this route was created.
78 * @return a type of route
79
80 */
81 public Type type() {
82 return type;
83 }
84
85 @Override
86 public String toString() {
87 return toStringHelper(this)
88 .add("source", source)
89 .add("group", group)
90 .add("origin", type)
91 .toString();
92 }
93
94 @Override
95 public boolean equals(Object o) {
96 if (this == o) {
97 return true;
98 }
99 if (o == null || getClass() != o.getClass()) {
100 return false;
101 }
102 McastRoute that = (McastRoute) o;
103 return Objects.equal(source, that.source) &&
104 Objects.equal(group, that.group) &&
105 Objects.equal(type, that.type);
106 }
107
108 @Override
109 public int hashCode() {
110 return Objects.hashCode(source, group, type);
111 }
112
113}