REST API for FPM Accept Routes

Change-Id: I2cd2f2ac5e7c7079ae87bfe32e76baeb97567e02
diff --git a/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/FpmConnectionInfo.java b/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/FpmConnectionInfo.java
index cf8c393..1a54fe9 100644
--- a/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/FpmConnectionInfo.java
+++ b/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/FpmConnectionInfo.java
@@ -26,6 +26,7 @@
     private final NodeId connectedTo;
     private final long connectTime;
     private final FpmPeer peer;
+    private final boolean acceptRoutes;
 
     /**
      * Creates a new connection info.
@@ -34,13 +35,31 @@
      * @param peer FPM peer
      * @param connectTime time the connection was made
      */
+    @Deprecated
     public FpmConnectionInfo(NodeId connectedTo, FpmPeer peer, long connectTime) {
         this.connectedTo = connectedTo;
         this.peer = peer;
         this.connectTime = connectTime;
+        this.acceptRoutes = true;
     }
 
     /**
+     * Creates a new connection info.
+     *
+     * @param connectedTo ONOS node the FPM peer is connected to
+     * @param peer FPM peer
+     * @param connectTime time the connection was made
+     * @param acceptRoutes flag to accept or discard routes
+     */
+    FpmConnectionInfo(NodeId connectedTo, FpmPeer peer, long connectTime, boolean acceptRoutes) {
+        this.connectedTo = connectedTo;
+        this.peer = peer;
+        this.connectTime = connectTime;
+        this.acceptRoutes = acceptRoutes;
+    }
+
+
+    /**
      * Returns the node the FPM peers is connected to.
      *
      * @return ONOS node
@@ -66,4 +85,13 @@
     public long connectTime() {
         return connectTime;
     }
+
+    /**
+     * Returns the acceptRoutes flag status of the peer.
+     *
+     * @return acceptRoutes flag
+     */
+    public boolean isAcceptRoutes() {
+        return acceptRoutes;
+    }
 }
diff --git a/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/FpmInfoService.java b/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/FpmInfoService.java
index c604707..a56c48d 100644
--- a/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/FpmInfoService.java
+++ b/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/FpmInfoService.java
@@ -16,8 +16,10 @@
 
 package org.onosproject.routing.fpm;
 
+import java.util.Collection;
 import java.util.Map;
 
+
 /**
  * Provides information about the FPM route receiver module.
  */
@@ -41,4 +43,12 @@
      * Pushes all local FPM routes to route store.
      */
     void pushFpmRoutes();
+
+    /**
+     * Updates the acceptRoute flag to either accept or discard routes for input peers address.
+     *
+     * @param peers peers for which flag is updated
+     */
+    void updateAcceptRouteFlag(Collection<FpmPeerAcceptRoutes> peers);
+
 }
diff --git a/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/FpmManager.java b/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/FpmManager.java
index e922755..6b6df43 100644
--- a/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/FpmManager.java
+++ b/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/FpmManager.java
@@ -88,6 +88,7 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.Iterator;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
@@ -688,6 +689,41 @@
                         e -> toFpmInfo(e.getKey(), e.getValue())));
     }
 
