blob: f4f1bd566c874c92294907c3e6f64854dd37ebf5 [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 */
Jonathan Hartfbfe2a82016-03-29 11:36:33 -070030public class PimPacketHandler {
Rusty Eddy4ae5aa82015-12-15 12:58:27 -080031
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 */
Jonathan Hartfbfe2a82016-03-29 11:36:33 -070037 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 */
Jonathan Hartfbfe2a82016-03-29 11:36:33 -070047 public void processPacket(Ethernet ethPkt, PimInterface pimi) {
Rusty Eddy4ae5aa82015-12-15 12:58:27 -080048 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) {
Rusty Eddy4ae5aa82015-12-15 12:58:27 -080053 return;
Rusty Eddy95421642015-10-21 17:22:13 -070054 }
55
Rusty Eddy4ae5aa82015-12-15 12:58:27 -080056 // Get the IP header
57 IPv4 ip = (IPv4) ethPkt.getPayload();
58 if (ip.getProtocol() != IPv4.PROTOCOL_PIM) {
Rusty Eddy4ae5aa82015-12-15 12:58:27 -080059 return;
Rusty Eddy95421642015-10-21 17:22:13 -070060 }
61
Rusty Eddy4ae5aa82015-12-15 12:58:27 -080062 // Get the address of our the neighbor that sent this packet to us.
63 IpAddress nbraddr = IpAddress.valueOf(ip.getDestinationAddress());
Jonathan Hart7f4bc522016-02-20 11:32:43 -080064 if (log.isTraceEnabled()) {
65 log.trace("Packet {} received on port {}", nbraddr, pimi);
66 }
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 Eddy4ae5aa82015-12-15 12:58:27 -080074 case PIM.TYPE_HELLO:
75 pimi.processHello(ethPkt);
Rusty Eddy4ae5aa82015-12-15 12:58:27 -080076 break;
Rusty Eddy4ae5aa82015-12-15 12:58:27 -080077 case PIM.TYPE_JOIN_PRUNE_REQUEST:
78 pimi.processJoinPrune(ethPkt);
79 log.debug("Received a PIM Join/Prune message");
80 break;
Rusty Eddy4ae5aa82015-12-15 12:58:27 -080081 default:
Jonathan Hart7f4bc522016-02-20 11:32:43 -080082 log.debug("Received unsupported PIM type: {}", pim.getPimMsgType());
Rusty Eddy4ae5aa82015-12-15 12:58:27 -080083 break;
84 }
Rusty Eddy95421642015-10-21 17:22:13 -070085 }
86}