vRouter: ignore routes that don't come from Quagga
Change-Id: I1a67a18b7f5f0a4e43156c017b92c12789e81104
diff --git a/apps/routing/src/main/java/org/onosproject/routing/fpm/FpmManager.java b/apps/routing/src/main/java/org/onosproject/routing/fpm/FpmManager.java
index d89ae4e..efda592 100644
--- a/apps/routing/src/main/java/org/onosproject/routing/fpm/FpmManager.java
+++ b/apps/routing/src/main/java/org/onosproject/routing/fpm/FpmManager.java
@@ -41,6 +41,7 @@
import org.onosproject.routing.fpm.protocol.RouteAttributeDst;
import org.onosproject.routing.fpm.protocol.RouteAttributeGateway;
import org.onosproject.routing.fpm.protocol.RtNetlink;
+import org.onosproject.routing.fpm.protocol.RtProtocol;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -145,6 +146,11 @@
log.trace("Received FPM message: {}", fpmMessage);
}
+ if (rtNetlink.protocol() != RtProtocol.ZEBRA) {
+ log.trace("Ignoring non-zebra route");
+ return;
+ }
+
IpAddress dstAddress = null;
IpAddress gateway = null;
diff --git a/apps/routing/src/main/java/org/onosproject/routing/fpm/protocol/RtNetlink.java b/apps/routing/src/main/java/org/onosproject/routing/fpm/protocol/RtNetlink.java
index 94b9d62..9017618 100644
--- a/apps/routing/src/main/java/org/onosproject/routing/fpm/protocol/RtNetlink.java
+++ b/apps/routing/src/main/java/org/onosproject/routing/fpm/protocol/RtNetlink.java
@@ -43,7 +43,7 @@
private final int srcLength;
private final short tos;
private final short table;
- private final short protocol;
+ private final RtProtocol protocol;
private final short scope;
private final short type;
private final long flags;
@@ -69,7 +69,7 @@
int srcLength,
short tos,
short table,
- short protocol,
+ RtProtocol protocol,
short scope,
short type,
long flags,
@@ -139,7 +139,7 @@
*
* @return protocol
*/
- public short protocol() {
+ public RtProtocol protocol() {
return protocol;
}
@@ -222,6 +222,8 @@
long flags = Integer.reverseBytes(bb.getInt());
List<RouteAttribute> attributes = new ArrayList<>();
+ RtProtocol rtProtocol = RtProtocol.get(protocol);
+
while (bb.hasRemaining()) {
RouteAttribute attribute = RouteAttribute.decode(buffer, bb.position(),
bb.limit() - bb.position());
@@ -235,7 +237,7 @@
srcLength,
tos,
table,
- protocol,
+ rtProtocol,
scope,
type,
flags,
diff --git a/apps/routing/src/main/java/org/onosproject/routing/fpm/protocol/RtProtocol.java b/apps/routing/src/main/java/org/onosproject/routing/fpm/protocol/RtProtocol.java
new file mode 100644
index 0000000..0b2ba09
--- /dev/null
+++ b/apps/routing/src/main/java/org/onosproject/routing/fpm/protocol/RtProtocol.java
@@ -0,0 +1,141 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.routing.fpm.protocol;
+
+/**
+ * RtNetlink protocol value.
+ * <p>
+ * This is a subset of the protocol values used in rtnetlink.
+ * Taken from linux/rtnetlink.h
+ * </p>
+ */
+public enum RtProtocol {
+ /**
+ * Unspecified.
+ */
+ UNSPEC((short) 0),
+
+ /**
+ * Route installed by ICMP redirects.
+ */
+ REDIRECT((short) 1),
+
+ /**
+ * Route installed by kernel.
+ */
+ KERNEL((short) 2),
+
+ /**
+ * Route installed during boot.
+ */
+ BOOT((short) 3),
+
+ /**
+ * Route installed by administrator.
+ */
+ STATIC((short) 4),
+
+ /**
+ * GateD.
+ */
+ GATED((short) 8),
+
+ /**
+ * RDISC/ND router advertisements.
+ */
+ RA((short) 9),
+
+ /**
+ * Merit MRT.
+ */
+ MRT((short) 10),
+
+ /**
+ * Zebra.
+ */
+ ZEBRA((short) 11),
+
+ /**
+ * BIRD.
+ */
+ BIRD((short) 12),
+
+ /**
+ * DECnet routing daemon.
+ */
+ DNROUTED((short) 13),
+
+ /**
+ * XORP.
+ */
+ XORP((short) 14),
+
+ /**
+ * Netsukuku.
+ */
+ NTK((short) 15),
+
+ /**
+ * DHCP client.
+ */
+ DHCP((short) 16),
+
+ /**
+ * Multicast daemon.
+ */
+ MROUTED((short) 17),
+
+ /**
+ * Unknown.
+ */
+ UNKNOWN((short) 0);
+
+ private final short value;
+
+ /**
+ * Constructor.
+ *
+ * @param value value
+ */
+ RtProtocol(short value) {
+ this.value = value;
+ }
+
+ /**
+ * Returns the value.
+ *
+ * @return value
+ */
+ public short value() {
+ return value;
+ }
+
+ /**
+ * Gets the RtProtocol for the given integer value.
+ *
+ * @param value value
+ * @return RtProtocol, or null if unsupported type value
+ */
+ public static RtProtocol get(short value) {
+ for (RtProtocol p : RtProtocol.values()) {
+ if (p.value() == value) {
+ return p;
+ }
+ }
+ return UNKNOWN;
+ }
+}