+    @Override
+    public void updateAcceptRouteFlag(Collection<FpmPeerAcceptRoutes> modifiedPeers) {
+        modifiedPeers.forEach(modifiedPeer -> {
+            log.debug("FPM connection to {} is disabled", modifiedPeer);
+            NodeId localNode = clusterService.getLocalNode().id();
+            log.debug("Peer Flag {}", modifiedPeer.isAcceptRoutes());
+            peers.compute(modifiedPeer.peer(), (p, infos) -> {
+                if (infos == null) {
+                    return null;
+                }
+                Iterator<FpmConnectionInfo> iterator = infos.iterator();
+                if (iterator.hasNext()) {
+                    FpmConnectionInfo connectionInfo = iterator.next();
+                    if (connectionInfo.isAcceptRoutes() == modifiedPeer.isAcceptRoutes()) {
+                        return null;
+                    }
+                    localPeers.remove(modifiedPeer.peer());
+                    infos.remove(connectionInfo);
+                    infos.add(new FpmConnectionInfo(localNode, modifiedPeer.peer(),
+                            System.currentTimeMillis(), modifiedPeer.isAcceptRoutes()));
+                    localPeers.put(modifiedPeer.peer(), infos);
+                }
+                Map<IpPrefix, Route> routes = fpmRoutes.get(modifiedPeer.peer());
+                if (routes != null && !modifiedPeer.isAcceptRoutes()) {
+                    updateRouteStore(Lists.newArrayList(), routes.values());
+                } else {
+                    updateRouteStore(routes.values(), Lists.newArrayList());
+                }
+
+                return infos;
+            });
+        });
+
+    }
+
     private class InternalFpmListener implements FpmListener {
         @Override
         public void fpmMessage(FpmPeer peer, FpmHeader fpmMessage) {
@@ -707,7 +743,7 @@
                     infos = new HashSet<>();
                 }
 
-                infos.add(new FpmConnectionInfo(localNode, peer, System.currentTimeMillis()));
+                infos.add(new FpmConnectionInfo(localNode, peer, System.currentTimeMillis(), true));
                 localPeers.put(peer, infos);
                 return infos;
             });
diff --git a/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/FpmPeerAcceptRoutes.java b/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/FpmPeerAcceptRoutes.java
new file mode 100644
index 0000000..18ce018
--- /dev/null
+++ b/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/FpmPeerAcceptRoutes.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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;
+
+import java.util.Objects;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+
+/**
+ * Represents an FPM peer with accept routes flag.
+ */
+public class FpmPeerAcceptRoutes {
+
+    private final boolean isAcceptRoutes;
+    private final FpmPeer peer;
+
+
+
+    /**
+     * Creates a new FPM peer.
+     *
+     * @param peer Fpm Peer
+     * @param isAcceptRoutes is route accepted on peer
+     *
+     */
+    public FpmPeerAcceptRoutes(FpmPeer peer, boolean isAcceptRoutes) {
+        this.peer = peer;
+        this.isAcceptRoutes = isAcceptRoutes;
+    }
+
+    /**
+     * Returns isAcceptRoutes flag status.
+     *
+     * @return isAcceptRoutes
+     */
+    public boolean isAcceptRoutes() {
+        return isAcceptRoutes;
+    }
+
+    /**
+     * Returns the FPM peer.
+     *
+     * @return FPM peer
+     */
+    public FpmPeer peer() {
+        return peer;
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(isAcceptRoutes, peer);
+    }
+
+    @Override
+    public boolean equals(Object other) {
+        if (this == other) {
+            return true;
+        }
+
+        if (!(other instanceof FpmPeerAcceptRoutes)) {
+            return false;
+        }
+
+        FpmPeerAcceptRoutes that = (FpmPeerAcceptRoutes) other;
+
+        return Objects.equals(this.isAcceptRoutes, that.isAcceptRoutes) &&
+                Objects.equals(this.peer, that.peer);
+    }
+
+    @Override
+    public String toString() {
+        return toStringHelper(this)
+                .add("peer", peer)
+                .add("isAcceptRoutes", isAcceptRoutes)
+                .toString();
+    }
+
+}
diff --git a/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/cli/FpmAcceptRoutesInfoCommand.java b/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/cli/FpmAcceptRoutesInfoCommand.java
new file mode 100644
index 0000000..b219ca2
--- /dev/null
+++ b/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/cli/FpmAcceptRoutesInfoCommand.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.cli;
+
+import org.apache.karaf.shell.api.action.Argument;
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.onlab.packet.IpAddress;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.routing.fpm.FpmInfoService;
+import org.onosproject.routing.fpm.FpmPeer;
+import org.onosproject.routing.fpm.FpmPeerInfo;
+
+import java.util.Comparator;
+import java.util.Map;
+
+/**
+ * Displays the acceptRoute flag value for given peer.
+ */
+@Service
+@Command(scope = "onos", name = "fpm-get-accept-route",
+        description = "Displays the acceptRoute flag value for given peer")
+public class FpmAcceptRoutesInfoCommand extends AbstractShellCommand {
+
+    private static final String FORMAT = "peer %s  port %s acceptRoutes %s";
+
+    @Argument(index = 0, name = "peerAddress", description = "Peer Ip address",
+            required = false, multiValued = false)
+    String peerAddress = null;
+
+
+
+    @Override
+    protected void doExecute() {
+        FpmInfoService fpmInfo = get(FpmInfoService.class);
+        if (peerAddress != null) {
+            IpAddress address = IpAddress.valueOf(peerAddress);
+            fpmInfo.peers().entrySet().stream()
+                    .filter(peer -> peer.getKey().address().equals(address))
+                    .map(Map.Entry::getValue)
+                    .forEach(this::print);
+        } else {
+            fpmInfo.peers().entrySet().stream()
+                    .sorted(Comparator.<Map.Entry<FpmPeer, FpmPeerInfo>, IpAddress>comparing(e -> e.getKey().address())
+                            .thenComparing(e -> e.getKey().port()))
+                    .map(Map.Entry::getValue)
+                    .forEach(this::print);
+        }
+    }
+
+    private void print(FpmPeerInfo info) {
+        info.connections().forEach(cinfo ->
+            print(FORMAT, cinfo.peer().address(),
+                    cinfo.peer().port(),
+                    cinfo.isAcceptRoutes())
+        );
+    }
+}
diff --git a/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/cli/FpmConnectionsList.java b/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/cli/FpmConnectionsList.java
index d797844..d0d9c3d 100644
--- a/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/cli/FpmConnectionsList.java
+++ b/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/cli/FpmConnectionsList.java
@@ -17,6 +17,7 @@
 package org.onosproject.routing.fpm.cli;
 
 import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.Argument;
 import org.apache.karaf.shell.api.action.lifecycle.Service;
 import org.onlab.packet.IpAddress;
 import org.onlab.util.Tools;
