blob: afc57fd69f6a7d1458dfbc51e3247046644782b5 [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;
Rusty Eddy95421642015-10-21 17:22:13 -070021import org.onlab.packet.PIM;
Rusty Eddy95421642015-10-21 17:22:13 -070022import org.slf4j.Logger;
23
Rusty Eddy95421642015-10-21 17:22:13 -070024import static com.google.common.base.Preconditions.checkNotNull;
25import static org.slf4j.LoggerFactory.getLogger;
26
27/**
Rusty Eddy4ae5aa82015-12-15 12:58:27 -080028 * This class will process PIM packets.
Rusty Eddy95421642015-10-21 17:22:13 -070029 */
Rusty Eddy4ae5aa82015-12-15 12:58:27 -080030public class PIMPacketHandler {
31
Rusty Eddy95421642015-10-21 17:22:13 -070032 private final Logger log = getLogger(getClass());
33
Rusty Eddy4ae5aa82015-12-15 12:58:27 -080034 /**
35 * Constructor for this class.
36 */
37 public PIMPacketHandler() {
Rusty Eddy95421642015-10-21 17:22:13 -070038 }
39
40 /**
Rusty Eddy4ae5aa82015-12-15 12:58:27 -080041 * Sanitize and process the packet.
42 * TODO: replace ConnectPoint with PIMInterface when PIMInterface has been added.
Rusty Eddy95421642015-10-21 17:22:13 -070043 *
Rusty Eddy4ae5aa82015-12-15 12:58:27 -080044 * @param ethPkt the packet starting with the Ethernet header.
45 * @param pimi the PIM Interface the packet arrived on.
Rusty Eddy95421642015-10-21 17:22:13 -070046 */
Rusty Eddy4ae5aa82015-12-15 12:58:27 -080047 public void processPacket(Ethernet ethPkt, PIMInterface pimi) {
48 checkNotNull(ethPkt);
49 checkNotNull(pimi);
Rusty Eddy95421642015-10-21 17:22:13 -070050
Rusty Eddy4ae5aa82015-12-15 12:58:27 -080051 // Sanitize the ethernet header to ensure it is IPv4. IPv6 we'll deal with later
52 if (ethPkt.getEtherType() != Ethernet.TYPE_IPV4) {
53 log.debug("Recieved a non IPv4 packet");
54 return;
Rusty Eddy95421642015-10-21 17:22:13 -070055 }
56
Rusty Eddy4ae5aa82015-12-15 12:58:27 -080057 // Get the IP header
58 IPv4 ip = (IPv4) ethPkt.getPayload();
59 if (ip.getProtocol() != IPv4.PROTOCOL_PIM) {
60 log.debug("Received a non PIM IP packet");
61 return;
Rusty Eddy95421642015-10-21 17:22:13 -070062 }
63
Rusty Eddy4ae5aa82015-12-15 12:58:27 -080064 // Get the address of our the neighbor that sent this packet to us.
65 IpAddress nbraddr = IpAddress.valueOf(ip.getDestinationAddress());
66 log.debug("Packet " + nbraddr.toString() + " received on port " + pimi.toString());
Rusty Eddy95421642015-10-21 17:22:13 -070067
Rusty Eddy4ae5aa82015-12-15 12:58:27 -080068 // Get the PIM header
69 PIM pim = (PIM) ip.getPayload();
70 checkNotNull(pim);
Rusty Eddy95421642015-10-21 17:22:13 -070071
Rusty Eddy4ae5aa82015-12-15 12:58:27 -080072 // Process the pim packet
73 switch (pim.getPimMsgType()) {
Rusty Eddy95421642015-10-21 17:22:13 -070074
Rusty Eddy4ae5aa82015-12-15 12:58:27 -080075 case PIM.TYPE_HELLO:
76 pimi.processHello(ethPkt);
77 log.debug("Received a PIM hello packet");
78 break;
Rusty Eddy95421642015-10-21 17:22:13 -070079
Rusty Eddy4ae5aa82015-12-15 12:58:27 -080080 case PIM.TYPE_JOIN_PRUNE_REQUEST:
81 pimi.processJoinPrune(ethPkt);
82 log.debug("Received a PIM Join/Prune message");
83 break;
84
85 default:
86 log.debug("Recieved unsupported PIM type: " + pim.getPimMsgType());
87 break;
88 }
Rusty Eddy95421642015-10-21 17:22:13 -070089 }
90}