blob: 5ac3a94e63d056b53924b79b80f91ffbd95f649b [file] [log] [blame]
alshabib2ce0c732015-10-02 11:20:39 +02001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
alshabib2ce0c732015-10-02 11:20:39 +02003 *
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;
alshabib79e52872015-12-07 16:01:01 -080020import org.onlab.packet.IpAddress;
alshabib2ce0c732015-10-02 11:20:39 +020021
22import static com.google.common.base.MoreObjects.toStringHelper;
alshabibed0951f2015-10-02 21:39:27 +020023import static com.google.common.base.Preconditions.checkNotNull;
alshabib2ce0c732015-10-02 11:20:39 +020024
25/**
26 * An entity representing a multicast route consisting of a source
27 * and a multicast group address.
28 */
29@Beta
30public class McastRoute {
31
32 public enum Type {
33 /**
34 * Route originates from PIM.
35 */
36 PIM,
37
38 /**
39 * Route originates from IGMP.
40 */
41 IGMP,
42
43 /**
44 * Route originates from other config (ie. REST, CLI).
45 */
46 STATIC
47 }
48
alshabib79e52872015-12-07 16:01:01 -080049 private final IpAddress source;
50 private final IpAddress group;
alshabib2ce0c732015-10-02 11:20:39 +020051 private final Type type;
52
alshabib79e52872015-12-07 16:01:01 -080053 public McastRoute(IpAddress source, IpAddress group, Type type) {
alshabibed0951f2015-10-02 21:39:27 +020054 checkNotNull(source, "Multicast route must have a source");
55 checkNotNull(group, "Multicast route must specify a group address");
56 checkNotNull(type, "Must indicate what type of route");
alshabib2ce0c732015-10-02 11:20:39 +020057 this.source = source;
58 this.group = group;
59 this.type = type;
60 }
61
62 /**
63 * Fetches the source address of this route.
64 *
65 * @return an ip address
66 */
alshabib79e52872015-12-07 16:01:01 -080067 public IpAddress source() {
alshabib2ce0c732015-10-02 11:20:39 +020068 return source;
69 }
70
71 /**
72 * Fetches the group address of this route.
73 *
74 * @return an ip address
75 */
alshabib79e52872015-12-07 16:01:01 -080076 public IpAddress group() {
alshabib2ce0c732015-10-02 11:20:39 +020077 return group;
78 }
79
80 /**
81 * Obtains how this route was created.
82 * @return a type of route
83
84 */
85 public Type type() {
86 return type;
87 }
88
89 @Override
90 public String toString() {
91 return toStringHelper(this)
92 .add("source", source)
93 .add("group", group)
94 .add("origin", type)
95 .toString();
96 }
97
98 @Override
99 public boolean equals(Object o) {
100 if (this == o) {
101 return true;
102 }
103 if (o == null || getClass() != o.getClass()) {
104 return false;
105 }
106 McastRoute that = (McastRoute) o;
107 return Objects.equal(source, that.source) &&
108 Objects.equal(group, that.group) &&
109 Objects.equal(type, that.type);
110 }
111
112 @Override
113 public int hashCode() {
114 return Objects.hashCode(source, group, type);
115 }
116
117}