@@ -37,19 +38,32 @@
         description = "Displays the current FPM connections")
 public class FpmConnectionsList extends AbstractShellCommand {
 
-    private static final String FORMAT = "peer %s:%s connected to %s since %s %s (%d routes locally)";
+    private static final String FORMAT = "peer %s:%s connected to %s since %s %s (%d routes locally) acceptRoutes %s";
+
+    @Argument(index = 0, name = "peerAddress", description = "Peer Ip address",
+            required = false, multiValued = false)
+    String peerAddress = null;
 
     @Override
     protected void doExecute() {
         FpmInfoService fpmInfo = get(FpmInfoService.class);
 
         print(String.format("PD Pushing is %s.", fpmInfo.isPdPushEnabled() ? "enabled" : "disabled"));
+        if (peerAddress != null) {
+            IpAddress address = IpAddress.valueOf(peerAddress);
+            fpmInfo.peers().entrySet().stream()
+                    .filter(peer -> peer.getKey().address().equals(address))
+                    .map(Map.Entry::getValue)
+                    .forEach(this::print);
+        } else {
+            fpmInfo.peers().entrySet().stream()
+                    .sorted(Comparator.<Map.Entry<FpmPeer, FpmPeerInfo>, IpAddress>comparing(e -> e.getKey().address())
+                            .thenComparing(e -> e.getKey().port()))
+                    .map(Map.Entry::getValue)
+                    .forEach(this::print);
+        }
 
-        fpmInfo.peers().entrySet().stream()
-                .sorted(Comparator.<Map.Entry<FpmPeer, FpmPeerInfo>, IpAddress>comparing(e -> e.getKey().address())
-                        .thenComparing(e -> e.getKey().port()))
-                .map(Map.Entry::getValue)
-                .forEach(this::print);
+
     }
 
     private void print(FpmPeerInfo info) {
@@ -59,7 +73,8 @@
             print(FORMAT, cinfo.peer().address(), cinfo.peer().port(),
                     cinfo.connectedTo(), Tools.timeAgo(cinfo.connectTime()),
                     cinfo.connectedTo().equals(clusterService.getLocalNode().id()) ? "*" : "",
-                    info.routes())
+                    info.routes(),
+                    cinfo.isAcceptRoutes())
         );
     }
 }
