blob: 16784c2b59f15bf05977d29f2e7c262da4ef0086 [file] [log] [blame]
sanghob35a6192015-04-01 13:05:26 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
sanghob35a6192015-04-01 13:05:26 -07003 *
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.segmentrouting;
17
sanghob35a6192015-04-01 13:05:26 -070018import org.onlab.packet.Ethernet;
19import org.onlab.packet.ICMP;
Pier Ventre735b8c82016-12-02 08:16:05 -080020import org.onlab.packet.ICMP6;
sanghob35a6192015-04-01 13:05:26 -070021import org.onlab.packet.IPv4;
Pier Ventre735b8c82016-12-02 08:16:05 -080022import org.onlab.packet.IPv6;
sanghob35a6192015-04-01 13:05:26 -070023import org.onlab.packet.Ip4Address;
Pier Ventref4b5fce2016-11-28 16:48:06 -080024import org.onlab.packet.Ip6Address;
Pier Ventree0ae7a32016-11-23 09:57:42 -080025import org.onlab.packet.IpAddress;
sanghob35a6192015-04-01 13:05:26 -070026import org.onlab.packet.IpPrefix;
27import org.onlab.packet.MPLS;
Pier Ventref4b5fce2016-11-28 16:48:06 -080028import org.onlab.packet.MacAddress;
29import org.onlab.packet.VlanId;
Pier Ventre735b8c82016-12-02 08:16:05 -080030import org.onlab.packet.ndp.NeighborSolicitation;
Pier Ventre10bd8d12016-11-26 21:05:22 -080031import org.onosproject.incubator.net.neighbour.NeighbourMessageContext;
Pier Ventref4b5fce2016-11-28 16:48:06 -080032import org.onosproject.incubator.net.neighbour.NeighbourMessageType;
sanghob35a6192015-04-01 13:05:26 -070033import org.onosproject.net.ConnectPoint;
34import org.onosproject.net.DeviceId;
Pier Ventref4b5fce2016-11-28 16:48:06 -080035import org.onosproject.net.Host;
36import org.onosproject.net.HostId;
sanghob35a6192015-04-01 13:05:26 -070037import org.onosproject.net.flow.DefaultTrafficTreatment;
38import org.onosproject.net.flow.TrafficTreatment;
Pier Ventref4b5fce2016-11-28 16:48:06 -080039import org.onosproject.net.host.HostService;
sanghob35a6192015-04-01 13:05:26 -070040import org.onosproject.net.packet.DefaultOutboundPacket;
Pier Luigi7dad71c2017-02-01 13:50:04 -080041import org.onosproject.net.packet.InboundPacket;
sanghob35a6192015-04-01 13:05:26 -070042import org.onosproject.net.packet.OutboundPacket;
Pier Luigi7dad71c2017-02-01 13:50:04 -080043import org.onosproject.net.packet.PacketContext;
Charles Chan0b4e6182015-11-03 10:42:14 -080044import org.onosproject.segmentrouting.config.DeviceConfigNotFoundException;
Pier Ventref4b5fce2016-11-28 16:48:06 -080045import org.onosproject.segmentrouting.config.SegmentRoutingAppConfig;
sanghob35a6192015-04-01 13:05:26 -070046import org.slf4j.Logger;
47import org.slf4j.LoggerFactory;
48
Jonathan Hart2a655752015-04-07 16:46:33 -070049import java.nio.ByteBuffer;
Saurav Das837e0bb2015-10-30 17:45:38 -070050import java.util.Set;
Jonathan Hart2a655752015-04-07 16:46:33 -070051
Charles Chane849c192016-01-11 18:28:54 -080052/**
53 * Handler of ICMP packets that responses or forwards ICMP packets that
54 * are sent to the controller.
55 */
Pier Ventre735b8c82016-12-02 08:16:05 -080056public class IcmpHandler extends SegmentRoutingNeighbourHandler {
sanghob35a6192015-04-01 13:05:26 -070057
58 private static Logger log = LoggerFactory.getLogger(IcmpHandler.class);
sanghob35a6192015-04-01 13:05:26 -070059
60 /**
61 * Creates an IcmpHandler object.
62 *
63 * @param srManager SegmentRoutingManager object
64 */
65 public IcmpHandler(SegmentRoutingManager srManager) {
Pier Ventre735b8c82016-12-02 08:16:05 -080066 super(srManager);
67 }
68
69 /**
70 * Utility function to send packet out.
71 *
72 * @param outport the output port
73 * @param payload the packet to send
74 * @param sid the segment id
75 * @param destIpAddress the destination ip address
76 * @param allowedHops the hop limit/ttl
77 */
78 private void sendPacketOut(ConnectPoint outport,
79 Ethernet payload,
80 int sid,
81 IpAddress destIpAddress,
82 byte allowedHops) {
83 int destSid;
84 if (destIpAddress.isIp4()) {
85 destSid = config.getIPv4SegmentId(payload.getDestinationMAC());
86 } else {
87 destSid = config.getIPv6SegmentId(payload.getDestinationMAC());
88 }
89
90 if (sid == -1 || destSid == sid ||
91 config.inSameSubnet(outport.deviceId(), destIpAddress)) {
92 TrafficTreatment treatment = DefaultTrafficTreatment.builder().
93 setOutput(outport.port()).build();
94 OutboundPacket packet = new DefaultOutboundPacket(outport.deviceId(),
95 treatment, ByteBuffer.wrap(payload.serialize()));
96 srManager.packetService.emit(packet);
97 } else {
98 log.debug("Send a MPLS packet as a ICMP response");
99 TrafficTreatment treatment = DefaultTrafficTreatment.builder()
100 .setOutput(outport.port())
101 .build();
102
103 payload.setEtherType(Ethernet.MPLS_UNICAST);
104 MPLS mplsPkt = new MPLS();
105 mplsPkt.setLabel(sid);
106 mplsPkt.setTtl(allowedHops);
107 mplsPkt.setPayload(payload.getPayload());
108 payload.setPayload(mplsPkt);
109
110 OutboundPacket packet = new DefaultOutboundPacket(outport.deviceId(),
111 treatment, ByteBuffer.wrap(payload.serialize()));
112
113 srManager.packetService.emit(packet);
114 }
sanghob35a6192015-04-01 13:05:26 -0700115 }
116
Pier Ventref4b5fce2016-11-28 16:48:06 -0800117 //////////////////////////////////////
118 // ICMP Echo/Reply Protocol //
119 //////////////////////////////////////
120
sanghob35a6192015-04-01 13:05:26 -0700121 /**
122 * Process incoming ICMP packet.
123 * If it is an ICMP request to router or known host, then sends an ICMP response.
124 * If it is an ICMP packet to known host and forward the packet to the host.
125 * If it is an ICMP packet to unknown host in a subnet, then sends an ARP request
126 * to the subnet.
127 *
Pier Ventre735b8c82016-12-02 08:16:05 -0800128 * @param eth inbound ICMP packet
129 * @param inPort the input port
sanghob35a6192015-04-01 13:05:26 -0700130 */
Pier Ventre735b8c82016-12-02 08:16:05 -0800131 public void processIcmp(Ethernet eth, ConnectPoint inPort) {
132 DeviceId deviceId = inPort.deviceId();
133 IPv4 ipv4Packet = (IPv4) eth.getPayload();
134 Ip4Address destinationAddress = Ip4Address.valueOf(ipv4Packet.getDestinationAddress());
Pier Ventre10bd8d12016-11-26 21:05:22 -0800135 Set<IpAddress> gatewayIpAddresses = config.getPortIPs(deviceId);
Pier Ventree0ae7a32016-11-23 09:57:42 -0800136 IpAddress routerIp;
Charles Chan0b4e6182015-11-03 10:42:14 -0800137 try {
Pier Ventree0ae7a32016-11-23 09:57:42 -0800138 routerIp = config.getRouterIpv4(deviceId);
Charles Chan0b4e6182015-11-03 10:42:14 -0800139 } catch (DeviceConfigNotFoundException e) {
140 log.warn(e.getMessage() + " Aborting processPacketIn.");
141 return;
142 }
sanghob35a6192015-04-01 13:05:26 -0700143 // ICMP to the router IP or gateway IP
Pier Ventre735b8c82016-12-02 08:16:05 -0800144 if (((ICMP) ipv4Packet.getPayload()).getIcmpType() == ICMP.TYPE_ECHO_REQUEST &&
145 (destinationAddress.equals(routerIp.getIp4Address()) ||
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700146 gatewayIpAddresses.contains(destinationAddress))) {
Pier Ventre735b8c82016-12-02 08:16:05 -0800147 sendIcmpResponse(eth, inPort);
148 // We remove the packet from the queue
149 srManager.ipHandler.dequeuePacket(ipv4Packet, destinationAddress);
sanghob35a6192015-04-01 13:05:26 -0700150
151 // ICMP for any known host
152 } else if (!srManager.hostService.getHostsByIp(destinationAddress).isEmpty()) {
Saurav Das4ce45962015-11-24 23:21:05 -0800153 // TODO: known host packet should not be coming to controller - resend flows?
sanghob35a6192015-04-01 13:05:26 -0700154 srManager.ipHandler.forwardPackets(deviceId, destinationAddress);
155
156 // ICMP for an unknown host in the subnet of the router
157 } else if (config.inSameSubnet(deviceId, destinationAddress)) {
Pier Ventre735b8c82016-12-02 08:16:05 -0800158 srManager.arpHandler.sendArpRequest(deviceId, destinationAddress, inPort);
sanghob35a6192015-04-01 13:05:26 -0700159
160 // ICMP for an unknown host
161 } else {
162 log.debug("ICMP request for unknown host {} ", destinationAddress);
Pier Ventre735b8c82016-12-02 08:16:05 -0800163 // We remove the packet from the queue
164 srManager.ipHandler.dequeuePacket(ipv4Packet, destinationAddress);
sanghob35a6192015-04-01 13:05:26 -0700165 }
166 }
167
Charles Chan68aa62d2015-11-09 16:37:23 -0800168 /**
169 * Sends an ICMP reply message.
170 *
171 * Note: we assume that packets sending from the edge switches to the hosts
172 * have untagged VLAN.
173 * @param icmpRequest the original ICMP request
174 * @param outport the output port where the ICMP reply should be sent to
175 */
Pier Ventree0ae7a32016-11-23 09:57:42 -0800176 private void sendIcmpResponse(Ethernet icmpRequest, ConnectPoint outport) {
Charles Chan68aa62d2015-11-09 16:37:23 -0800177 // Note: We assume that packets arrive at the edge switches have
178 // untagged VLAN.
Pier Ventre735b8c82016-12-02 08:16:05 -0800179 Ethernet icmpReplyEth = ICMP.buildIcmpReply(icmpRequest);
sanghob35a6192015-04-01 13:05:26 -0700180 IPv4 icmpRequestIpv4 = (IPv4) icmpRequest.getPayload();
Pier Ventre735b8c82016-12-02 08:16:05 -0800181 IPv4 icmpReplyIpv4 = (IPv4) icmpReplyEth.getPayload();
182 Ip4Address destIpAddress = Ip4Address.valueOf(icmpRequestIpv4.getSourceAddress());
sangho666cd6d2015-04-14 16:27:13 -0700183 Ip4Address destRouterAddress = config.getRouterIpAddressForASubnetHost(destIpAddress);
Pier Ventree0ae7a32016-11-23 09:57:42 -0800184 int destSid = config.getIPv4SegmentId(destRouterAddress);
Charles Chan68aaad52016-12-09 12:54:49 -0800185 if (destSid < 0) {
Pier Ventre735b8c82016-12-02 08:16:05 -0800186 log.warn("Cannot find the Segment ID for {}", destIpAddress);
sanghob35a6192015-04-01 13:05:26 -0700187 return;
188 }
Pier Ventre735b8c82016-12-02 08:16:05 -0800189 sendPacketOut(outport, icmpReplyEth, destSid, destIpAddress, icmpReplyIpv4.getTtl());
sanghob35a6192015-04-01 13:05:26 -0700190 }
191
Pier Ventre735b8c82016-12-02 08:16:05 -0800192 ///////////////////////////////////////////
193 // ICMPv6 Echo/Reply Protocol //
194 ///////////////////////////////////////////
sanghob35a6192015-04-01 13:05:26 -0700195
Pier Ventre735b8c82016-12-02 08:16:05 -0800196 /**
197 * Process incoming ICMPv6 packet.
198 * If it is an ICMP request to router or known host, then sends an ICMP response.
199 * If it is an ICMP packet to known host and forward the packet to the host.
200 * If it is an ICMP packet to unknown host in a subnet, then sends an ARP request
201 * to the subnet.
202 *
203 * @param eth the incoming ICMPv6 packet
204 * @param inPort the input port
205 */
206 public void processIcmpv6(Ethernet eth, ConnectPoint inPort) {
207 DeviceId deviceId = inPort.deviceId();
208 IPv6 ipv6Packet = (IPv6) eth.getPayload();
209 Ip6Address destinationAddress = Ip6Address.valueOf(ipv6Packet.getDestinationAddress());
210 Set<IpAddress> gatewayIpAddresses = config.getPortIPs(deviceId);
211 IpAddress routerIp;
212 try {
213 routerIp = config.getRouterIpv6(deviceId);
214 } catch (DeviceConfigNotFoundException e) {
215 log.warn(e.getMessage() + " Aborting processPacketIn.");
216 return;
sanghob35a6192015-04-01 13:05:26 -0700217 }
Pier Ventre735b8c82016-12-02 08:16:05 -0800218 ICMP6 icmp6 = (ICMP6) ipv6Packet.getPayload();
219 // ICMP to the router IP or gateway IP
220 if (icmp6.getIcmpType() == ICMP6.ECHO_REQUEST &&
221 (destinationAddress.equals(routerIp.getIp6Address()) ||
222 gatewayIpAddresses.contains(destinationAddress))) {
223 sendIcmpv6Response(eth, inPort);
224 // We remove the packet from the queue
225 srManager.ipHandler.dequeuePacket(ipv6Packet, destinationAddress);
226 // ICMP for any known host
227 } else if (!srManager.hostService.getHostsByIp(destinationAddress).isEmpty()) {
228 // TODO: known host packet should not be coming to controller - resend flows?
229 srManager.ipHandler.forwardPackets(deviceId, destinationAddress);
230 // ICMP for an unknown host in the subnet of the router
231 } else if (config.inSameSubnet(deviceId, destinationAddress)) {
232 sendNdpRequest(deviceId, destinationAddress, inPort);
233 // ICMP for an unknown host or not configured host
234 } else {
235 log.debug("ICMPv6 request for unknown host or not configured host {} ", destinationAddress);
236 // We remove the packet from the queue
237 srManager.ipHandler.dequeuePacket(ipv6Packet, destinationAddress);
238 }
239 }
240
241 /**
242 * Sends an ICMPv6 reply message.
243 *
244 * Note: we assume that packets sending from the edge switches to the hosts
245 * have untagged VLAN.
246 * @param ethRequest the original ICMP request
247 * @param outport the output port where the ICMP reply should be sent to
248 */
249 private void sendIcmpv6Response(Ethernet ethRequest, ConnectPoint outport) {
250 // Note: We assume that packets arrive at the edge switches have
251 // untagged VLAN.
252 Ethernet ethReply = ICMP6.buildIcmp6Reply(ethRequest);
253 IPv6 icmpRequestIpv6 = (IPv6) ethRequest.getPayload();
254 IPv6 icmpReplyIpv6 = (IPv6) ethRequest.getPayload();
255 Ip6Address destIpAddress = Ip6Address.valueOf(icmpRequestIpv6.getSourceAddress());
256 Ip6Address destRouterAddress = config.getRouterIpAddressForASubnetHost(destIpAddress);
257 int sid = config.getIPv6SegmentId(destRouterAddress);
258 if (sid < 0) {
259 log.warn("Cannot find the Segment ID for {}", destIpAddress);
260 return;
261 }
262 sendPacketOut(outport, ethReply, sid, destIpAddress, icmpReplyIpv6.getHopLimit());
sanghob35a6192015-04-01 13:05:26 -0700263 }
sangho666cd6d2015-04-14 16:27:13 -0700264
Pier Ventref4b5fce2016-11-28 16:48:06 -0800265 ///////////////////////////////////////////
266 // ICMPv6 Neighbour Discovery Protocol //
267 ///////////////////////////////////////////
sangho666cd6d2015-04-14 16:27:13 -0700268
Pier Ventref4b5fce2016-11-28 16:48:06 -0800269 /**
270 * Process incoming NDP packet.
271 *
272 * If it is an NDP request for the router or for the gateway, then sends a NDP reply.
273 * If it is an NDP request to unknown host flood in the subnet.
274 * If it is an NDP packet to known host forward the packet to the host.
275 *
276 * FIXME If the NDP packets use link local addresses we fail.
277 *
278 * @param pkt inbound packet
279 * @param hostService the host service
280 */
281 public void processPacketIn(NeighbourMessageContext pkt, HostService hostService) {
282 /*
283 * First we validate the ndp packet
284 */
285 SegmentRoutingAppConfig appConfig = srManager.cfgService
286 .getConfig(srManager.appId, SegmentRoutingAppConfig.class);
287 if (appConfig != null && appConfig.suppressSubnet().contains(pkt.inPort())) {
288 // Ignore NDP packets come from suppressed ports
289 pkt.drop();
290 return;
291 }
292 if (!validateSrcIp(pkt)) {
293 log.debug("Ignore NDP packet discovered on {} with unexpected src ip address {}.",
294 pkt.inPort(), pkt.sender());
295 pkt.drop();
296 return;
297 }
298
299 if (pkt.type() == NeighbourMessageType.REQUEST) {
300 handleNdpRequest(pkt, hostService);
301 } else {
302 handleNdpReply(pkt, hostService);
303 }
304
305 }
306
307 /**
308 * Utility function to verify if the src ip belongs to the same
309 * subnet configured on the port it is seen.
310 *
311 * @param pkt the ndp packet and context information
312 * @return true if the src ip is a valid address for the subnet configured
313 * for the connect point
314 */
315 private boolean validateSrcIp(NeighbourMessageContext pkt) {
316 ConnectPoint connectPoint = pkt.inPort();
317 IpPrefix subnet = config.getPortIPv6Subnet(
318 connectPoint.deviceId(),
319 connectPoint.port()
Pier Luigi0e358632017-01-31 09:35:05 -0800320 );
Pier Ventref4b5fce2016-11-28 16:48:06 -0800321 return subnet != null && subnet.contains(pkt.sender());
322 }
323
324 /**
325 * Helper method to handle the ndp requests.
326 *
327 * @param pkt the ndp packet request and context information
328 * @param hostService the host service
329 */
330 private void handleNdpRequest(NeighbourMessageContext pkt, HostService hostService) {
331 /*
332 * ND request for the gateway. We have to reply on behalf
333 * of the gateway.
334 */
335 if (isNdpForGateway(pkt)) {
336 log.debug("Sending NDP reply on behalf of the router");
Pier Ventre735b8c82016-12-02 08:16:05 -0800337 sendResponse(pkt, config.getRouterMacForAGatewayIp(pkt.target()), hostService);
Pier Ventref4b5fce2016-11-28 16:48:06 -0800338 } else {
339 /*
340 * ND request for an host. We do a search by Ip.
341 */
342 Set<Host> hosts = hostService.getHostsByIp(pkt.target());
343 /*
344 * Possible misconfiguration ? In future this case
345 * should be handled we can have same hosts in different
346 * vlans.
347 */
348 if (hosts.size() > 1) {
349 log.warn("More than one host with IP {}", pkt.target());
350 }
351 Host targetHost = hosts.stream().findFirst().orElse(null);
352 /*
353 * If we know the host forward to its attachment
354 * point.
355 */
356 if (targetHost != null) {
357 log.debug("Forward NDP request to the target host");
358 pkt.forward(targetHost.location());
359 } else {
360 /*
361 * Flood otherwise.
362 */
363 log.debug("Flood NDP request to the target subnet");
364 flood(pkt);
365 }
366 }
367 }
368
369 /**
370 * Helper method to handle the ndp replies.
371 *
372 * @param pkt the ndp packet reply and context information
373 * @param hostService the host service
374 */
375 private void handleNdpReply(NeighbourMessageContext pkt, HostService hostService) {
376 if (isNdpForGateway(pkt)) {
377 log.debug("Forwarding all the ip packets we stored");
378 Ip6Address hostIpAddress = pkt.sender().getIp6Address();
379 srManager.ipHandler.forwardPackets(pkt.inPort().deviceId(), hostIpAddress);
380 } else {
381 HostId hostId = HostId.hostId(pkt.dstMac(), pkt.vlan());
382 Host targetHost = hostService.getHost(hostId);
383 if (targetHost != null) {
384 log.debug("Forwarding the reply to the host");
385 pkt.forward(targetHost.location());
386 } else {
387 /*
388 * We don't have to flood towards spine facing ports.
389 */
Charles Chan59cc16d2017-02-02 16:20:42 -0800390 if (pkt.vlan().equals(SegmentRoutingManager.INTERNAL_VLAN)) {
Pier Ventref4b5fce2016-11-28 16:48:06 -0800391 return;
392 }
393 log.debug("Flooding the reply to the subnet");
394 flood(pkt);
395 }
396 }
397 }
398
399 /**
400 * Utility to verify if the ND are for the gateway.
401 *
402 * @param pkt the ndp packet
403 * @return true if the ndp is for the gateway. False otherwise
404 */
405 private boolean isNdpForGateway(NeighbourMessageContext pkt) {
406 DeviceId deviceId = pkt.inPort().deviceId();
407 Set<IpAddress> gatewayIpAddresses = null;
408 try {
409 if (pkt.target().equals(config.getRouterIpv6(deviceId))) {
410 return true;
411 }
412 gatewayIpAddresses = config.getPortIPs(deviceId);
413 } catch (DeviceConfigNotFoundException e) {
414 log.warn(e.getMessage() + " Aborting check for router IP in processing ndp");
415 }
416 if (gatewayIpAddresses != null &&
417 gatewayIpAddresses.contains(pkt.target())) {
418 return true;
419 }
420 return false;
421 }
422
423 /**
Pier Ventre735b8c82016-12-02 08:16:05 -0800424 * Sends a NDP request for the target IP address to all ports except in-port.
Pier Ventref4b5fce2016-11-28 16:48:06 -0800425 *
Pier Ventre735b8c82016-12-02 08:16:05 -0800426 * @param deviceId Switch device ID
427 * @param targetAddress target IP address for ARP
428 * @param inPort in-port
Pier Ventref4b5fce2016-11-28 16:48:06 -0800429 */
Pier Ventre735b8c82016-12-02 08:16:05 -0800430 public void sendNdpRequest(DeviceId deviceId, IpAddress targetAddress, ConnectPoint inPort) {
431 byte[] senderMacAddress = new byte[MacAddress.MAC_ADDRESS_LENGTH];
432 byte[] senderIpAddress = new byte[Ip6Address.BYTE_LENGTH];
433 /*
434 * Retrieves device info.
435 */
Pier Luigia905c0c2017-01-29 12:38:48 -0800436 if (!getSenderInfo(senderMacAddress, senderIpAddress, deviceId, targetAddress)) {
437 log.warn("Aborting sendNdpRequest, we cannot get all the information needed");
438 return;
439 }
Pier Ventre735b8c82016-12-02 08:16:05 -0800440 /*
441 * We have to compute the dst mac address and dst
442 * ip address.
443 */
444 byte[] dstIp = IPv6.getSolicitNodeAddress(targetAddress.toOctets());
445 byte[] dstMac = IPv6.getMCastMacAddress(dstIp);
446 /*
447 * Creates the request.
448 */
449 Ethernet ndpRequest = NeighborSolicitation.buildNdpSolicit(
450 targetAddress.toOctets(),
451 senderIpAddress,
452 dstIp,
453 senderMacAddress,
454 dstMac,
455 VlanId.NONE
456 );
457 flood(ndpRequest, inPort, targetAddress);
Pier Ventref4b5fce2016-11-28 16:48:06 -0800458 }
459
Pier Luigi7dad71c2017-02-01 13:50:04 -0800460 /////////////////////////////////////////////////////////////////
461 // XXX Neighbour hacking, temporary workaround will be //
462 // removed as soon as possible, when the bridging will //
463 // be implemented. For now, it's fine to leave this //
464 /////////////////////////////////////////////////////////////////
465
Pier Luigi7dad71c2017-02-01 13:50:04 -0800466 // XXX Neighbour hacking, this method is used to handle
467 // the ICMPv6 protocols for the upstream port
468 public boolean handleUPstreamPackets(PacketContext packetContext) {
469 InboundPacket pkt = packetContext.inPacket();
470 Ethernet ethernet = pkt.parsed();
Pier Luigi721b6622017-02-03 13:34:21 -0800471 if (srManager.vRouterCP == null || srManager.upstreamCP == null) {
Pier Luigi7dad71c2017-02-01 13:50:04 -0800472 return false;
473 }
Pier Luigi721b6622017-02-03 13:34:21 -0800474 if (pkt.receivedFrom().equals(srManager.upstreamCP)) {
475 sendTo(ByteBuffer.wrap(ethernet.serialize()), srManager.vRouterCP);
Pier Luigi7dad71c2017-02-01 13:50:04 -0800476 return true;
477 }
478 return false;
479 }
480
Pier Luigi7dad71c2017-02-01 13:50:04 -0800481 // XXX Neigbour hack. To send out a packet
482 private void sendTo(ByteBuffer packet, ConnectPoint outPort) {
483 TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
484 builder.setOutput(outPort.port());
485 srManager.packetService.emit(new DefaultOutboundPacket(outPort.deviceId(),
486 builder.build(), packet));
487 }
488
sanghob35a6192015-04-01 13:05:26 -0700489}