blob: 3cf0e324bb9857b3297b8ded83b3b33bb63f772e [file] [log] [blame]
Pier Ventreb6b81d52016-12-02 08:16:05 -08001/*
Brian O'Connor0947d7e2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Pier Ventreb6b81d52016-12-02 08:16:05 -08003 *
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
17package org.onosproject.segmentrouting;
18
Ray Milkey2a31aeb2017-08-03 16:28:24 -070019import org.onosproject.net.neighbour.NeighbourMessageContext;
20import org.onosproject.net.neighbour.NeighbourMessageHandler;
Pier Ventreb6b81d52016-12-02 08:16:05 -080021import org.onosproject.net.host.HostService;
22import org.slf4j.Logger;
23import org.slf4j.LoggerFactory;
24
25/**
26 * This handler dispatches to the appropriate handlers the
27 * neighbour discovery protocols.
28 */
29public class SegmentRoutingNeighbourDispatcher implements NeighbourMessageHandler {
30
31 private static Logger log = LoggerFactory.getLogger(SegmentRoutingNeighbourDispatcher.class);
32 private SegmentRoutingManager manager;
33
34 /**
35 * Create a segment routing neighbour dispatcher.
36 *
37 * @param segmentRoutingManager the segment routing manager
38 */
39 public SegmentRoutingNeighbourDispatcher(SegmentRoutingManager segmentRoutingManager) {
40 this.manager = segmentRoutingManager;
41 }
42
43 @Override
44 public void handleMessage(NeighbourMessageContext context, HostService hostService) {
Charles Chana7601c92019-01-23 15:03:17 -080045 manager.neighborExecutor.execute(() -> handleMessageInternal(context, hostService));
46 }
47
48 private void handleMessageInternal(NeighbourMessageContext context, HostService hostService) {
Saurav Dase6c448a2018-01-18 12:07:33 -080049 log.trace("Received {} packet on {}: {}", context.protocol(),
50 context.inPort(), context.packet());
Pier Ventreb6b81d52016-12-02 08:16:05 -080051 switch (context.protocol()) {
52 case ARP:
53 if (this.manager.arpHandler != null) {
54 this.manager.arpHandler.processPacketIn(context, hostService);
55 }
56 break;
57 case NDP:
58 if (this.manager.icmpHandler != null) {
59 this.manager.icmpHandler.processPacketIn(context, hostService);
60 }
61 break;
62 default:
63 log.warn("Unknown protocol", context.protocol());
64 }
65 }
66
67
68}