blob: 3686c479ebcc570ee1f84892c100146125ccd4e1 [file] [log] [blame]
Jonathan Hart06e89082016-08-08 17:21:01 -07001/*
2 * Copyright 2016-present 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
17package org.onosproject.incubator.net.neighbour;
18
19import org.onosproject.net.Host;
20import org.onosproject.net.host.HostService;
21
22import java.util.Set;
23
24import static org.onosproject.net.HostId.hostId;
25
26/**
27 * Default neighbour message handler which implements basic proxying on a flat
28 * L2 network (i.e. ProxyArp behaviour).
29 */
30public class DefaultNeighbourMessageHandler implements NeighbourMessageHandler {
31 @Override
32 public void handleMessage(NeighbourMessageContext context, HostService hostService) {
33 // See if we have the target host in the host store
34 Set<Host> hosts = hostService.getHostsByIp(context.target());
35
36 Host dst = null;
37 Host src = hostService.getHost(hostId(context.srcMac(), context.vlan()));
38
39 for (Host host : hosts) {
40 if (host.vlan().equals(context.vlan())) {
41 dst = host;
42 break;
43 }
44 }
45
46 if (src != null && dst != null) {
47 // We know the target host so we can respond
48 context.reply(dst.mac());
49 return;
50 }
51
52 // The request couldn't be resolved.
53 // Flood the request on all ports except the incoming port.
54 context.flood();
55 }
56}