diff --git a/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/cli/FpmSetAcceptRoutesCommand.java b/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/cli/FpmSetAcceptRoutesCommand.java
new file mode 100644
index 0000000..d0204ff
--- /dev/null
+++ b/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/cli/FpmSetAcceptRoutesCommand.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.cli;
+
+import org.apache.karaf.shell.api.action.Argument;
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.onlab.packet.IpAddress;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.routing.fpm.FpmInfoService;
+import org.onosproject.routing.fpm.FpmPeer;
+import org.onosproject.routing.fpm.FpmPeerAcceptRoutes;
+
+import java.util.Collections;
+
+/**
+ * Sets acceptRoute flag for given peer.
+ */
+@Service
+@Command(scope = "onos", name = "fpm-set-accept-routes",
+        description = "Adds a flag to Fpm peer to accept or discard routes")
+public class FpmSetAcceptRoutesCommand extends AbstractShellCommand {
+    @Argument(index = 0, name = "peerAddress", description = "IpAddress of peer",
+            required = true)
+    String peerAddressString = null;
+
+    @Argument(index = 1, name = "peerPort", description = "Port of peer",
+            required = true)
+    String peerPort = null;
+
+    @Argument(index = 2, name = "acceptRoutes", description = "Flag to accept or discard routes",
+            required = true)
+    String acceptRoutesString = null;
+
+    @Override
+    protected void doExecute() {
+        FpmInfoService service = AbstractShellCommand.get(FpmInfoService.class);
+
+        IpAddress peerAddress = IpAddress.valueOf(peerAddressString);
+        boolean isAcceptRoutes =  Boolean.parseBoolean(acceptRoutesString);
+        int port = Integer.parseInt(peerPort);
+        FpmPeer peer = new FpmPeer(peerAddress, port);
+        service.updateAcceptRouteFlag(Collections.singleton(new FpmPeerAcceptRoutes(peer, isAcceptRoutes)));
+
+    }
+}
diff --git a/apps/routing/fpm/web/src/main/java/org/onosproject/fpm/web/FpmAcceptRoutesCodec.java b/apps/routing/fpm/web/src/main/java/org/onosproject/fpm/web/FpmAcceptRoutesCodec.java
new file mode 100644
index 0000000..9161ee6
--- /dev/null
+++ b/apps/routing/fpm/web/src/main/java/org/onosproject/fpm/web/FpmAcceptRoutesCodec.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2015-present Open Networking Foundation
+ *
+ * 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.fpm.web;
+
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.onosproject.codec.CodecContext;
+import org.onosproject.codec.JsonCodec;
+import org.onosproject.routing.fpm.FpmPeer;
+
+import org.onlab.packet.IpAddress;
+import org.onosproject.routing.fpm.FpmPeerAcceptRoutes;
+
+/**
+ * Codec of FpmPeerInfo class.
+ */
+public final class FpmAcceptRoutesCodec extends JsonCodec<FpmPeerAcceptRoutes> {
+
+    // JSON field names
+    private static final String PEER_ADDRESS = "peerAddress";
+    private static final String PEER_PORT = "peerPort";
+    private static final String ACCEPT_ROUTES = "acceptRoutes";
+
+    @Override
+    public FpmPeerAcceptRoutes decode(ObjectNode json, CodecContext context) {
+        if (json == null || !json.isObject()) {
+            return null;
+        }
+
+        IpAddress address = IpAddress.valueOf(json.path(PEER_ADDRESS).asText());
+        int port = Integer.parseInt(json.path(PEER_PORT).asText());
+        boolean isAcceptRoutes = Boolean.valueOf(json.path(ACCEPT_ROUTES).asText());
+        FpmPeer peer = new FpmPeer(address, port);
+        FpmPeerAcceptRoutes updatedPeer = new FpmPeerAcceptRoutes(peer, isAcceptRoutes);
+        return updatedPeer;
+    }
+}
diff --git a/apps/routing/fpm/web/src/main/java/org/onosproject/fpm/web/FpmCodec.java b/apps/routing/fpm/web/src/main/java/org/onosproject/fpm/web/FpmCodec.java
index fda14db..fa127e4 100755
--- a/apps/routing/fpm/web/src/main/java/org/onosproject/fpm/web/FpmCodec.java
+++ b/apps/routing/fpm/web/src/main/java/org/onosproject/fpm/web/FpmCodec.java
@@ -22,6 +22,7 @@
 import org.onosproject.codec.JsonCodec;
 import org.onosproject.routing.fpm.FpmPeerInfo;
 
