blob: 8bf23332e4a85cdea5bdba630f140806a38eed3b [file] [log] [blame]
Rusty Eddy95421642015-10-21 17:22:13 -07001/*
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.pim.impl;
17
18import org.onlab.packet.Ethernet;
19import org.onlab.packet.IPv4;
Rusty Eddy95421642015-10-21 17:22:13 -070020import org.onlab.packet.IpAddress;
21import org.onlab.packet.MacAddress;
22import org.onlab.packet.PIM;
23import org.onlab.packet.pim.PIMHello;
24import org.onlab.packet.pim.PIMHelloOption;
25import org.onosproject.incubator.net.intf.Interface;
Rusty Eddy95421642015-10-21 17:22:13 -070026import org.onosproject.net.host.InterfaceIpAddress;
27import org.slf4j.Logger;
Rusty Eddy95421642015-10-21 17:22:13 -070028
Rusty Eddy4ae5aa82015-12-15 12:58:27 -080029import java.util.Set;
Rusty Eddy95421642015-10-21 17:22:13 -070030
Rusty Eddy4ae5aa82015-12-15 12:58:27 -080031import static org.slf4j.LoggerFactory.getLogger;
Rusty Eddy95421642015-10-21 17:22:13 -070032
33/**
Ray Milkeya059a702016-01-12 11:10:33 -080034 * PIM Interface represents an ONOS Interface with IP and MAC addresses for
Rusty Eddy4ae5aa82015-12-15 12:58:27 -080035 * a given ConnectPoint.
Rusty Eddy95421642015-10-21 17:22:13 -070036 */
37public class PIMInterface {
Rusty Eddy95421642015-10-21 17:22:13 -070038
Rusty Eddy4ae5aa82015-12-15 12:58:27 -080039 private final Logger log = getLogger(getClass());
Rusty Eddy95421642015-10-21 17:22:13 -070040
Rusty Eddy4ae5aa82015-12-15 12:58:27 -080041 private Interface onosInterface;
Rusty Eddy95421642015-10-21 17:22:13 -070042
Rusty Eddy4ae5aa82015-12-15 12:58:27 -080043 // Our hello opt holdtime
44 private short holdtime = PIMHelloOption.DEFAULT_HOLDTIME;
Rusty Eddy95421642015-10-21 17:22:13 -070045
Rusty Eddy4ae5aa82015-12-15 12:58:27 -080046 // Our hello opt prune delay
47 private int pruneDelay = PIMHelloOption.DEFAULT_PRUNEDELAY;
Rusty Eddy95421642015-10-21 17:22:13 -070048
Rusty Eddy4ae5aa82015-12-15 12:58:27 -080049 // Neighbor priority
50 private int priority = PIMHelloOption.DEFAULT_PRIORITY;
Rusty Eddy95421642015-10-21 17:22:13 -070051
Rusty Eddy4ae5aa82015-12-15 12:58:27 -080052 // Our current genid
53 private int genid = PIMHelloOption.DEFAULT_GENID; // Needs to be assigned.
Rusty Eddy95421642015-10-21 17:22:13 -070054
55 /**
Rusty Eddy4ae5aa82015-12-15 12:58:27 -080056 * Create a PIMInterface from an ONOS Interface.
Charles Chan30ba4002015-11-05 14:45:16 -080057 *
Rusty Eddy4ae5aa82015-12-15 12:58:27 -080058 * @param intf the ONOS Interface.
Rusty Eddy95421642015-10-21 17:22:13 -070059 */
60 public PIMInterface(Interface intf) {
Rusty Eddy4ae5aa82015-12-15 12:58:27 -080061 onosInterface = intf;
Rusty Eddy95421642015-10-21 17:22:13 -070062 }
63
64 /**
Rusty Eddy4ae5aa82015-12-15 12:58:27 -080065 * Return the ONOS Interface.
Rusty Eddy95421642015-10-21 17:22:13 -070066 *
Rusty Eddy4ae5aa82015-12-15 12:58:27 -080067 * @return ONOS Interface.
Rusty Eddy95421642015-10-21 17:22:13 -070068 */
69 public Interface getInterface() {
Rusty Eddy4ae5aa82015-12-15 12:58:27 -080070 return this.onosInterface;
Rusty Eddy95421642015-10-21 17:22:13 -070071 }
72
73 /**
Rusty Eddy4ae5aa82015-12-15 12:58:27 -080074 * Set the ONOS Interface, it will override a previous value.
Rusty Eddy95421642015-10-21 17:22:13 -070075 *
Rusty Eddy4ae5aa82015-12-15 12:58:27 -080076 * @param intf ONOS Interface.
77 */
78 public PIMInterface setInterface(Interface intf) {
79 this.onosInterface = intf;
80 return this;
81 }
82
83 /**
84 * Get the set of IP Addresses associated with this interface.
85 *
86 * @return a set of Ip Addresses on this interface
87 */
88 public Set<InterfaceIpAddress> getIpAddresses() {
89 return this.onosInterface.ipAddresses();
90 }
91
92 /**
93 * Return a single "best" IP address.
94 *
95 * @return the choosen IP address or null if none
Rusty Eddy95421642015-10-21 17:22:13 -070096 */
97 public IpAddress getIpAddress() {
Rusty Eddy4ae5aa82015-12-15 12:58:27 -080098 if (onosInterface.ipAddresses().isEmpty()) {
Rusty Eddy95421642015-10-21 17:22:13 -070099 return null;
100 }
101
Rusty Eddy95421642015-10-21 17:22:13 -0700102 IpAddress ipaddr = null;
Rusty Eddy4ae5aa82015-12-15 12:58:27 -0800103 for (InterfaceIpAddress ifipaddr : onosInterface.ipAddresses()) {
Rusty Eddy95421642015-10-21 17:22:13 -0700104 ipaddr = ifipaddr.ipAddress();
105 break;
106 }
107 return ipaddr;
108 }
109
110 /**
Rusty Eddy4ae5aa82015-12-15 12:58:27 -0800111 * Get the holdtime.
Rusty Eddy95421642015-10-21 17:22:13 -0700112 *
Rusty Eddy4ae5aa82015-12-15 12:58:27 -0800113 * @return the holdtime
114 */
115 public short getHoldtime() {
116 return this.holdtime;
117 }
118
119 /**
120 * Get the prune delay.
121 *
122 * @return The prune delay
123 */
124 public int getPruneDelay() {
125 return this.pruneDelay;
126 }
127
128 /**
129 * Get our hello priority.
130 *
131 * @return our priority
Rusty Eddy95421642015-10-21 17:22:13 -0700132 */
133 public int getPriority() {
134 return this.priority;
135 }
136
137 /**
Rusty Eddy4ae5aa82015-12-15 12:58:27 -0800138 * Get our generation ID.
Rusty Eddy95421642015-10-21 17:22:13 -0700139 *
Rusty Eddy4ae5aa82015-12-15 12:58:27 -0800140 * @return our generation ID
Rusty Eddy95421642015-10-21 17:22:13 -0700141 */
Rusty Eddy4ae5aa82015-12-15 12:58:27 -0800142 public int getGenid() {
143 return this.genid;
Rusty Eddy95421642015-10-21 17:22:13 -0700144 }
145
146 /**
Rusty Eddy4ae5aa82015-12-15 12:58:27 -0800147 * Process an incoming PIM Hello message.
Rusty Eddy95421642015-10-21 17:22:13 -0700148 *
Rusty Eddy4ae5aa82015-12-15 12:58:27 -0800149 * @param ethPkt the Ethernet packet header
Rusty Eddy95421642015-10-21 17:22:13 -0700150 */
Rusty Eddy4ae5aa82015-12-15 12:58:27 -0800151 public void processHello(Ethernet ethPkt) {
Rusty Eddy95421642015-10-21 17:22:13 -0700152
Rusty Eddy4ae5aa82015-12-15 12:58:27 -0800153 // We'll need to save our neighbors MAC address
154 MacAddress nbrmac = ethPkt.getSourceMAC();
Rusty Eddy95421642015-10-21 17:22:13 -0700155
Rusty Eddy4ae5aa82015-12-15 12:58:27 -0800156 // And we'll need to save neighbors IP Address.
157 IPv4 iphdr = (IPv4) ethPkt.getPayload();
158 IpAddress srcip = IpAddress.valueOf(iphdr.getSourceAddress());
Rusty Eddy95421642015-10-21 17:22:13 -0700159
Rusty Eddy4ae5aa82015-12-15 12:58:27 -0800160 PIM pimhdr = (PIM) iphdr.getPayload();
161 if (pimhdr.getPimMsgType() != PIM.TYPE_HELLO) {
162 log.error("process Hello has received a non hello packet type: " + pimhdr.getPimMsgType());
Rusty Eddy95421642015-10-21 17:22:13 -0700163 return;
164 }
165
Rusty Eddy4ae5aa82015-12-15 12:58:27 -0800166 // TODO: Maybe a good idea to check the checksum. Let's jump into the hello options.
167 PIMHello hello = (PIMHello) pimhdr.getPayload();
168
169 // TODO: this is about where we find or create our PIMNeighbor
170
171 boolean reElectDr = false;
172
173 // Start walking through all the hello options to handle accordingly.
174 for (PIMHelloOption opt : hello.getOptions().values()) {
175
176 // TODO: This is where we handle the options and modify the neighbor accordingly.
177 // We'll need to create the PIMNeighbor class next. Depending on what happens
178 // we may need to re-elect a DR
Rusty Eddy95421642015-10-21 17:22:13 -0700179 }
Rusty Eddy4ae5aa82015-12-15 12:58:27 -0800180
181 if (reElectDr) {
182 // TODO: create an election() method and call it here with a PIMNeighbor
183 }
Rusty Eddy95421642015-10-21 17:22:13 -0700184 }
185
186 /**
Rusty Eddy4ae5aa82015-12-15 12:58:27 -0800187 * Process an incoming PIM JoinPrune message.
Rusty Eddy95421642015-10-21 17:22:13 -0700188 *
Rusty Eddy4ae5aa82015-12-15 12:58:27 -0800189 * @param ethPkt the Ethernet packet header.
Rusty Eddy95421642015-10-21 17:22:13 -0700190 */
Rusty Eddy4ae5aa82015-12-15 12:58:27 -0800191 public void processJoinPrune(Ethernet ethPkt) {
Rusty Eddy95421642015-10-21 17:22:13 -0700192
Rusty Eddy95421642015-10-21 17:22:13 -0700193 }
Rusty Eddy95421642015-10-21 17:22:13 -0700194}