alshabib | 2ce0c73 | 2015-10-02 11:20:39 +0200 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.net.mcast; |
| 17 | |
| 18 | import com.google.common.annotations.Beta; |
| 19 | import com.google.common.base.Objects; |
| 20 | import org.onlab.packet.IpPrefix; |
| 21 | |
| 22 | import static com.google.common.base.MoreObjects.toStringHelper; |
alshabib | ed0951f | 2015-10-02 21:39:27 +0200 | [diff] [blame] | 23 | import static com.google.common.base.Preconditions.checkNotNull; |
alshabib | 2ce0c73 | 2015-10-02 11:20:39 +0200 | [diff] [blame] | 24 | |
| 25 | /** |
| 26 | * An entity representing a multicast route consisting of a source |
| 27 | * and a multicast group address. |
| 28 | */ |
| 29 | @Beta |
| 30 | public 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 | |
| 49 | private final IpPrefix source; |
| 50 | private final IpPrefix group; |
| 51 | private final Type type; |
| 52 | |
| 53 | public McastRoute(IpPrefix source, IpPrefix group, Type type) { |
alshabib | ed0951f | 2015-10-02 21:39:27 +0200 | [diff] [blame] | 54 | 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"); |
alshabib | 2ce0c73 | 2015-10-02 11:20:39 +0200 | [diff] [blame] | 57 | 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 | */ |
| 67 | public IpPrefix source() { |
| 68 | return source; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Fetches the group address of this route. |
| 73 | * |
| 74 | * @return an ip address |
| 75 | */ |
| 76 | public IpPrefix group() { |
| 77 | 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 | } |