+
 /**
  * Codec of FpmPeerInfo class.
  */
@@ -33,6 +34,7 @@
     private static final String CONNECTED_TO = "connectedTo";
     private static final String CONNECTION_TIME = "connectionTime";
     private static final String LOCAL_ROUTES = "localRoutes";
+    private static final String ACCEPT_ROUTES = "acceptRoutes";
 
 
     @Override
@@ -47,6 +49,7 @@
             fpmNode.put(CONNECTED_TO, connection.connectedTo().toString());
             fpmNode.put(CONNECTION_TIME, Tools.timeAgo(connection.connectTime()));
             fpmNode.put(LOCAL_ROUTES, fpmPeerInfo.routes());
+            fpmNode.put(ACCEPT_ROUTES, connection.isAcceptRoutes());
             connectionArray.add(fpmNode);
         });
 
diff --git a/apps/routing/fpm/web/src/main/java/org/onosproject/fpm/web/FpmWebResource.java b/apps/routing/fpm/web/src/main/java/org/onosproject/fpm/web/FpmWebResource.java
index 6b6ea92..51bb0fe 100644
--- a/apps/routing/fpm/web/src/main/java/org/onosproject/fpm/web/FpmWebResource.java
+++ b/apps/routing/fpm/web/src/main/java/org/onosproject/fpm/web/FpmWebResource.java
@@ -25,15 +25,25 @@
 import org.onosproject.routing.fpm.FpmPeerInfo;
 import org.onosproject.routing.fpm.FpmInfoService;
 import org.onosproject.routing.fpm.FpmPeer;
+import org.onosproject.routing.fpm.FpmPeerAcceptRoutes;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
+import java.io.IOException;
+import static org.onlab.util.Tools.nullIsIllegal;
+import static org.onlab.util.Tools.readTreeFromStream;
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.POST;
+import java.io.InputStream;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
-
 import java.util.Comparator;
 import java.util.Map;
+import java.util.List;
 
 /**
  * FPM REST API.
@@ -41,9 +51,17 @@
 @Path("")
 public class FpmWebResource extends AbstractWebResource {
 
+    private static final String ACCEPT_ROUTES = "acceptRoutes";
+    private static final String PEER_ADDRESS = "peerAddress";
+    private static final String PEER_PORT = "peerPort";
+    protected static final String PEERS = "peers";
+    protected static final String PEERS_KEY_ERROR = "Peers key must be present";
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
     /**
      * To get all fpm connections.
      * @return 200 OK with component properties of given component and variable.
+     * @onos.rsModel FpmConnectionsGet
      */
     @GET
     @Produces(MediaType.APPLICATION_JSON)
@@ -53,6 +71,60 @@
         return Response.status(200).entity(node).build();
     }
 
