Jonathan Hart
Committed by Pavlin Radoslavov

Handle packets that can't be deserialized properly.

Catch BufferUnderflowExceptions that occur while trying to deserialzed
Ethernet packet, and account for the fact that packets may not have been
deserialized correctly when using InboundPackets.

Addresses ONOS-605.

Change-Id: Ia7191e62a339125c9c4d3fe0cf63f9c33eb74cb5
...@@ -27,6 +27,7 @@ import org.apache.felix.scr.annotations.Modified; ...@@ -27,6 +27,7 @@ import org.apache.felix.scr.annotations.Modified;
27 import org.apache.felix.scr.annotations.Property; 27 import org.apache.felix.scr.annotations.Property;
28 import org.apache.felix.scr.annotations.Reference; 28 import org.apache.felix.scr.annotations.Reference;
29 import org.apache.felix.scr.annotations.ReferenceCardinality; 29 import org.apache.felix.scr.annotations.ReferenceCardinality;
30 +import org.onlab.packet.Ethernet;
30 import org.onosproject.core.ApplicationId; 31 import org.onosproject.core.ApplicationId;
31 import org.onosproject.core.CoreService; 32 import org.onosproject.core.CoreService;
32 import org.onosproject.net.Host; 33 import org.onosproject.net.Host;
...@@ -46,7 +47,6 @@ import org.onosproject.net.packet.PacketContext; ...@@ -46,7 +47,6 @@ import org.onosproject.net.packet.PacketContext;
46 import org.onosproject.net.packet.PacketProcessor; 47 import org.onosproject.net.packet.PacketProcessor;
47 import org.onosproject.net.packet.PacketService; 48 import org.onosproject.net.packet.PacketService;
48 import org.onosproject.net.topology.TopologyService; 49 import org.onosproject.net.topology.TopologyService;
49 -import org.onlab.packet.Ethernet;
50 import org.osgi.service.component.ComponentContext; 50 import org.osgi.service.component.ComponentContext;
51 import org.slf4j.Logger; 51 import org.slf4j.Logger;
52 52
...@@ -167,6 +167,10 @@ public class ReactiveForwarding { ...@@ -167,6 +167,10 @@ public class ReactiveForwarding {
167 InboundPacket pkt = context.inPacket(); 167 InboundPacket pkt = context.inPacket();
168 Ethernet ethPkt = pkt.parsed(); 168 Ethernet ethPkt = pkt.parsed();
169 169
170 + if (ethPkt == null) {
171 + return;
172 + }
173 +
170 // Bail if this is deemed to be a control packet. 174 // Bail if this is deemed to be a control packet.
171 if (isControlPacket(ethPkt)) { 175 if (isControlPacket(ethPkt)) {
172 return; 176 return;
......
...@@ -15,11 +15,14 @@ ...@@ -15,11 +15,14 @@
15 */ 15 */
16 package org.onosproject.ifwd; 16 package org.onosproject.ifwd;
17 17
18 +import static org.slf4j.LoggerFactory.getLogger;
19 +
18 import org.apache.felix.scr.annotations.Activate; 20 import org.apache.felix.scr.annotations.Activate;
19 import org.apache.felix.scr.annotations.Component; 21 import org.apache.felix.scr.annotations.Component;
20 import org.apache.felix.scr.annotations.Deactivate; 22 import org.apache.felix.scr.annotations.Deactivate;
21 import org.apache.felix.scr.annotations.Reference; 23 import org.apache.felix.scr.annotations.Reference;
22 import org.apache.felix.scr.annotations.ReferenceCardinality; 24 import org.apache.felix.scr.annotations.ReferenceCardinality;
25 +import org.onlab.packet.Ethernet;
23 import org.onosproject.core.ApplicationId; 26 import org.onosproject.core.ApplicationId;
24 import org.onosproject.core.CoreService; 27 import org.onosproject.core.CoreService;
25 import org.onosproject.net.Host; 28 import org.onosproject.net.Host;
...@@ -39,11 +42,8 @@ import org.onosproject.net.packet.PacketContext; ...@@ -39,11 +42,8 @@ import org.onosproject.net.packet.PacketContext;
39 import org.onosproject.net.packet.PacketProcessor; 42 import org.onosproject.net.packet.PacketProcessor;
40 import org.onosproject.net.packet.PacketService; 43 import org.onosproject.net.packet.PacketService;
41 import org.onosproject.net.topology.TopologyService; 44 import org.onosproject.net.topology.TopologyService;
42 -import org.onlab.packet.Ethernet;
43 import org.slf4j.Logger; 45 import org.slf4j.Logger;
44 46
45 -import static org.slf4j.LoggerFactory.getLogger;
46 -
47 /** 47 /**
48 * WORK-IN-PROGRESS: Sample reactive forwarding application using intent framework. 48 * WORK-IN-PROGRESS: Sample reactive forwarding application using intent framework.
49 */ 49 */
...@@ -100,6 +100,10 @@ public class IntentReactiveForwarding { ...@@ -100,6 +100,10 @@ public class IntentReactiveForwarding {
100 InboundPacket pkt = context.inPacket(); 100 InboundPacket pkt = context.inPacket();
101 Ethernet ethPkt = pkt.parsed(); 101 Ethernet ethPkt = pkt.parsed();
102 102
103 + if (ethPkt == null) {
104 + return;
105 + }
106 +
103 HostId srcId = HostId.hostId(ethPkt.getSourceMAC()); 107 HostId srcId = HostId.hostId(ethPkt.getSourceMAC());
104 HostId dstId = HostId.hostId(ethPkt.getDestinationMAC()); 108 HostId dstId = HostId.hostId(ethPkt.getDestinationMAC());
105 109
......
...@@ -31,6 +31,12 @@ import org.apache.felix.scr.annotations.Deactivate; ...@@ -31,6 +31,12 @@ import org.apache.felix.scr.annotations.Deactivate;
31 import org.apache.felix.scr.annotations.Reference; 31 import org.apache.felix.scr.annotations.Reference;
32 import org.apache.felix.scr.annotations.ReferenceCardinality; 32 import org.apache.felix.scr.annotations.ReferenceCardinality;
33 import org.apache.felix.scr.annotations.Service; 33 import org.apache.felix.scr.annotations.Service;
34 +import org.onlab.packet.ARP;
35 +import org.onlab.packet.Ethernet;
36 +import org.onlab.packet.Ip4Address;
37 +import org.onlab.packet.IpAddress;
38 +import org.onlab.packet.MacAddress;
39 +import org.onlab.packet.VlanId;
34 import org.onosproject.core.ApplicationId; 40 import org.onosproject.core.ApplicationId;
35 import org.onosproject.core.CoreService; 41 import org.onosproject.core.CoreService;
36 import org.onosproject.net.ConnectPoint; 42 import org.onosproject.net.ConnectPoint;
...@@ -61,12 +67,6 @@ import org.onosproject.net.packet.InboundPacket; ...@@ -61,12 +67,6 @@ import org.onosproject.net.packet.InboundPacket;
61 import org.onosproject.net.packet.PacketContext; 67 import org.onosproject.net.packet.PacketContext;
62 import org.onosproject.net.packet.PacketService; 68 import org.onosproject.net.packet.PacketService;
63 import org.onosproject.net.proxyarp.ProxyArpService; 69 import org.onosproject.net.proxyarp.ProxyArpService;
64 -import org.onlab.packet.ARP;
65 -import org.onlab.packet.Ethernet;
66 -import org.onlab.packet.Ip4Address;
67 -import org.onlab.packet.IpAddress;
68 -import org.onlab.packet.MacAddress;
69 -import org.onlab.packet.VlanId;
70 import org.slf4j.Logger; 70 import org.slf4j.Logger;
71 71
72 import com.google.common.collect.HashMultimap; 72 import com.google.common.collect.HashMultimap;
...@@ -309,7 +309,7 @@ public class ProxyArpManager implements ProxyArpService { ...@@ -309,7 +309,7 @@ public class ProxyArpManager implements ProxyArpService {
309 public boolean handleArp(PacketContext context) { 309 public boolean handleArp(PacketContext context) {
310 InboundPacket pkt = context.inPacket(); 310 InboundPacket pkt = context.inPacket();
311 Ethernet ethPkt = pkt.parsed(); 311 Ethernet ethPkt = pkt.parsed();
312 - if (ethPkt.getEtherType() == Ethernet.TYPE_ARP) { 312 + if (ethPkt != null && ethPkt.getEtherType() == Ethernet.TYPE_ARP) {
313 ARP arp = (ARP) ethPkt.getPayload(); 313 ARP arp = (ARP) ethPkt.getPayload();
314 if (arp.getOpCode() == ARP.OP_REPLY) { 314 if (arp.getOpCode() == ARP.OP_REPLY) {
315 forward(ethPkt); 315 forward(ethPkt);
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 package org.onosproject.openflow.controller; 16 package org.onosproject.openflow.controller;
17 17
18 18
19 +import java.nio.BufferUnderflowException;
19 import java.util.Collections; 20 import java.util.Collections;
20 import java.util.concurrent.atomic.AtomicBoolean; 21 import java.util.concurrent.atomic.AtomicBoolean;
21 22
...@@ -85,8 +86,12 @@ public final class DefaultOpenFlowPacketContext implements OpenFlowPacketContext ...@@ -85,8 +86,12 @@ public final class DefaultOpenFlowPacketContext implements OpenFlowPacketContext
85 @Override 86 @Override
86 public Ethernet parsed() { 87 public Ethernet parsed() {
87 Ethernet eth = new Ethernet(); 88 Ethernet eth = new Ethernet();
88 - eth.deserialize(pktin.getData(), 0, pktin.getTotalLen()); 89 + try {
89 - return eth; 90 + eth.deserialize(pktin.getData(), 0, pktin.getData().length);
91 + return eth;
92 + } catch (BufferUnderflowException e) {
93 + return null;
94 + }
90 } 95 }
91 96
92 @Override 97 @Override
......
...@@ -15,6 +15,11 @@ ...@@ -15,6 +15,11 @@
15 */ 15 */
16 package org.onosproject.provider.host.impl; 16 package org.onosproject.provider.host.impl;
17 17
18 +import static org.slf4j.LoggerFactory.getLogger;
19 +
20 +import java.util.Dictionary;
21 +import java.util.Set;
22 +
18 import org.apache.felix.scr.annotations.Activate; 23 import org.apache.felix.scr.annotations.Activate;
19 import org.apache.felix.scr.annotations.Component; 24 import org.apache.felix.scr.annotations.Component;
20 import org.apache.felix.scr.annotations.Deactivate; 25 import org.apache.felix.scr.annotations.Deactivate;
...@@ -22,6 +27,14 @@ import org.apache.felix.scr.annotations.Modified; ...@@ -22,6 +27,14 @@ import org.apache.felix.scr.annotations.Modified;
22 import org.apache.felix.scr.annotations.Property; 27 import org.apache.felix.scr.annotations.Property;
23 import org.apache.felix.scr.annotations.Reference; 28 import org.apache.felix.scr.annotations.Reference;
24 import org.apache.felix.scr.annotations.ReferenceCardinality; 29 import org.apache.felix.scr.annotations.ReferenceCardinality;
30 +import org.onlab.packet.ARP;
31 +import org.onlab.packet.Ethernet;
32 +import org.onlab.packet.IPacket;
33 +import org.onlab.packet.IPv6;
34 +import org.onlab.packet.IpAddress;
35 +import org.onlab.packet.VlanId;
36 +import org.onlab.packet.ndp.NeighborAdvertisement;
37 +import org.onlab.packet.ndp.NeighborSolicitation;
25 import org.onosproject.core.ApplicationId; 38 import org.onosproject.core.ApplicationId;
26 import org.onosproject.core.CoreService; 39 import org.onosproject.core.CoreService;
27 import org.onosproject.net.ConnectPoint; 40 import org.onosproject.net.ConnectPoint;
...@@ -52,22 +65,9 @@ import org.onosproject.net.provider.AbstractProvider; ...@@ -52,22 +65,9 @@ import org.onosproject.net.provider.AbstractProvider;
52 import org.onosproject.net.provider.ProviderId; 65 import org.onosproject.net.provider.ProviderId;
53 import org.onosproject.net.topology.Topology; 66 import org.onosproject.net.topology.Topology;
54 import org.onosproject.net.topology.TopologyService; 67 import org.onosproject.net.topology.TopologyService;
55 -import org.onlab.packet.ARP;
56 -import org.onlab.packet.Ethernet;
57 -import org.onlab.packet.IpAddress;
58 -import org.onlab.packet.IPacket;
59 -import org.onlab.packet.IPv6;
60 -import org.onlab.packet.ndp.NeighborAdvertisement;
61 -import org.onlab.packet.ndp.NeighborSolicitation;
62 -import org.onlab.packet.VlanId;
63 import org.osgi.service.component.ComponentContext; 68 import org.osgi.service.component.ComponentContext;
64 import org.slf4j.Logger; 69 import org.slf4j.Logger;
65 70
66 -import java.util.Dictionary;
67 -import java.util.Set;
68 -
69 -import static org.slf4j.LoggerFactory.getLogger;
70 -
71 /** 71 /**
72 * Provider which uses an OpenFlow controller to detect network 72 * Provider which uses an OpenFlow controller to detect network
73 * end-station hosts. 73 * end-station hosts.
...@@ -200,6 +200,10 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid ...@@ -200,6 +200,10 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid
200 } 200 }
201 Ethernet eth = context.inPacket().parsed(); 201 Ethernet eth = context.inPacket().parsed();
202 202
203 + if (eth == null) {
204 + return;
205 + }
206 +
203 VlanId vlan = VlanId.vlanId(eth.getVlanID()); 207 VlanId vlan = VlanId.vlanId(eth.getVlanID());
204 ConnectPoint heardOn = context.inPacket().receivedFrom(); 208 ConnectPoint heardOn = context.inPacket().receivedFrom();
205 209
......
...@@ -33,6 +33,9 @@ import java.util.concurrent.atomic.AtomicInteger; ...@@ -33,6 +33,9 @@ import java.util.concurrent.atomic.AtomicInteger;
33 33
34 import org.jboss.netty.util.Timeout; 34 import org.jboss.netty.util.Timeout;
35 import org.jboss.netty.util.TimerTask; 35 import org.jboss.netty.util.TimerTask;
36 +import org.onlab.packet.Ethernet;
37 +import org.onlab.packet.ONOSLLDP;
38 +import org.onlab.util.Timer;
36 import org.onosproject.mastership.MastershipService; 39 import org.onosproject.mastership.MastershipService;
37 import org.onosproject.net.ConnectPoint; 40 import org.onosproject.net.ConnectPoint;
38 import org.onosproject.net.Device; 41 import org.onosproject.net.Device;
...@@ -47,9 +50,6 @@ import org.onosproject.net.packet.DefaultOutboundPacket; ...@@ -47,9 +50,6 @@ import org.onosproject.net.packet.DefaultOutboundPacket;
47 import org.onosproject.net.packet.OutboundPacket; 50 import org.onosproject.net.packet.OutboundPacket;
48 import org.onosproject.net.packet.PacketContext; 51 import org.onosproject.net.packet.PacketContext;
49 import org.onosproject.net.packet.PacketService; 52 import org.onosproject.net.packet.PacketService;
50 -import org.onlab.packet.Ethernet;
51 -import org.onlab.packet.ONOSLLDP;
52 -import org.onlab.util.Timer;
53 import org.slf4j.Logger; 53 import org.slf4j.Logger;
54 54
55 // TODO: add 'fast discovery' mode: drop LLDPs in destination switch but listen for flow_removed messages 55 // TODO: add 'fast discovery' mode: drop LLDPs in destination switch but listen for flow_removed messages
...@@ -208,6 +208,10 @@ public class LinkDiscovery implements TimerTask { ...@@ -208,6 +208,10 @@ public class LinkDiscovery implements TimerTask {
208 */ 208 */
209 public boolean handleLLDP(PacketContext context) { 209 public boolean handleLLDP(PacketContext context) {
210 Ethernet eth = context.inPacket().parsed(); 210 Ethernet eth = context.inPacket().parsed();
211 + if (eth == null) {
212 + return false;
213 + }
214 +
211 ONOSLLDP onoslldp = ONOSLLDP.parseONOSLLDP(eth); 215 ONOSLLDP onoslldp = ONOSLLDP.parseONOSLLDP(eth);
212 if (onoslldp != null) { 216 if (onoslldp != null) {
213 final PortNumber dstPort = 217 final PortNumber dstPort =
......