+    /**
+     * Performs disabling of FPM Peer.
+     *
+     * @param stream array of peer address and accept route flag
+     * @return 200 OK disable peer.
+     * @onos.rsModel FpmPeerSetAcceptRouteFlag
+     */
+    @POST
+    @Path("acceptRoutes")
+    @Consumes(MediaType.APPLICATION_JSON)
+    @Produces(MediaType.APPLICATION_JSON)
+    public Response updateAcceptRouteFlagForConnection(InputStream stream) {
+        FpmInfoService fpmService = get(FpmInfoService.class);
+        try {
+            ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
+            ArrayNode peersArray = nullIsIllegal((ArrayNode) jsonTree.get(PEERS),
+                    PEERS_KEY_ERROR);
+            List<FpmPeerAcceptRoutes> fpmPeerRouteInfo = (new FpmAcceptRoutesCodec()).decode(peersArray, this);
+            fpmService.updateAcceptRouteFlag(fpmPeerRouteInfo);
+        } catch (IOException ex) {
+            throw new IllegalArgumentException(ex);
+        }
+
+        return Response.ok().build();
+
+    }
+
+    /**
+     * Gets peers acceptRoute Flag details.
+     * @param peerAddress peer identifier
+     * @return 200 OK with a collection of peerInfo
+     * @onos.rsModel FpmPeerGetAcceptRoutes
+     */
+    @GET
+    @Produces(MediaType.APPLICATION_JSON)
+    @Path("acceptRoutes/{peerAddress}")
+    public Response getPeerAcceptRouteInfo(@PathParam("peerAddress") String peerAddress) {
+        ObjectNode node = getFpmPeerAcceptFlagInfoJsonOutput(peerAddress);
+        return Response.status(200).entity(node).build();
+    }
+
+    /**
+     * Gets all peers acceptRoute Flag details.
+     * @return 200 OK with a collection of peerInfo
+     * @onos.rsModel FpmGetAcceptRoutes
+     */
+    @GET
+    @Produces(MediaType.APPLICATION_JSON)
+    @Path("acceptRoutes/")
+    public Response getAllPeerAcceptRouteInfo() {
+        ObjectNode node = getFpmPeerRouteInfoJsonOutput();
+        return Response.status(200).entity(node).build();
+    }
+
 
     private ObjectNode getFpmConnectionsJsonOutput() {
 
@@ -72,6 +144,54 @@
         return node;
 
     }
+
+    private ObjectNode getFpmPeerRouteInfoJsonOutput() {
+
+        FpmInfoService fpmService = get(FpmInfoService.class);
+        ObjectNode node = mapper().createObjectNode();
+        ArrayNode connectionArray = mapper().createArrayNode();
+        Map<FpmPeer, FpmPeerInfo> fpmPeers = fpmService.peers();
+        fpmPeers.entrySet().stream()
+                .sorted(Comparator.<Map.Entry<FpmPeer, FpmPeerInfo>, IpAddress>comparing(e -> e.getKey().address())
+                        .thenComparing(e -> e.getKey().port()))
+                .map(Map.Entry::getValue)
+                .forEach(fpmPeerInfo -> {
+                    fpmPeerInfo.connections().forEach(connection -> {
+                        ObjectNode fpmNode = mapper().createObjectNode();
+                        fpmNode.put(PEER_ADDRESS, connection.peer().address().toString());
+                        fpmNode.put(PEER_PORT, connection.peer().port());
+                        fpmNode.put(ACCEPT_ROUTES, connection.isAcceptRoutes());
+                        connectionArray.add(fpmNode);
+                    });
+
+                });
+
+        node.put("fpm-peer-info", connectionArray);
+        return node;
+
+
+    }
+
+    private ObjectNode getFpmPeerAcceptFlagInfoJsonOutput(String address) {
+
+        FpmInfoService fpmService = get(FpmInfoService.class);
+        ObjectNode fpmNode = mapper().createObjectNode();
+        Map<FpmPeer, FpmPeerInfo> fpmPeers = fpmService.peers();
+        IpAddress peerAddress = IpAddress.valueOf(address);
+        fpmPeers.entrySet().stream()
+                .filter(peer -> peer.getKey().address().equals(peerAddress))
+                .map(Map.Entry::getValue)
+                .forEach(fpmPeerInfo -> {
+                    fpmPeerInfo.connections().forEach(connection -> {
+                        fpmNode.put(ACCEPT_ROUTES, connection.isAcceptRoutes());
+                    });
+                });
+
+
+        return fpmNode;
+
+
+    }
 }
 
 
diff --git a/apps/routing/fpm/web/src/main/resources/definitions/FpmConnectionsGet.json b/apps/routing/fpm/web/src/main/resources/definitions/FpmConnectionsGet.json
new file mode 100644
index 0000000..207453c
--- /dev/null
+++ b/apps/routing/fpm/web/src/main/resources/definitions/FpmConnectionsGet.json
@@ -0,0 +1,37 @@
+{
+  "type": "object",
+  "required": [
+    "peerAddress",
+    "peerPort",
+    "connectedTo",
+    "connectionTime",
+    "localRoutes",
+    "acceptRoutes"
+  ],
+  "properties": {
+    "peerAddress": {
+      "type": "string",
+      "example": "10.255.0.0"
+    },
+    "peerPort": {
+      "type": "int",
+      "example": "34455"
+    },
+    "connectedTo": {
+      "type": "string",
+      "example": "10.2.2.5"
+    },
+    "connectionTime": {
+      "type": "string",
+      "example": "3m ago"
+    },
+    "localRoutes": {
+      "type": "int",
+      "example": "2"
+    },
+    "acceptRoutes": {
+      "type": "boolean",
+      "example": "true"
+    }
+  }
+}
\ No newline at end of file
diff --git a/apps/routing/fpm/web/src/main/resources/definitions/FpmGetAcceptRoutes.json b/apps/routing/fpm/web/src/main/resources/definitions/FpmGetAcceptRoutes.json
new file mode 100644
index 0000000..ce23582
--- /dev/null
+++ b/apps/routing/fpm/web/src/main/resources/definitions/FpmGetAcceptRoutes.json
@@ -0,0 +1,22 @@
+{
+  "type": "object",
+  "required": [
+    "peerAddress",
+    "peerPort",
+    "acceptRoutes"
+  ],
+  "properties": {
+    "peerAddress": {
+      "type": "String",
+      "example": "10.0.0.1"
+    },
+    "peerPort": {
+      "type": "Integer",
+      "example": "56789"
+    },
+    "acceptRoutes": {
+      "type": "boolean",
+      "example": "true"
+    }
+  }
+}
diff --git a/apps/routing/fpm/web/src/main/resources/definitions/FpmPeerGetAcceptRoutes.json b/apps/routing/fpm/web/src/main/resources/definitions/FpmPeerGetAcceptRoutes.json
new file mode 100644
index 0000000..87e0c6e
--- /dev/null
+++ b/apps/routing/fpm/web/src/main/resources/definitions/FpmPeerGetAcceptRoutes.json
@@ -0,0 +1,12 @@
+{
+  "type": "object",
+  "required": [
+    "acceptRoutes"
+  ],
+  "properties": {
+    "acceptRoutes": {
+      "type": "boolean",
+      "example": "true"
+    }
+  }
+}
diff --git a/apps/routing/fpm/web/src/main/resources/definitions/FpmPeerSetAcceptRouteFlag.json b/apps/routing/fpm/web/src/main/resources/definitions/FpmPeerSetAcceptRouteFlag.json
new file mode 100644
index 0000000..652f552
--- /dev/null
+++ b/apps/routing/fpm/web/src/main/resources/definitions/FpmPeerSetAcceptRouteFlag.json
@@ -0,0 +1,40 @@
+{
+  "type": "object",
+  "title": "peers",
+  "required": [
+    "peers"
+  ],
+  "properties": {
+    "peers": {
+      "type": "array",
+      "xml": {
+        "name": "peers",
+        "wrapped": true
+      },
+      "items": {
+        "type": "object",
+        "title": "peer",
+        "required": [
+          "peerAddress",
+          "port",
+          "acceptRoutes"
+        ],
+        "properties": {
+          "peerAddress": {
+            "type": "string",
+            "example": "10.255.0.0"
+          },
+          "peerPort": {
+            "type": "int",
+            "example": "23456"
+          },
+          "acceptRoutes": {
+            "type": "boolean",
+            "example": "true"
+          }
+        }
+      }
+    }
+  }
+}
+
diff --git a/tools/package/etc/org.apache.karaf.command.acl.onos.cfg b/tools/package/etc/org.apache.karaf.command.acl.onos.cfg
index a35b13a..837f333 100644
--- a/tools/package/etc/org.apache.karaf.command.acl.onos.cfg
+++ b/tools/package/etc/org.apache.karaf.command.acl.onos.cfg
@@ -106,6 +106,7 @@
 flows = viewer
 fpm-connections = admin
 fpm-push-routes = admin
+fpm-set-accept-routes = admin
 gateway-add = admin
 gateway-delete = admin
 gateways = viewer