ONOS-7251 - Initial implementation of fabric.p4 L2 broadcast feature.

Thrift client cherry-picked from the commit dd5792ac9ee38a702c3128a34224852b5c284687

Change-Id: I989f2b2074485a892195889a7c976b518510da88
diff --git a/core/api/src/main/java/org/onosproject/net/pi/runtime/PiActionGroupHandle.java b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiActionGroupHandle.java
index 25a035b..4c87f1f 100644
--- a/core/api/src/main/java/org/onosproject/net/pi/runtime/PiActionGroupHandle.java
+++ b/core/api/src/main/java/org/onosproject/net/pi/runtime/PiActionGroupHandle.java
@@ -63,7 +63,7 @@
         return Objects.equal(deviceId(), that.deviceId()) &&
                 Objects.equal(piEntity().actionProfileId(),
                               that.piEntity().actionProfileId()) &&
-                Objects.equal(piEntity().id(), piEntity().id());
+                Objects.equal(piEntity().id(), that.piEntity().id());
     }
 
     @Override
diff --git a/drivers/bmv2/BUCK b/drivers/bmv2/BUCK
index 728f92b..9c27e09 100644
--- a/drivers/bmv2/BUCK
+++ b/drivers/bmv2/BUCK
@@ -3,20 +3,29 @@
 COMPILE_DEPS = [
     '//lib:CORE_DEPS',
     '//lib:minimal-json',
+    '//lib:KRYO',
+    '//lib:JACKSON',
+    '//lib:libthrift',
     '//protocols/p4runtime/api:onos-protocols-p4runtime-api',
     '//protocols/p4runtime/model:onos-protocols-p4runtime-model',
+    '//protocols/bmv2/thrift-api:onos-protocols-bmv2-thrift-api',
     '//drivers/p4runtime:onos-drivers-p4runtime',
     '//incubator/grpc-dependencies:grpc-core-repkg-' + GRPC_VER,
     '//lib:grpc-netty-' + GRPC_VER,
     '//pipelines/basic:onos-pipelines-basic',
+    '//core/store/serializers:onos-core-serializers',
 ]
 
 BUNDLES = [
     ':onos-drivers-bmv2',
+    '//lib:libthrift',
+    '//protocols/bmv2/thrift-api:onos-protocols-bmv2-thrift-api',
 ]
 
 osgi_jar(
     deps = COMPILE_DEPS,
+    resources_root = 'src/main/resources',
+    resources = glob(['src/main/resources/**']),
 )
 
 onos_app (
diff --git a/drivers/bmv2/features.xml b/drivers/bmv2/features.xml
index 448f07a..7d851a1 100644
--- a/drivers/bmv2/features.xml
+++ b/drivers/bmv2/features.xml
@@ -14,11 +14,14 @@
   ~ See the License for the specific language governing permissions and
   ~ limitations under the License.
   -->
-<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}">
+<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0"
+          name="${project.artifactId}-${project.version}">
     <feature name="${project.artifactId}" version="${project.version}"
              description="${project.description}">
         <feature>onos-api</feature>
-        <bundle>mvn:${project.groupId}/${project.artifactId}/${project.version}</bundle>
+        <bundle>
+            mvn:${project.groupId}/${project.artifactId}/${project.version}
+        </bundle>
 
     </feature>
 </features>
diff --git a/drivers/bmv2/pom.xml b/drivers/bmv2/pom.xml
index 7336c70..bde8fde 100644
--- a/drivers/bmv2/pom.xml
+++ b/drivers/bmv2/pom.xml
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!--
-  ~ Copyright 2017-present Open Networking Foundation
+  ~ Copyright 2018-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.
@@ -15,8 +15,8 @@
   ~ limitations under the License.
   -->
 
-<project xmlns="http://maven.apache.org/POM/4.0.0"
-         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xmlns="http://maven.apache.org/POM/4.0.0"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     <parent>
         <artifactId>onos-drivers-general</artifactId>
@@ -37,6 +37,12 @@
         </dependency>
 
         <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-core-serializers</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
+        <dependency>
             <groupId>io.grpc</groupId>
             <artifactId>grpc-netty</artifactId>
             <version>${grpccore.version}</version>
@@ -66,6 +72,19 @@
             <version>${project.version}</version>
         </dependency>
 
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-bmv2-protocol-thrift-api</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.thrift</groupId>
+            <artifactId>libthrift</artifactId>
+            <version>0.9.3</version>
+        </dependency>
+        <!-- protocols/p4runtime/api missing -->
+
     </dependencies>
 
     <properties>
diff --git a/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/Bmv2DeviceHandshaker.java b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/Bmv2DeviceHandshaker.java
new file mode 100644
index 0000000..efb7b77
--- /dev/null
+++ b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/Bmv2DeviceHandshaker.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright 2018-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.drivers.bmv2;
+
+import org.onosproject.drivers.bmv2.api.Bmv2PreController;
+import org.onosproject.drivers.p4runtime.P4RuntimeHandshaker;
+import org.onosproject.net.DeviceId;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.concurrent.CompletableFuture;
+
+public class Bmv2DeviceHandshaker extends P4RuntimeHandshaker {
+
+    public static final String THRIFT_SERVER_ADDRESS_KEY = "bmv2-thrift_ip";
+    public static final String THRIFT_SERVER_PORT_KEY = "bmv2-thrift_port";
+    protected final Logger log = LoggerFactory.getLogger(getClass());
+
+    @Override
+    public CompletableFuture<Boolean> connect() {
+        //connect to both GRPC and Thrift servers in parallel
+        CompletableFuture<Boolean> futureP4Runtime = super.connect();
+        CompletableFuture<Boolean> futureBmv2Pre = connectToBmv2Pre();
+        //combine futures and asses the overall result by using P4Runtime connection status
+        return futureP4Runtime.thenCombine(futureBmv2Pre,
+                                           (p4RuntimeConnected, bmv2PreConnected) -> p4RuntimeConnected);
+    }
+
+    @Override
+    public CompletableFuture<Boolean> disconnect() {
+        //disconnect from both GRPC and Thrift servers in parallel
+        CompletableFuture<Boolean> futureP4Runtime = super.disconnect();
+        CompletableFuture<Boolean> futureBmv2Pre = disconnectFromBmv2Pre();
+        //combine futures and asses the overall result by using P4Runtime disconnection status
+        return futureP4Runtime.thenCombine(futureBmv2Pre,
+                                           (p4RuntimeDisconnected, bmv2PreDisconnected) -> p4RuntimeDisconnected);
+    }
+
+    private CompletableFuture<Boolean> connectToBmv2Pre() {
+        return CompletableFuture.supplyAsync(this::createPreClient);
+    }
+
+    private CompletableFuture<Boolean> disconnectFromBmv2Pre() {
+        return CompletableFuture.supplyAsync(() -> {
+            removePreClient();
+            return true;
+        });
+    }
+
+    /**
+     * Creates a BMv2 PRE client for this device.
+     *
+     * @return true if successful; false otherwise
+     */
+    private boolean createPreClient() {
+        DeviceId deviceId = handler().data().deviceId();
+
+        String serverAddress = data().value(THRIFT_SERVER_ADDRESS_KEY);
+        String serverPortString = data().value(THRIFT_SERVER_PORT_KEY);
+
+        if (serverAddress == null || serverPortString == null) {
+            log.warn("Unable to create PRE client for {}, missing driver data key (required is {}, and {})",
+                     deviceId, THRIFT_SERVER_ADDRESS_KEY, THRIFT_SERVER_PORT_KEY);
+            return false;
+        }
+        Bmv2PreController bmv2PreController = handler().get(Bmv2PreController.class);
+        try {
+            return bmv2PreController.createPreClient(deviceId,
+                                                     serverAddress,
+                                                     Integer.parseUnsignedInt(serverPortString));
+        } catch (RuntimeException e) {
+            log.warn("Unable to create BMv2 PRE client for {} due to {}", deviceId, e.toString());
+            return false;
+        }
+    }
+
+    private void removePreClient() {
+        DeviceId deviceId = handler().data().deviceId();
+        handler().get(Bmv2PreController.class).removePreClient(deviceId);
+    }
+}
diff --git a/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/Bmv2GroupProgrammable.java b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/Bmv2GroupProgrammable.java
new file mode 100644
index 0000000..1ab518f
--- /dev/null
+++ b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/Bmv2GroupProgrammable.java
@@ -0,0 +1,257 @@
+/*
+ * Copyright 2018-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.drivers.bmv2;
+
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import com.google.common.collect.ImmutableList;
+import org.onosproject.core.GroupId;
+import org.onosproject.drivers.bmv2.api.Bmv2DeviceAgent;
+import org.onosproject.drivers.bmv2.api.Bmv2PreController;
+import org.onosproject.drivers.bmv2.api.runtime.Bmv2PreGroup;
+import org.onosproject.drivers.bmv2.api.runtime.Bmv2PreGroupHandle;
+import org.onosproject.drivers.bmv2.api.runtime.Bmv2RuntimeException;
+import org.onosproject.drivers.bmv2.impl.Bmv2PreGroupTranslatorImpl;
+import org.onosproject.drivers.bmv2.mirror.Bmv2PreGroupMirror;
+import org.onosproject.drivers.p4runtime.P4RuntimeGroupProgrammable;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.group.Group;
+import org.onosproject.net.group.GroupDescription;
+import org.onosproject.net.group.GroupOperation;
+import org.onosproject.net.group.GroupOperations;
+import org.slf4j.Logger;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+import java.util.stream.Collectors;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Implementation of the group programmable behaviour for BMv2.
+ */
+public class Bmv2GroupProgrammable extends P4RuntimeGroupProgrammable {
+
+    private static final Logger log = getLogger(Bmv2GroupProgrammable.class);
+
+    private static final int PRE_GROUP_LOCK_EXPIRE_TIME_IN_MIN = 10;
+
+    // Needed to synchronize operations over the same group.
+    private static final LoadingCache<Bmv2PreGroupHandle, Lock> PRE_GROUP_LOCKS = CacheBuilder.newBuilder()
+            .expireAfterAccess(PRE_GROUP_LOCK_EXPIRE_TIME_IN_MIN, TimeUnit.MINUTES)
+            .build(new CacheLoader<Bmv2PreGroupHandle, Lock>() {
+                @Override
+                public Lock load(Bmv2PreGroupHandle bmv2PreGroupHandle) {
+                    return new ReentrantLock();
+                }
+            });
+
+    private Bmv2PreGroupMirror preGroupMirror;
+    private Bmv2PreController bmv2PreController;
+
+    @Override
+    protected boolean setupBehaviour() {
+        if (!super.setupBehaviour()) {
+            return false;
+        }
+
+        preGroupMirror = handler().get(Bmv2PreGroupMirror.class);
+        bmv2PreController = handler().get(Bmv2PreController.class);
+
+        return getBmv2DeviceAgent() != null
+                && preGroupMirror != null
+                && bmv2PreController != null;
+    }
+
+    @Override
+    public void performGroupOperation(DeviceId deviceId,
+                                      GroupOperations groupOps) {
+        if (!setupBehaviour()) {
+            return;
+        }
+        groupOps.operations().forEach(op -> processGroupOp(deviceId, op));
+    }
+
+
+    /**
+     * Fetches all groups of P4Runtime and BMv2 PRE in a device. Combines and returns them respectively.
+     *
+     * @return all the groups which are managed via both P4Runtime and BMv2 PRE
+     */
+    @Override
+    public Collection<Group> getGroups() {
+        //get groups managed via P4Runtime
+        Collection<Group> groups = getP4Groups();
+        //get groups managed via BMv2 Thrift
+        groups.addAll(getPreGroups());
+        return ImmutableList.copyOf(groups);
+    }
+
+    private Collection<Group> getP4Groups() {
+        return super.getGroups();
+    }
+
+    /**
+     * Returns BMv2 agent associated with a BMv2 device.
+     *
+     * @return BMv2 agent
+     */
+    private Bmv2DeviceAgent getBmv2DeviceAgent() {
+        return bmv2PreController.getPreClient(deviceId);
+    }
+
+    /**
+     * Retrieves groups of BMv2 PRE.
+     *
+     * @return collection of PRE groups
+     */
+    private Collection<Group> getPreGroups() {
+        if (!setupBehaviour()) {
+            return Collections.emptyList();
+        }
+        Bmv2DeviceAgent bmv2DeviceAgent = getBmv2DeviceAgent();
+
+        try {
+            return bmv2DeviceAgent.getPreGroups().stream()
+                    .map(preGroup -> groupStore.getGroup(deviceId, GroupId.valueOf(preGroup.groupId())))
+                    .collect(Collectors.toList());
+        } catch (Bmv2RuntimeException e) {
+            log.error("Exception while getting Bmv2 PRE groups of {}", deviceId, e);
+            return Collections.emptyList();
+        }
+    }
+
+    /**
+     * Checks whether specified group is a PRE group or not.
+     *
+     * @param group group
+     * @return Returns true iff this group is a PRE group; false otherwise.
+     */
+    private boolean isPreGroup(Group group) {
+        return group.type().equals(GroupDescription.Type.ALL);
+    }
+
+    /**
+     * Makes a decision between two methodologies over group type.
+     * A group of ALL type is evaluated by GroupProgrammable of BMv2;
+     * it is passed on to GroupProgrammable of P4Runtime otherwise.
+     *
+     * @param deviceId ID of the device on which the group is being accommodated.
+     * @param groupOp  group operation
+     */
+    private void processGroupOp(DeviceId deviceId, GroupOperation groupOp) {
+        final Group group = groupStore.getGroup(deviceId, groupOp.groupId());
+
+        if (isPreGroup(group)) {
+            processPreGroupOp(deviceId, groupOp);
+        } else {
+            //means the group is managed via P4Runtime.
+            super.performGroupOperation(deviceId,
+                                        new GroupOperations(Arrays.asList(new GroupOperation[]{groupOp})));
+        }
+    }
+
+    private void processPreGroupOp(DeviceId deviceId, GroupOperation groupOp) {
+        if (!setupBehaviour()) {
+            return;
+        }
+
+        final Group group = groupStore.getGroup(deviceId, groupOp.groupId());
+
+        Bmv2PreGroup preGroup = Bmv2PreGroupTranslatorImpl.translate(group);
+
+        final Bmv2PreGroupHandle handle = Bmv2PreGroupHandle.of(deviceId, preGroup);
+
+        final Bmv2PreGroup groupOnDevice = preGroupMirror.get(handle);
+
+        PRE_GROUP_LOCKS.getUnchecked(handle).lock();
+        try {
+            switch (groupOp.opType()) {
+                case ADD:
+                    onAdd(preGroup, handle);
+                    break;
+                case MODIFY:
+                    onModify(preGroup, groupOnDevice, handle);
+                    break;
+                case DELETE:
+                    onDelete(groupOnDevice, handle);
+                    break;
+                default:
+                    log.warn("PRE Group operation {} not supported", groupOp.opType());
+            }
+        } finally {
+            PRE_GROUP_LOCKS.getUnchecked(handle).unlock();
+        }
+    }
+
+    private void onAdd(Bmv2PreGroup preGroup, Bmv2PreGroupHandle handle) {
+        try {
+            writeGroup(preGroup, handle);
+        } catch (Bmv2RuntimeException e) {
+            log.error("Unable to create the PRE group with groupId={}. deviceId={}", preGroup.groupId(), deviceId, e);
+        }
+    }
+
+    private void onDelete(Bmv2PreGroup preGroupOnDevice, Bmv2PreGroupHandle handle) {
+        if (preGroupOnDevice == null) {
+            log.warn("Unable to delete the group. Nonexistent in the group mirror! deviceId={}", deviceId);
+            return;
+        }
+        try {
+            deleteGroup(preGroupOnDevice, handle);
+        } catch (Bmv2RuntimeException e) {
+            log.error("Unable to delete the group. deviceId={}", deviceId, e);
+        }
+    }
+
+    private void onModify(Bmv2PreGroup preGroup, Bmv2PreGroup preGroupOnDevice, Bmv2PreGroupHandle handle) {
+        if (preGroupOnDevice == null) {
+            log.warn("Unable to modify the group. Nonexistent in the group mirror! deviceId={}", deviceId);
+            return;
+        }
+        if (preGroup.equals(preGroupOnDevice)) {
+            return;
+        }
+        try {
+            deleteGroup(preGroupOnDevice, handle);
+            writeGroup(preGroup, handle);
+        } catch (Bmv2RuntimeException e) {
+            log.error("Unable to modify the group. deviceId={}, groupId={}", deviceId, preGroup.groupId(), e);
+        }
+    }
+
+    private void writeGroup(Bmv2PreGroup preGroup, Bmv2PreGroupHandle handle) throws Bmv2RuntimeException {
+        Bmv2DeviceAgent bmv2DeviceAgent = getBmv2DeviceAgent();
+        Bmv2PreGroup bmv2PreGroupCreated = bmv2DeviceAgent.writePreGroup(preGroup);
+        //put the created group into the mirror store
+        preGroupMirror.put(handle, bmv2PreGroupCreated);
+    }
+
+    private void deleteGroup(Bmv2PreGroup preGroupOnDevice, Bmv2PreGroupHandle handle) throws Bmv2RuntimeException {
+        Bmv2DeviceAgent bmv2DeviceAgent = getBmv2DeviceAgent();
+        bmv2DeviceAgent.deletePreGroup(preGroupOnDevice);
+        //remove the group from the mirror
+        preGroupMirror.remove(handle);
+    }
+
+}
\ No newline at end of file
diff --git a/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/api/Bmv2DeviceAgent.java b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/api/Bmv2DeviceAgent.java
new file mode 100644
index 0000000..ac83038
--- /dev/null
+++ b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/api/Bmv2DeviceAgent.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2018-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.drivers.bmv2.api;
+
+import org.onosproject.drivers.bmv2.api.runtime.Bmv2PreGroup;
+import org.onosproject.drivers.bmv2.api.runtime.Bmv2RuntimeException;
+import org.onosproject.net.DeviceId;
+
+import java.util.List;
+
+/**
+ * An agent to control a BMv2 device.
+ */
+public interface Bmv2DeviceAgent {
+
+    /**
+     * Returns the device ID of this agent.
+     *
+     * @return a device id
+     */
+    DeviceId deviceId();
+
+    /**
+     * Creates a multicast group and related entries atomically on a BMv2 device.
+     * If successful returns modified version of the group object that is filled with BMv2 switch-specific identifiers
+     * of the created group and nodes; throws Bmv2RuntimeException otherwise.
+     *
+     * @param preGroup Bmv2PreGroup
+     * @return modified version of preGroup param.
+     * @throws Bmv2RuntimeException if any error occurs
+     */
+    Bmv2PreGroup writePreGroup(Bmv2PreGroup preGroup) throws Bmv2RuntimeException;
+
+    /**
+     * Deletes a multicast group and all associated nodes from a BMV2 device.
+     *
+     * @param preGroup Bmv2PreGroup
+     * @throws Bmv2RuntimeException if any error occurs
+     */
+    void deletePreGroup(Bmv2PreGroup preGroup) throws Bmv2RuntimeException;
+
+    /**
+     * Returns all BMv2 PRE groups.
+     *
+     * @return list of PRE groups.
+     * @throws Bmv2RuntimeException if any error occurs
+     */
+    List<Bmv2PreGroup> getPreGroups() throws Bmv2RuntimeException;
+}
diff --git a/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/api/Bmv2PreController.java b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/api/Bmv2PreController.java
new file mode 100644
index 0000000..b9d3910
--- /dev/null
+++ b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/api/Bmv2PreController.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2018-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.drivers.bmv2.api;
+
+import org.onosproject.net.DeviceId;
+
+/**
+ * PRE Controller for BMv2 devices.
+ */
+public interface Bmv2PreController {
+
+    /**
+     * Creates a client to communicate with the PRE layer of a BMv2 device
+     * and associates it with the given device identifier.
+     * Returns true if the client was created and the channel to the device is open.
+     * If so, a {@link Bmv2DeviceAgent} can be later obtained by invoking {@link #getPreClient(DeviceId)}.
+     * Otherwise, returns false.
+     *
+     * @param deviceId         device identifier
+     * @param thriftServerIp   Thrift server address
+     * @param thriftServerPort Thrift server port
+     * @return true if the client was created and the channel to the device is open; false otherwise
+     * @throws IllegalStateException if a client already exists for the given device identifier
+     */
+    boolean createPreClient(DeviceId deviceId, String thriftServerIp, Integer thriftServerPort);
+
+    /**
+     * Returns the PRE client associated with the given device identifier, if any.
+     *
+     * @param deviceId device identifier
+     * @return client instance if a client has already been created; null otherwise
+     */
+    Bmv2DeviceAgent getPreClient(DeviceId deviceId);
+
+    /**
+     * Removes the PRE client associated with the given device identifier.
+     *
+     * @param deviceId device identifier
+     */
+    void removePreClient(DeviceId deviceId);
+
+}
diff --git a/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/api/package-info.java b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/api/package-info.java
new file mode 100644
index 0000000..d96ec97
--- /dev/null
+++ b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/api/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2018-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 for BMv2 API.
+ */
+package org.onosproject.drivers.bmv2.api;
\ No newline at end of file
diff --git a/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/api/runtime/Bmv2Entity.java b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/api/runtime/Bmv2Entity.java
new file mode 100644
index 0000000..8412763
--- /dev/null
+++ b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/api/runtime/Bmv2Entity.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2018-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.drivers.bmv2.api.runtime;
+
+
+/**
+ * Abstraction of an entity of BMv2 that can be read or write
+ * at runtime.
+ */
+public interface Bmv2Entity {
+
+    /**
+     * Returns the type of this entity.
+     *
+     * @return entity type
+     */
+    Bmv2EntityType entityType();
+}
diff --git a/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/api/runtime/Bmv2EntityType.java b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/api/runtime/Bmv2EntityType.java
new file mode 100644
index 0000000..e219024
--- /dev/null
+++ b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/api/runtime/Bmv2EntityType.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2018-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.drivers.bmv2.api.runtime;
+
+/**
+ * Type of runtime entity of BMv2.
+ */
+public enum Bmv2EntityType {
+
+    /**
+     * Indicates a multicast group.
+     */
+    PRE_GROUP
+}
diff --git a/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/api/runtime/Bmv2Handle.java b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/api/runtime/Bmv2Handle.java
new file mode 100644
index 0000000..373b41b
--- /dev/null
+++ b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/api/runtime/Bmv2Handle.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2018-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.drivers.bmv2.api.runtime;
+
+import org.onosproject.net.DeviceId;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Global identifier of an entity applied to a BMv2 device.
+ * @param <E> an object extending Bmv2Entity
+ */
+public abstract class Bmv2Handle<E extends Bmv2Entity> {
+
+    private final DeviceId deviceId;
+    private final E bmv2Entity;
+
+    protected Bmv2Handle(DeviceId deviceId, E bmv2Entity) {
+        this.deviceId = checkNotNull(deviceId);
+        this.bmv2Entity = checkNotNull(bmv2Entity);
+    }
+
+    /**
+     * Returns the device ID of this handle.
+     *
+     * @return device ID
+     */
+    public final DeviceId deviceId() {
+        return deviceId;
+    }
+
+    /**
+     * Returns the type of entity identified by this handle.
+     *
+     * @return BMv2 entity type
+     */
+    public final Bmv2EntityType entityType() {
+        return bmv2Entity.entityType();
+    }
+
+    /**
+     * The entity to which this handle is associated.
+     *
+     * @return Bmv2 entity
+     */
+    public final E bmv2Entity() {
+        return bmv2Entity;
+    }
+
+    @Override
+    public abstract int hashCode();
+
+    @Override
+    public abstract boolean equals(Object obj);
+
+    @Override
+    public abstract String toString();
+}
diff --git a/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/api/runtime/Bmv2PreGroup.java b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/api/runtime/Bmv2PreGroup.java
new file mode 100644
index 0000000..c0c4b5d
--- /dev/null
+++ b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/api/runtime/Bmv2PreGroup.java
@@ -0,0 +1,143 @@
+/*
+ * Copyright 2018-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.drivers.bmv2.api.runtime;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.base.Objects;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Sets;
+
+import java.util.Set;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Representation of a multicast group in BMv2 PRE.
+ */
+public class Bmv2PreGroup implements Bmv2Entity {
+
+    private final Integer groupId;
+    private final Bmv2PreNodes nodes;
+    //internal device-level identifier used by BMv2
+    private Integer nativeGroupHandle;
+
+    public Bmv2PreGroup(Integer groupId, Bmv2PreNodes nodes) {
+        this.groupId = checkNotNull(groupId, "groupId argument can not be null");
+        this.nodes = checkNotNull(nodes, "nodes argument can not be null");
+    }
+
+    /**
+     * Returns a new builder of BMv2 PRE groups.
+     *
+     * @return a BMv2 PRE group builder
+     */
+    public static Bmv2PreGroupBuilder builder() {
+        return new Bmv2PreGroupBuilder();
+    }
+
+    public Integer groupId() {
+        return groupId;
+    }
+
+    public Integer nativeGroupHandle() {
+        return nativeGroupHandle;
+    }
+
+    public Bmv2PreNodes nodes() {
+        return nodes;
+    }
+
+    public void setNativeGroupHandle(Integer nativeGroupHandle) {
+        this.nativeGroupHandle = nativeGroupHandle;
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hashCode(groupId, nodes, nativeGroupHandle);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null || getClass() != obj.getClass()) {
+            return false;
+        }
+        final Bmv2PreGroup other = (Bmv2PreGroup) obj;
+        return Objects.equal(this.groupId, other.groupId)
+                && Objects.equal(this.nodes, other.nodes);
+    }
+
+    @Override
+    public String toString() {
+        return MoreObjects.toStringHelper(this)
+                .add("groupId", groupId)
+                .add("nativeGroupHandle", nativeGroupHandle)
+                .add("nodes", nodes)
+                .toString();
+    }
+
+    @Override
+    public Bmv2EntityType entityType() {
+        return Bmv2EntityType.PRE_GROUP;
+    }
+
+    /**
+     * Builder of BMv2 PRE groups.
+     */
+    public static final class Bmv2PreGroupBuilder {
+        private Integer groupId;
+        private Set<Bmv2PreNode> nodes = Sets.newHashSet();
+
+        private Bmv2PreGroupBuilder() {
+            //hidden constructor
+        }
+
+        /**
+         * Sets the identifier of this group.
+         *
+         * @param groupId identifier of this BMv2 PRE group.
+         * @return this
+         */
+        public Bmv2PreGroupBuilder withGroupId(Integer groupId) {
+            this.groupId = groupId;
+            return this;
+        }
+
+        /**
+         * Adds a node to this group.
+         *
+         * @param node a BMv2 PRE node.
+         * @return this
+         */
+        public Bmv2PreGroupBuilder addNode(Bmv2PreNode node) {
+            nodes.add(node);
+            return this;
+        }
+
+        /**
+         * Creates a new BMv2 PRE group.
+         *
+         * @return a new BMv2 PRE group
+         */
+        public Bmv2PreGroup build() {
+            return new Bmv2PreGroup(groupId, new Bmv2PreNodes(ImmutableSet.copyOf(nodes)));
+        }
+    }
+}
diff --git a/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/api/runtime/Bmv2PreGroupHandle.java b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/api/runtime/Bmv2PreGroupHandle.java
new file mode 100644
index 0000000..7e886bc
--- /dev/null
+++ b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/api/runtime/Bmv2PreGroupHandle.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2018-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.drivers.bmv2.api.runtime;
+
+
+import com.google.common.base.MoreObjects;
+import com.google.common.base.Objects;
+import org.onosproject.net.DeviceId;
+
+/**
+ * Global identifier of a BMv2 PRE group applied to a device, uniquely defined
+ * by a device ID and group ID.
+ */
+public final class Bmv2PreGroupHandle extends Bmv2Handle<Bmv2PreGroup> {
+
+    private Bmv2PreGroupHandle(DeviceId deviceId, Bmv2PreGroup group) {
+        super(deviceId, group);
+    }
+
+    /**
+     * Creates a new handle for the given device ID and BMv2 PRE group.
+     *
+     * @param deviceId device ID
+     * @param group    BMv2 PRE group
+     * @return BMv2 PRE group handle
+     */
+    public static Bmv2PreGroupHandle of(DeviceId deviceId,
+                                        Bmv2PreGroup group) {
+        return new Bmv2PreGroupHandle(deviceId, group);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hashCode(deviceId(),
+                                bmv2Entity().groupId());
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+        Bmv2PreGroupHandle that = (Bmv2PreGroupHandle) o;
+        return Objects.equal(deviceId(), that.deviceId()) &&
+                Objects.equal(bmv2Entity().groupId(), that.bmv2Entity().groupId());
+    }
+
+    @Override
+    public String toString() {
+        return MoreObjects.toStringHelper(this)
+                .add("deviceId", deviceId())
+                .add("groupId", bmv2Entity().groupId())
+                .toString();
+    }
+}
diff --git a/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/api/runtime/Bmv2PreJsonGroups.java b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/api/runtime/Bmv2PreJsonGroups.java
new file mode 100644
index 0000000..83a6fa2
--- /dev/null
+++ b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/api/runtime/Bmv2PreJsonGroups.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright 2018-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.drivers.bmv2.api.runtime;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+/**
+ * Represents mc group list retrieved from BMv2 PRE.
+ */
+public final class Bmv2PreJsonGroups {
+    public final L1Handle[] l1handles;
+    public final L2Handle[] l2handles;
+    public final Lag[] lags;
+    public final Mgrp[] mgrps;
+
+    @JsonCreator
+    public Bmv2PreJsonGroups(@JsonProperty("l1_handles") L1Handle[] l1handles,
+                             @JsonProperty("l2_handles") L2Handle[] l2handles,
+                             @JsonProperty("lags") Lag[] lags,
+                             @JsonProperty("mgrps") Mgrp[] mgrps) {
+        this.l1handles = l1handles;
+        this.l2handles = l2handles;
+        this.lags = lags;
+        this.mgrps = mgrps;
+    }
+
+    public static final class L1Handle {
+        public final int handle;
+        public final int l2handle;
+        public final int rid;
+
+        @JsonCreator
+        public L1Handle(@JsonProperty("handle") int handle,
+                        @JsonProperty("l2_handle") int l2handle,
+                        @JsonProperty("rid") int rid) {
+            this.handle = handle;
+            this.l2handle = l2handle;
+            this.rid = rid;
+        }
+    }
+
+    public static final class L2Handle {
+        public final int handle;
+        public final int[] lags;
+        public final int[] ports;
+
+        @JsonCreator
+        public L2Handle(@JsonProperty("handle") int handle,
+                        @JsonProperty("lags") int[] lags,
+                        @JsonProperty("ports") int[] ports) {
+            this.handle = handle;
+            this.lags = lags;
+            this.ports = ports;
+        }
+    }
+
+    public static final class Lag {
+        //lag is not used for now
+        @JsonCreator
+        public Lag() {
+        }
+    }
+
+    public static final class Mgrp {
+        public final int id;
+        public final int[] l1handles;
+
+        @JsonCreator
+        public Mgrp(@JsonProperty("id") int id, @JsonProperty("l1_handles") int[] l1handles) {
+            this.id = id;
+            this.l1handles = l1handles;
+        }
+    }
+}
+
diff --git a/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/api/runtime/Bmv2PreNode.java b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/api/runtime/Bmv2PreNode.java
new file mode 100644
index 0000000..3d50e50
--- /dev/null
+++ b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/api/runtime/Bmv2PreNode.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright 2018-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.drivers.bmv2.api.runtime;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.base.Objects;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * The class that represents a multicast node in BMv2 PRE.
+ */
+public class Bmv2PreNode {
+    //replication id
+    private final Integer rid;
+    private final String portMap;
+    private Integer l1Handle;
+
+    public Bmv2PreNode(Integer rid, String portMap) {
+        this.rid = checkNotNull(rid, "rid argument can not be null");
+        this.portMap = checkNotNull(portMap, "portMap argument can not be null");
+    }
+
+    public static Bmv2PreNodeBuilder builder() {
+        return new Bmv2PreNodeBuilder();
+    }
+
+    public Integer rid() {
+        return rid;
+    }
+
+    public String portMap() {
+        return portMap;
+    }
+
+    public Integer l1Handle() {
+        return l1Handle;
+    }
+
+    public void setL1Handle(Integer l1Handle) {
+        this.l1Handle = l1Handle;
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hashCode(rid, portMap, l1Handle);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null || getClass() != obj.getClass()) {
+            return false;
+        }
+        final Bmv2PreNode other = (Bmv2PreNode) obj;
+        return Objects.equal(this.rid, other.rid)
+                && Objects.equal(this.portMap, other.portMap);
+    }
+
+    @Override
+    public String toString() {
+        return MoreObjects.toStringHelper(this)
+                .add("rid", rid)
+                .add("portMap", portMap)
+                .add("l1Handle", l1Handle)
+                .toString();
+    }
+
+    public static final class Bmv2PreNodeBuilder {
+        //replication id
+        private Integer rid;
+        private String portMap;
+        private Integer l1Handle;
+
+        private Bmv2PreNodeBuilder() {
+        }
+
+        public Bmv2PreNodeBuilder withRid(Integer rid) {
+            this.rid = rid;
+            return this;
+        }
+
+        public Bmv2PreNodeBuilder withPortMap(String portMap) {
+            this.portMap = portMap;
+            return this;
+        }
+
+        public Bmv2PreNodeBuilder withL1Handle(Integer l1Handle) {
+            this.l1Handle = l1Handle;
+            return this;
+        }
+
+        public Bmv2PreNode build() {
+            Bmv2PreNode bmv2PreNode = new Bmv2PreNode(rid, portMap);
+            bmv2PreNode.setL1Handle(l1Handle);
+            return bmv2PreNode;
+        }
+    }
+}
diff --git a/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/api/runtime/Bmv2PreNodes.java b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/api/runtime/Bmv2PreNodes.java
new file mode 100644
index 0000000..31edef1
--- /dev/null
+++ b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/api/runtime/Bmv2PreNodes.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2018-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.drivers.bmv2.api.runtime;
+
+
+import com.google.common.base.Objects;
+import com.google.common.collect.ImmutableSet;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Immutable collection of BMv2 PRE group nodes.
+ */
+public final class Bmv2PreNodes {
+    private final ImmutableSet<Bmv2PreNode> nodes;
+
+    /**
+     * Creates a immutable list of group nodes.
+     *
+     * @param nodes list of group nodes
+     */
+    public Bmv2PreNodes(ImmutableSet<Bmv2PreNode> nodes) {
+        this.nodes = checkNotNull(nodes);
+    }
+
+    public ImmutableSet<Bmv2PreNode> nodes() {
+        return nodes;
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hashCode(nodes);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (obj instanceof Bmv2PreNodes) {
+            return (this.nodes.containsAll(((Bmv2PreNodes) obj).nodes) &&
+                    ((Bmv2PreNodes) obj).nodes.containsAll(this.nodes));
+        }
+        return false;
+    }
+
+    @Override
+    public String toString() {
+        return toStringHelper(this)
+                .add("nodes", nodes)
+                .toString();
+    }
+}
diff --git a/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/api/runtime/Bmv2RuntimeException.java b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/api/runtime/Bmv2RuntimeException.java
new file mode 100644
index 0000000..fd61bcf
--- /dev/null
+++ b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/api/runtime/Bmv2RuntimeException.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2018-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.drivers.bmv2.api.runtime;
+
+/**
+ * General exception of the BMv2 runtime APIs.
+ */
+public final class Bmv2RuntimeException extends Exception {
+
+    private final Code code;
+    private String codeString;
+
+    public Bmv2RuntimeException(String message) {
+        super(message);
+        this.code = Code.OTHER;
+        this.codeString = message;
+    }
+
+    public Bmv2RuntimeException(Throwable cause) {
+        super(cause);
+        this.code = Code.OTHER;
+        this.codeString = cause.toString();
+    }
+
+    public Bmv2RuntimeException(Code code) {
+        super(code.name());
+        this.code = code;
+    }
+
+    public Code getCode() {
+        return this.code;
+    }
+
+    public String explain() {
+        return (codeString == null) ? code.name() : code.name() + " " + codeString;
+    }
+
+    @Override
+    public String toString() {
+        return getClass().getSimpleName() + " " + explain();
+    }
+
+    /**
+     * Code of BMv2 error.
+     */
+    public enum Code {
+        /**
+         * Indicates table is full.
+         */
+        TABLE_FULL,
+        INVALID_MGID,
+        /**
+         * Indicates multicast group handle is invalid.
+         */
+        INVALID_MGRP_HANDLE,
+        /**
+         * Indicates l1 handle is not associated with a node.
+         */
+        INVALID_L1_HANDLE,
+        /**
+         * Indicates a general error.
+         */
+        MC_GENERAL_ERROR,
+        /**
+         * Indicates an unknown error.
+         */
+        MC_UNKNOWN_ERROR,
+        OTHER
+    }
+}
diff --git a/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/api/runtime/package-info.java b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/api/runtime/package-info.java
new file mode 100644
index 0000000..ef19b3a
--- /dev/null
+++ b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/api/runtime/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2018-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.
+ *
+ */
+/**
+ * Classes abstracting entities of BMv2.
+ */
+package org.onosproject.drivers.bmv2.api.runtime;
\ No newline at end of file
diff --git a/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/ctl/Bmv2DeviceThriftClient.java b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/ctl/Bmv2DeviceThriftClient.java
new file mode 100644
index 0000000..cdcfb0c
--- /dev/null
+++ b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/ctl/Bmv2DeviceThriftClient.java
@@ -0,0 +1,406 @@
+/*
+ * Copyright 2018-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.drivers.bmv2.ctl;
+
+import org.apache.thrift.TException;
+import org.onosproject.bmv2.thriftapi.SimplePreLAG;
+import org.onosproject.drivers.bmv2.api.Bmv2DeviceAgent;
+import org.onosproject.drivers.bmv2.api.runtime.Bmv2PreGroup;
+import org.onosproject.drivers.bmv2.api.runtime.Bmv2PreNode;
+import org.onosproject.drivers.bmv2.api.runtime.Bmv2RuntimeException;
+import org.onosproject.drivers.bmv2.impl.Bmv2PreGroupTranslatorImpl;
+import org.onosproject.net.DeviceId;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.List;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.onosproject.drivers.bmv2.ctl.Bmv2TExceptionParser.parseTException;
+
+/**
+ * Implementation of a Thrift client to control a BMv2 device.
+ */
+final class Bmv2DeviceThriftClient implements Bmv2DeviceAgent {
+
+    // FIXME: make context_id arbitrary for each call
+    // See: https://github.com/p4lang/behavioral-model/blob/master/modules/bm_sim/include/bm_sim/context.h
+    private static final int CONTEXT_ID = 0;
+    private static final String DEFAULT_LAG_MAP = "";
+    private final Logger log = LoggerFactory.getLogger(this.getClass());
+    private final SimplePreLAG.Iface simplePreLagClient;
+    private final DeviceId deviceId;
+
+    // ban constructor
+    protected Bmv2DeviceThriftClient(DeviceId deviceId, SimplePreLAG.Iface simplePreLagClient) {
+        this.deviceId = deviceId;
+        this.simplePreLagClient = simplePreLagClient;
+    }
+
+    @Override
+    public DeviceId deviceId() {
+        return deviceId;
+    }
+
+    @Override
+    public Bmv2PreGroup writePreGroup(Bmv2PreGroup preGroup) throws Bmv2RuntimeException {
+        log.debug("Creating a multicast group... > deviceId={}, {}", deviceId, preGroup);
+
+        GroupRollbackMachine groupRollbackMachine = new GroupRollbackMachine(preGroup);
+        try {
+            //first create mc group
+            preGroup.setNativeGroupHandle(createMcGroup(preGroup.groupId()));
+            groupRollbackMachine.setState(GroupOperationState.GROUP_CREATED);
+            //create mc nodes
+            createMcNodesOfGroup(preGroup);
+            groupRollbackMachine.setState(GroupOperationState.NODES_CREATED);
+            //associate nodes with group
+            associateMcNodesOfGroup(preGroup);
+            groupRollbackMachine.setState(GroupOperationState.NODES_ASSOCIATED);
+
+            log.debug("Multicast group created successfully. deviceId={}, {}", deviceId, preGroup);
+
+            return preGroup;
+        } finally {
+            groupRollbackMachine.rollbackIfNecessary();
+        }
+    }
+
+    @Override
+    public void deletePreGroup(Bmv2PreGroup preGroup) throws Bmv2RuntimeException {
+        log.debug("Deleting a multicast group... > deviceId={}, {}", deviceId, preGroup);
+        //disassociate mc nodes from group
+        disassociateMcNodesOfGroup(preGroup);
+        //delete mc nodes
+        deleteMcNodesOfGroup(preGroup);
+        //delete group
+        deleteMcGroup(preGroup);
+
+        log.debug("Multicast group deleted. deviceId={}, {}", deviceId, preGroup);
+    }
+
+    @Override
+    public List<Bmv2PreGroup> getPreGroups() throws Bmv2RuntimeException {
+        try {
+            String entries = simplePreLagClient.bm_mc_get_entries(CONTEXT_ID);
+            return Bmv2PreGroupTranslatorImpl.translate(entries);
+
+        } catch (TException | IOException e) {
+            log.debug("Exception while getting multicast groups. deviceId={}", deviceId, e);
+
+            if (e instanceof TException) {
+                throw parseTException((TException) e);
+            } else {
+                throw new Bmv2RuntimeException(e);
+            }
+        }
+    }
+
+    /**
+     * Creates multicast nodes one by one.
+     * Node handles obtained as the results of node creation operations are stored
+     * in given Bmv2PreGroup object.
+     *
+     * @param preGroup Bmv2PreGroup object
+     * @throws Bmv2RuntimeException
+     */
+    private void createMcNodesOfGroup(Bmv2PreGroup preGroup) throws Bmv2RuntimeException {
+        for (Bmv2PreNode node : preGroup.nodes().nodes()) {
+            node.setL1Handle(createMcNode(node));
+        }
+    }
+
+    /**
+     * Associates multicast nodes with a group one by one.
+     *
+     * @param preGroup Bmv2PreGroup object
+     * @throws Bmv2RuntimeException
+     */
+    private void associateMcNodesOfGroup(Bmv2PreGroup preGroup) throws Bmv2RuntimeException {
+        int nativeGroupHandle = preGroup.nativeGroupHandle();
+        for (Bmv2PreNode node : preGroup.nodes().nodes()) {
+            associateMcNode(nativeGroupHandle, node);
+        }
+    }
+
+    /**
+     * Deletes multicast nodes one by one.
+     *
+     * @param preGroup Bmv2PreGroup object
+     * @throws Bmv2RuntimeException
+     */
+    private void deleteMcNodesOfGroup(Bmv2PreGroup preGroup) throws Bmv2RuntimeException {
+        for (Bmv2PreNode node : preGroup.nodes().nodes()) {
+            destroyMcNode(node);
+        }
+    }
+
+    /**
+     * Disassociates multicast nodes from a group one by one.
+     *
+     * @param preGroup Bmv2PreGroup object
+     * @throws Bmv2RuntimeException
+     */
+    private void disassociateMcNodesOfGroup(Bmv2PreGroup preGroup) throws Bmv2RuntimeException {
+        int nativeGroupHandle = preGroup.nativeGroupHandle();
+        for (Bmv2PreNode node : preGroup.nodes().nodes()) {
+            disassociateMcNode(nativeGroupHandle, node);
+        }
+    }
+
+
+    /**
+     * Creates a multicast group with specified group Id.
+     *
+     * @param groupId identifier of a group
+     * @return group handle (BMv2 specific identifier associated with the group)
+     * @throws Bmv2RuntimeException
+     */
+    private int createMcGroup(int groupId) throws Bmv2RuntimeException {
+        log.debug("Creating the multicast group... > deviceId={}, groupId={}", deviceId, groupId);
+        try {
+            return simplePreLagClient.bm_mc_mgrp_create(CONTEXT_ID, groupId);
+        } catch (TException e) {
+            log.debug("Exception during creating multicast group. deviceId={}, groupId={}", deviceId, groupId);
+            throw parseTException(e);
+        }
+    }
+
+    /**
+     * Deletes a multicast group from a BMv2 device.
+     *
+     * @param preGroup
+     * @throws Bmv2RuntimeException
+     */
+    private void deleteMcGroup(Bmv2PreGroup preGroup) throws Bmv2RuntimeException {
+        log.debug("Destroying the multicast group... > deviceId={}, groupId={}, groupHandle={}",
+                  deviceId, preGroup.groupId(), preGroup.nativeGroupHandle());
+        try {
+            simplePreLagClient.bm_mc_mgrp_destroy(CONTEXT_ID, preGroup.nativeGroupHandle());
+        } catch (TException e) {
+            log.debug("Exception during destroying multicast group. deviceId={}, groupId={}, groupHandle={}",
+                      deviceId, preGroup.groupId(), preGroup.nativeGroupHandle());
+            throw parseTException(e);
+        }
+    }
+
+    /**
+     * Creates a multicast node on the BMv2 device.
+     *
+     * @param node Bmv2PreNode
+     * @return L1 handle
+     * @throws Bmv2RuntimeException
+     */
+    private int createMcNode(Bmv2PreNode node) throws Bmv2RuntimeException {
+        log.debug("Creating the multicast node... > deviceId={}, {}", deviceId, node);
+        try {
+            return simplePreLagClient.bm_mc_node_create(CONTEXT_ID, node.rid(), node.portMap(), DEFAULT_LAG_MAP);
+        } catch (TException e) {
+            log.debug("Exception during creating multicast node: {}", node);
+            throw parseTException(e);
+        }
+    }
+
+    /**
+     * Associates a multicast node with a group.
+     *
+     * @param groupHandle handle of the group that the node will be associated with
+     * @param node        Bmv2PreNode
+     * @throws Bmv2RuntimeException
+     */
+    private void associateMcNode(int groupHandle, Bmv2PreNode node) throws Bmv2RuntimeException {
+        log.debug("Associating the multicast node with the group... > deviceId={}, groupHandle:{}, node:{}",
+                  deviceId, groupHandle, node);
+        try {
+            simplePreLagClient.bm_mc_node_associate(CONTEXT_ID, groupHandle, node.l1Handle());
+        } catch (TException e) {
+            log.debug("Exception during associating multicast node with group. deviceId={} groupHandle:{}, node:{}",
+                      deviceId, groupHandle, node);
+            throw parseTException(e);
+        }
+    }
+
+    /**
+     * Disassociates a multicast node from a group.
+     *
+     * @param groupHandle handle of the group that the node will be disassociated from
+     * @param node        Bmv2PreNode
+     * @throws Bmv2RuntimeException
+     */
+    private void disassociateMcNode(int groupHandle, Bmv2PreNode node) throws Bmv2RuntimeException {
+        log.debug("Disassociating the multicast node from the group... > deviceId={}, groupHandle:{}, node:{}",
+                  deviceId, groupHandle, node);
+        try {
+            simplePreLagClient.bm_mc_node_dissociate(CONTEXT_ID, groupHandle, node.l1Handle());
+        } catch (TException e) {
+            log.debug("Failed to disassociate multicast node from group. deviceId={} groupHandle:{}, node:{}",
+                      deviceId, groupHandle, node);
+            throw parseTException(e);
+        }
+    }
+
+    /**
+     * Destroys the multicast node in a BMv2 device.
+     *
+     * @param node PRE node which is about to be destroyed
+     * @throws Bmv2RuntimeException
+     */
+    private void destroyMcNode(Bmv2PreNode node) throws Bmv2RuntimeException {
+        log.debug("Destroying the multicast node... > deviceId={}, node:{}", deviceId, node);
+        try {
+            simplePreLagClient.bm_mc_node_destroy(CONTEXT_ID, node.l1Handle());
+        } catch (TException e) {
+            log.debug("Exception during destroying multicast node. deviceId={}, node:{}", deviceId, node);
+            throw parseTException(e);
+        }
+    }
+
+
+    /**
+     * Defines identifiers of main group operation steps.
+     */
+    private enum GroupOperationState {
+        IDLE, // nothing has been done
+        GROUP_CREATED, //the last successful step is group creation
+        NODES_CREATED, //the last successful step is node creation
+        NODES_ASSOCIATED //the last successful step is node association.
+    }
+
+    /**
+     * Implementation of a simple state machine to keep track of complex (non-atomic) operations on groups and
+     * to execute essential rollback steps accordingly.
+     * For example, creating a multicast group is composed of multiple steps:
+     * 1- Group creation
+     * 2- Node creation
+     * 3- Node association
+     * Each step associates with a GroupOperationState to keep track of group creation operation.
+     * A rollback flow is executed with respect to the current state.
+     */
+    private class GroupRollbackMachine {
+        Bmv2PreGroup preGroup;
+        //indicates the last successful step
+        GroupOperationState state = GroupOperationState.IDLE;
+
+        private GroupRollbackMachine() {
+            //hidden constructor
+        }
+
+        public GroupRollbackMachine(Bmv2PreGroup preGroup) {
+            this.preGroup = preGroup;
+        }
+
+        GroupOperationState state() {
+            return state;
+        }
+
+        void setState(GroupOperationState state) {
+            this.state = checkNotNull(state);
+        }
+
+        /**
+         * Checks the state and executes necessary rollback flow if necessary.
+         */
+        void rollbackIfNecessary() {
+            switch (state) {
+                case GROUP_CREATED:
+                    //means node creation failed. Delete already created nodes and the group
+                    onGroupCreated();
+                    break;
+                case NODES_CREATED:
+                    //means node association failed.
+                    //Disassociate already associated nodes then delete nodes and the group.
+                    onNodesCreated();
+                    break;
+                default:
+                    //do nothing in IDLE and NODES_ASSOCIATED states. They do not signify a failure.
+                    break;
+            }
+        }
+
+        /**
+         * Executes necessary steps in case the last successful step is group creation.
+         * This means one of the node creation operations has been failed and all previous steps should rollback.
+         */
+        private void onGroupCreated() {
+            log.warn("One of the steps of mc group creation operation has been failed." +
+                             "Rolling back in state {}...> deviceId={}, groupId={}",
+                     state, deviceId, preGroup.groupId());
+            deleteNodes(preGroup);
+            deleteGroup(preGroup);
+        }
+
+        /**
+         * Executes necessary steps in case the last successful step is node creation.
+         * This means one of the node association operations has been failed and all previous steps should rollback.
+         */
+        private void onNodesCreated() {
+            log.warn("One of the steps of mc group creation operation has been failed." +
+                             "Rolling back in state {}...> deviceId={}, groupId={}",
+                     state, deviceId, preGroup.groupId());
+            disassociateNodes(preGroup);
+            deleteNodes(preGroup);
+            deleteGroup(preGroup);
+        }
+
+        /**
+         * Deletes a group in the scope of rollback operation.
+         */
+        private void deleteGroup(Bmv2PreGroup preGroup) {
+            try {
+                deleteMcGroup(preGroup);
+            } catch (Bmv2RuntimeException e) {
+                log.error("Unable to destroy multicast group in the scope of rollback operation." +
+                                  "deviceId={}, groupId={}", deviceId, preGroup.groupId());
+            }
+        }
+
+
+        /**
+         * Disassociates all nodes from their group in the scope of rollback operation.
+         */
+        private void disassociateNodes(Bmv2PreGroup preGroup) {
+            preGroup.nodes().nodes().forEach(node -> {
+                try {
+                    disassociateMcNode(preGroup.nativeGroupHandle(), node);
+                } catch (Bmv2RuntimeException e) {
+                    log.error("Unable to disassociate the node in the scope of rollback operation." +
+                                      "deviceId={}, groupHandle={}, l1Handle={}",
+                              deviceId, preGroup.nativeGroupHandle(), node.l1Handle(), e);
+                }
+            });
+        }
+
+        /**
+         * Deletes all nodes of a group in the scope of rollback operation.
+         */
+        private void deleteNodes(Bmv2PreGroup preGroup) {
+            //filter created nodes and destroy them
+            preGroup.nodes().nodes().stream()
+                    .filter(node -> node.l1Handle() != null)
+                    .forEach(node -> {
+                        try {
+                            destroyMcNode(node);
+                        } catch (Bmv2RuntimeException e) {
+                            log.error("Unable to destroy the node in the scope of rollback operation." +
+                                              "deviceId={}, l1Handle={}", deviceId, node.l1Handle(), e);
+                        }
+                    });
+        }
+    }
+}
diff --git a/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/ctl/Bmv2PreControllerImpl.java b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/ctl/Bmv2PreControllerImpl.java
new file mode 100644
index 0000000..4c80e79
--- /dev/null
+++ b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/ctl/Bmv2PreControllerImpl.java
@@ -0,0 +1,237 @@
+/*
+ * Copyright 2018-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.drivers.bmv2.ctl;
+
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import com.google.common.collect.Maps;
+import org.apache.commons.lang3.tuple.Pair;
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Modified;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.thrift.protocol.TBinaryProtocol;
+import org.apache.thrift.protocol.TMultiplexedProtocol;
+import org.apache.thrift.protocol.TProtocol;
+import org.apache.thrift.transport.TSocket;
+import org.apache.thrift.transport.TTransport;
+import org.onlab.util.Tools;
+import org.onosproject.bmv2.thriftapi.SimplePreLAG;
+import org.onosproject.cfg.ComponentConfigService;
+import org.onosproject.drivers.bmv2.api.Bmv2DeviceAgent;
+import org.onosproject.drivers.bmv2.api.Bmv2PreController;
+import org.onosproject.net.DeviceId;
+import org.osgi.service.component.ComponentContext;
+import org.slf4j.Logger;
+
+import java.util.Dictionary;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static java.lang.String.format;
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * BMv2 PRE controller implementation.
+ */
+@Component(immediate = true)
+@Service
+public class Bmv2PreControllerImpl implements Bmv2PreController {
+
+    private static final int DEVICE_LOCK_CACHE_EXPIRE_TIME_IN_MIN = 10;
+    private static final int DEVICE_LOCK_WAITING_TIME_IN_SEC = 60;
+    private static final int DEFAULT_NUM_CONNECTION_RETRIES = 2;
+    private static final int DEFAULT_TIME_BETWEEN_RETRIES = 10;
+    private static final String THRIFT_SERVICE_NAME = "simple_pre_lag";
+    private final Logger log = getLogger(getClass());
+    private final Map<DeviceId, Pair<TTransport, Bmv2DeviceThriftClient>> clients = Maps.newHashMap();
+    //TODO consider a timeout mechanism for locks to limit the retention time
+    private final LoadingCache<DeviceId, ReadWriteLock> deviceLocks = CacheBuilder.newBuilder()
+            .expireAfterAccess(DEVICE_LOCK_CACHE_EXPIRE_TIME_IN_MIN, TimeUnit.MINUTES)
+            .build(new CacheLoader<DeviceId, ReadWriteLock>() {
+                @Override
+                public ReadWriteLock load(DeviceId deviceId) {
+                    return new ReentrantReadWriteLock();
+                }
+            });
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected ComponentConfigService cfgService;
+    @Property(name = "numConnectionRetries", intValue = DEFAULT_NUM_CONNECTION_RETRIES,
+            label = "Number of connection retries after a network error")
+    private int numConnectionRetries = DEFAULT_NUM_CONNECTION_RETRIES;
+    @Property(name = "timeBetweenRetries", intValue = DEFAULT_TIME_BETWEEN_RETRIES,
+            label = "Time between retries in milliseconds")
+    private int timeBetweenRetries = DEFAULT_TIME_BETWEEN_RETRIES;
+    @Property(name = "deviceLockWaitingTime", intValue = DEVICE_LOCK_WAITING_TIME_IN_SEC,
+            label = "Waiting time for a read/write lock in seconds")
+    private int deviceLockWaitingTime = DEVICE_LOCK_WAITING_TIME_IN_SEC;
+
+    @Activate
+    public void activate() {
+        cfgService.registerProperties(getClass());
+        log.info("Started");
+    }
+
+    @Deactivate
+    public void deactivate() {
+        cfgService.unregisterProperties(getClass(), false);
+        log.info("Stopped");
+    }
+
+    @Modified
+    protected void modified(ComponentContext context) {
+        Dictionary<?, ?> properties = context.getProperties();
+
+        Integer newNumConnRetries = Tools.getIntegerProperty(properties, "numConnectionRetries");
+        if (newNumConnRetries != null && newNumConnRetries >= 0) {
+            numConnectionRetries = newNumConnRetries;
+        } else {
+            log.warn("numConnectionRetries must be equal to or greater than 0");
+        }
+
+        Integer newTimeBtwRetries = Tools.getIntegerProperty(properties, "timeBetweenRetries");
+        if (newTimeBtwRetries != null && newTimeBtwRetries >= 0) {
+            timeBetweenRetries = newTimeBtwRetries;
+        } else {
+            log.warn("timeBetweenRetries must be equal to or greater than 0");
+        }
+
+        Integer newDeviceLockWaitingTime = Tools.getIntegerProperty(properties, "deviceLockWaitingTime");
+        if (newDeviceLockWaitingTime != null && newDeviceLockWaitingTime >= 0) {
+            deviceLockWaitingTime = newDeviceLockWaitingTime;
+        } else {
+            log.warn("deviceLockWaitingTime must be equal to or greater than 0");
+        }
+    }
+
+    @Override
+    public boolean createPreClient(DeviceId deviceId, String thriftServerIp, Integer thriftServerPort) {
+        checkNotNull(deviceId);
+        checkNotNull(thriftServerIp);
+        checkNotNull(thriftServerPort);
+
+        if (!acquireWriteLock(deviceId)) {
+            //reason is already logged during the lock acquisition
+            return false;
+        }
+
+        log.info("Creating PRE client for {} through Thrift server {}:{}", deviceId, thriftServerIp, thriftServerPort);
+
+        try {
+            if (clients.containsKey(deviceId)) {
+                throw new IllegalStateException(format("A client already exists for %s", deviceId));
+            } else {
+                return doCreateClient(deviceId, thriftServerIp, thriftServerPort);
+            }
+        } finally {
+            releaseWriteLock(deviceId);
+        }
+    }
+
+    @Override
+    public Bmv2DeviceAgent getPreClient(DeviceId deviceId) {
+        if (!acquireReadLock(deviceId)) {
+            return null;
+        }
+        try {
+            return clients.containsKey(deviceId) ? clients.get(deviceId).getRight() : null;
+        } finally {
+            releaseReadLock(deviceId);
+        }
+    }
+
+    @Override
+    public void removePreClient(DeviceId deviceId) {
+        if (!acquireWriteLock(deviceId)) {
+            //reason is already logged during the lock acquisition
+            return;
+        }
+
+        try {
+            if (clients.containsKey(deviceId)) {
+                TTransport transport = clients.get(deviceId).getLeft();
+                if (transport.isOpen()) {
+                    transport.close();
+                }
+                clients.remove(deviceId);
+            }
+        } finally {
+            releaseWriteLock(deviceId);
+        }
+    }
+
+    private boolean acquireWriteLock(DeviceId deviceId) {
+        try {
+            return deviceLocks.getUnchecked(deviceId).writeLock().tryLock(deviceLockWaitingTime, TimeUnit.SECONDS);
+        } catch (InterruptedException e) {
+            log.error("Unable to acquire write lock for device {} due to {}", deviceId, e.toString());
+        }
+        return false;
+    }
+
+    private boolean acquireReadLock(DeviceId deviceId) {
+        try {
+            return deviceLocks.getUnchecked(deviceId).readLock().tryLock(deviceLockWaitingTime, TimeUnit.SECONDS);
+        } catch (InterruptedException e) {
+            log.error("Unable to acquire read lock for device {} due to {}", deviceId, e.toString());
+        }
+        return false;
+    }
+
+    private void releaseWriteLock(DeviceId deviceId) {
+        deviceLocks.getUnchecked(deviceId).writeLock().unlock();
+    }
+
+    private void releaseReadLock(DeviceId deviceId) {
+        deviceLocks.getUnchecked(deviceId).readLock().unlock();
+    }
+
+    private boolean doCreateClient(DeviceId deviceId, String thriftServerIp, Integer thriftServerPort) {
+        SafeThriftClient.Options options = new SafeThriftClient.Options(numConnectionRetries, timeBetweenRetries);
+
+        try {
+            // Make the expensive call
+            TTransport transport = new TSocket(thriftServerIp, thriftServerPort);
+
+            TProtocol protocol = new TBinaryProtocol(transport);
+            // Create a client for simple_pre service.
+            SimplePreLAG.Client simplePreClient = new SimplePreLAG.Client(
+                    new TMultiplexedProtocol(protocol, THRIFT_SERVICE_NAME));
+
+            SimplePreLAG.Iface safeSimplePreClient = SafeThriftClient.wrap(simplePreClient,
+                                                                           SimplePreLAG.Iface.class,
+                                                                           options);
+
+            Bmv2DeviceThriftClient client = new Bmv2DeviceThriftClient(deviceId, safeSimplePreClient);
+            clients.put(deviceId, Pair.of(transport, client));
+            return true;
+
+        } catch (RuntimeException e) {
+            log.warn("Failed to create Thrift client for BMv2 device. deviceId={}, cause={}", deviceId, e);
+            return false;
+        }
+    }
+}
\ No newline at end of file
diff --git a/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/ctl/Bmv2TExceptionParser.java b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/ctl/Bmv2TExceptionParser.java
new file mode 100644
index 0000000..b765eca
--- /dev/null
+++ b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/ctl/Bmv2TExceptionParser.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2018-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.drivers.bmv2.ctl;
+
+
+import org.apache.thrift.TException;
+import org.onosproject.bmv2.thriftapi.InvalidMcOperation;
+import org.onosproject.drivers.bmv2.api.runtime.Bmv2RuntimeException;
+
+import static org.onosproject.drivers.bmv2.api.runtime.Bmv2RuntimeException.Code;
+
+/**
+ * Utility class to translate a Thrift exception into a Bmv2RuntimeException.
+ */
+final class Bmv2TExceptionParser {
+
+    private Bmv2TExceptionParser() {
+        // ban constructor.
+    }
+
+    static Bmv2RuntimeException parseTException(TException cause) {
+        try {
+            return new Bmv2RuntimeException(getCode(cause));
+        } catch (ParserException e) {
+            return new Bmv2RuntimeException(e.codeString);
+        }
+    }
+
+    private static Code getCode(TException e) throws ParserException {
+        if (e instanceof InvalidMcOperation) {
+            switch (((InvalidMcOperation) e).getCode()) {
+                case TABLE_FULL:
+                    return Code.TABLE_FULL;
+                case INVALID_MGID:
+                    return Code.INVALID_MGID;
+                case INVALID_L1_HANDLE:
+                    return Code.INVALID_L1_HANDLE;
+                case INVALID_MGRP_HANDLE:
+                    return Code.INVALID_MGRP_HANDLE;
+                case ERROR:
+                    return Code.MC_GENERAL_ERROR;
+                default:
+                    return Code.MC_UNKNOWN_ERROR;
+            }
+        } else {
+            throw new ParserException(e.toString());
+        }
+    }
+
+    private static class ParserException extends Exception {
+
+        private String codeString;
+
+        public ParserException(String codeString) {
+            this.codeString = codeString;
+        }
+    }
+}
diff --git a/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/ctl/SafeThriftClient.java b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/ctl/SafeThriftClient.java
new file mode 100644
index 0000000..a510954
--- /dev/null
+++ b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/ctl/SafeThriftClient.java
@@ -0,0 +1,251 @@
+/*
+ * Copyright 2018-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.
+ *
+ */
+
+/*
+ * Most of the code of this class was copied from:
+ * http://liveramp.com/engineering/reconnecting-thrift-client/
+ */
+
+package org.onosproject.drivers.bmv2.ctl;
+
+import com.google.common.collect.ImmutableSet;
+import org.apache.thrift.TServiceClient;
+import org.apache.thrift.transport.TTransport;
+import org.apache.thrift.transport.TTransportException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.Set;
+
+/**
+ * Thrift client wrapper that attempts a few reconnects before giving up a method call execution. It also provides
+ * synchronization between calls over the same transport.
+ */
+final class SafeThriftClient {
+
+    private static final Logger LOG = LoggerFactory.getLogger(SafeThriftClient.class);
+
+    /**
+     * List of causes which suggest a restart might fix things (defined as constants in {@link TTransportException}).
+     */
+    private static final Set<Integer> RESTARTABLE_CAUSES = ImmutableSet.of(TTransportException.NOT_OPEN,
+                                                                           TTransportException.END_OF_FILE,
+                                                                           TTransportException.TIMED_OUT,
+                                                                           TTransportException.UNKNOWN);
+
+    private SafeThriftClient() {
+        // ban constructor.
+    }
+
+    /**
+     * Reflectively wraps an already existing Thrift client.
+     *
+     * @param baseClient      the client to wrap
+     * @param clientInterface the interface that the client implements
+     * @param options         options that control behavior of the reconnecting client
+     * @param <T>             a class extending TServiceClient
+     * @param <C>             a client interface
+     * @return a wrapped client interface
+     */
+    public static <T extends TServiceClient, C> C wrap(T baseClient, Class<C> clientInterface, Options options) {
+        Object proxyObject = Proxy.newProxyInstance(clientInterface.getClassLoader(),
+                                                    new Class<?>[]{clientInterface},
+                                                    new ReconnectingClientProxy<T>(baseClient,
+                                                                                   options.getNumRetries(),
+                                                                                   options.getTimeBetweenRetries()));
+
+        return (C) proxyObject;
+    }
+
+    /**
+     * Reflectively wraps an already existing Thrift client.
+     *
+     * @param baseClient the client to wrap
+     * @param options    options that control behavior of the reconnecting client
+     * @param <T>        a class that extends TServiceClient
+     * @param <C>        a client interface
+     * @return a wrapped client interface
+     */
+    public static <T extends TServiceClient, C> C wrap(T baseClient, Options options) {
+        Class<?>[] interfaces = baseClient.getClass().getInterfaces();
+
+        for (Class<?> iface : interfaces) {
+            if (iface.getSimpleName().equals("Iface")
+                    && iface.getEnclosingClass().equals(baseClient.getClass().getEnclosingClass())) {
+                return (C) wrap(baseClient, iface, options);
+            }
+        }
+
+        throw new RuntimeException("Class needs to implement Iface directly. Use wrap(TServiceClient, Class) instead.");
+    }
+
+    /**
+     * Reflectively wraps an already existing Thrift client.
+     *
+     * @param baseClient      the client to wrap
+     * @param clientInterface the interface that the client implements
+     * @param <T>             a class that extends TServiceClient
+     * @param <C>             a client interface
+     * @return a wrapped client interface
+     */
+    public static <T extends TServiceClient, C> C wrap(T baseClient, Class<C> clientInterface) {
+        return wrap(baseClient, clientInterface, Options.defaults());
+    }
+
+    /**
+     * Reflectively wraps an already existing Thrift client.
+     *
+     * @param baseClient the client to wrap
+     * @param <T>        a class that extends TServiceClient
+     * @param <C>        a client interface
+     * @return a wrapped client interface
+     */
+    public static <T extends TServiceClient, C> C wrap(T baseClient) {
+        return wrap(baseClient, Options.defaults());
+    }
+
+    /**
+     * Reconnection options for {@link SafeThriftClient}.
+     */
+    public static class Options {
+        private int numRetries;
+        private long timeBetweenRetries;
+
+        /**
+         * Creates new options with the given parameters.
+         *
+         * @param numRetries         the maximum number of times to try reconnecting before giving up and throwing an
+         *                           exception
+         * @param timeBetweenRetries the number of milliseconds to wait in between reconnection attempts.
+         */
+        public Options(int numRetries, long timeBetweenRetries) {
+            this.numRetries = numRetries;
+            this.timeBetweenRetries = timeBetweenRetries;
+        }
+
+        private static Options defaults() {
+            return new Options(5, 10000L);
+        }
+
+        private int getNumRetries() {
+            return numRetries;
+        }
+
+        private long getTimeBetweenRetries() {
+            return timeBetweenRetries;
+        }
+    }
+
+    /**
+     * Helper proxy class. Attempts to call method on proxy object wrapped in try/catch. If it fails, it attempts a
+     * reconnect and tries the method again.
+     *
+     * @param <T> a class that extends TServiceClient
+     */
+    private static class ReconnectingClientProxy<T extends TServiceClient> implements InvocationHandler {
+        private final T baseClient;
+        private final TTransport transport;
+        private final int maxRetries;
+        private final long timeBetweenRetries;
+
+        public ReconnectingClientProxy(T baseClient, int maxRetries, long timeBetweenRetries) {
+            this.baseClient = baseClient;
+            this.transport = baseClient.getInputProtocol().getTransport();
+            this.maxRetries = maxRetries;
+            this.timeBetweenRetries = timeBetweenRetries;
+        }
+
+        private void reconnectOrThrowException()
+                throws TTransportException {
+            int errors = 0;
+            try {
+                if (transport.isOpen()) {
+                    transport.close();
+                }
+            } catch (Exception e) {
+                // Thrift seems to have a bug where if the transport is already closed a SocketException is thrown.
+                // However, such an exception is not advertised by .close(), hence the general-purpose catch.
+                LOG.debug("Exception while closing transport", e);
+            }
+
+            while (errors < maxRetries) {
+                try {
+                    LOG.debug("Attempting to reconnect...");
+                    transport.open();
+                    LOG.debug("Reconnection successful");
+                    break;
+                } catch (TTransportException e) {
+                    LOG.debug("Error while reconnecting:", e);
+                    errors++;
+
+                    if (errors < maxRetries) {
+                        try {
+                            LOG.debug("Sleeping for {} milliseconds before retrying", timeBetweenRetries);
+                            Thread.sleep(timeBetweenRetries);
+                        } catch (InterruptedException e2) {
+                            Thread.currentThread().interrupt();
+                            throw new RuntimeException(e);
+                        }
+                    }
+                }
+            }
+
+            if (errors >= maxRetries) {
+                throw new TTransportException("Failed to reconnect");
+            }
+        }
+
+        @Override
+        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+
+            // Thrift transport layer is not thread-safe (it's a wrapper on a socket), hence we need locking.
+            synchronized (transport) {
+
+                LOG.debug("Invoking method... > fromThread={}, method={}, args={}",
+                          Thread.currentThread().getId(), method.getName(), args);
+
+                try {
+
+                    return method.invoke(baseClient, args);
+                } catch (InvocationTargetException e) {
+                    if (e.getTargetException() instanceof TTransportException) {
+                        TTransportException cause = (TTransportException) e.getTargetException();
+
+                        if (RESTARTABLE_CAUSES.contains(cause.getType())) {
+                            // Try to reconnect. If fail, a TTransportException will be thrown.
+                            reconnectOrThrowException();
+                            try {
+                                // If here, transport has been successfully open, hence new exceptions will be thrown.
+                                return method.invoke(baseClient, args);
+                            } catch (InvocationTargetException e1) {
+                                LOG.debug("Exception: {}", e1.getTargetException());
+                                throw e1.getTargetException();
+                            }
+                        }
+                    }
+                    // Target exception is neither a TTransportException nor a restartable cause.
+                    LOG.debug("Exception: {}", e.getTargetException());
+                    throw e.getTargetException();
+                }
+            }
+        }
+    }
+}
diff --git a/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/ctl/package-info.java b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/ctl/package-info.java
new file mode 100644
index 0000000..f273b19
--- /dev/null
+++ b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/ctl/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2018-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 for BMv2 controller.
+ */
+package org.onosproject.drivers.bmv2.ctl;
\ No newline at end of file
diff --git a/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/impl/Bmv2PreGroupTranslatorImpl.java b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/impl/Bmv2PreGroupTranslatorImpl.java
new file mode 100644
index 0000000..6652ee0
--- /dev/null
+++ b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/impl/Bmv2PreGroupTranslatorImpl.java
@@ -0,0 +1,270 @@
+/*
+ * Copyright 2018-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.drivers.bmv2.impl;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.collect.Sets;
+import org.onosproject.core.GroupId;
+import org.onosproject.drivers.bmv2.api.runtime.Bmv2PreGroup;
+import org.onosproject.drivers.bmv2.api.runtime.Bmv2PreJsonGroups;
+import org.onosproject.drivers.bmv2.api.runtime.Bmv2PreNode;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.flow.TrafficTreatment;
+import org.onosproject.net.flow.instructions.Instructions;
+import org.onosproject.net.group.Group;
+import org.onosproject.net.group.GroupDescription;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+/**
+ * Implementation of BMv2 PRE group translation logic.
+ */
+public final class Bmv2PreGroupTranslatorImpl {
+
+    private static final int BMV2_PORT_MAP_SIZE = 256;
+
+    //hidden constructor
+    private Bmv2PreGroupTranslatorImpl() {
+    }
+
+    /**
+     * Returns a BMv2 PRE group equivalent to given group.
+     *
+     * @param group group
+     * @return a BMv2 PRE group
+     */
+    public static Bmv2PreGroup translate(Group group) {
+        if (!group.type().equals(GroupDescription.Type.ALL)) {
+            throw new RuntimeException("Unable to translate the group to BMv2 PRE group." +
+                                               "A BMv2 PRE group is to be of ALL type. GroupId="
+                                               + group.id());
+        }
+
+        Bmv2PreGroup.Bmv2PreGroupBuilder bmv2PreGroupBuilder = Bmv2PreGroup.builder();
+        bmv2PreGroupBuilder.withGroupId(group.id().id());
+        // RID is generated per an MG since L2 broadcast can be considered as a MG that have a single RID.
+        // for simplicity RID will be assigned to zero for any node in an MG.
+        int replicationId = 0;
+
+        Set<PortNumber> outPorts = Sets.newHashSet();
+        group.buckets().buckets().forEach(groupBucket -> {
+            //get output instructions of the bucket
+            Set<Instructions.OutputInstruction> outputInstructions = getOutputInstructions(groupBucket.treatment());
+            //check validity of output instructions
+            checkOutputInstructions(group.id(), outputInstructions);
+            outPorts.add(outputInstructions.iterator().next().port());
+        });
+        validatePorts(outPorts);
+        bmv2PreGroupBuilder.addNode(Bmv2PreNode.builder()
+                                            .withRid(replicationId)
+                                            .withPortMap(buildPortMap(outPorts))
+                                            .build());
+        return bmv2PreGroupBuilder.build();
+    }
+
+    /**
+     * Converts a PRE group list in JSON notation to list of Bmv2PreGroups.
+     *
+     * @param groupListJson group list string ing JSON notation
+     * @return list of Bmv2PreGroups
+     * @throws IOException in case JSON string can not be parsed
+     */
+    public static List<Bmv2PreGroup> translate(String groupListJson) throws IOException {
+        List<Bmv2PreGroup> preGroups = new ArrayList<>();
+        if (groupListJson == null) {
+            return preGroups;
+        }
+        ObjectMapper mapper = new ObjectMapper();
+        Bmv2PreJsonGroups bmv2PreJsonGroups = mapper.readValue(groupListJson, Bmv2PreJsonGroups.class);
+
+        Bmv2PreGroup.Bmv2PreGroupBuilder bmv2PreGroupBuilder;
+        for (Bmv2PreJsonGroups.Mgrp mgrp : bmv2PreJsonGroups.mgrps) {
+
+            bmv2PreGroupBuilder = Bmv2PreGroup.builder();
+            bmv2PreGroupBuilder.withGroupId(mgrp.id);
+
+            for (int l1handleId : mgrp.l1handles) {
+                Bmv2PreJsonGroups.L1Handle l1handle = getL1Handle(l1handleId, bmv2PreJsonGroups.l1handles);
+                if (l1handle == null) {
+                    continue;
+                }
+                Bmv2PreJsonGroups.L2Handle l2handle = getL2Handle(l1handle.l2handle, bmv2PreJsonGroups.l2handles);
+                if (l2handle == null) {
+                    continue;
+                }
+                bmv2PreGroupBuilder.addNode(Bmv2PreNode.builder()
+                                                    .withRid(l1handle.rid)
+                                                    .withPortMap(buildPortMap(l2handle.ports))
+                                                    .withL1Handle(l1handleId)
+                                                    .build());
+            }
+            preGroups.add(bmv2PreGroupBuilder.build());
+        }
+        return preGroups;
+    }
+
+    /**
+     * Retrieves L1Handle object pointed by given L1 handle pointer from L1 handles list.
+     *
+     * @param l1handlePointer pointer to a L1 handle
+     * @param l1handles       list of L1 handles
+     * @return L1 handle object if exists; null otherwise
+     */
+    private static Bmv2PreJsonGroups.L1Handle getL1Handle(int l1handlePointer,
+                                                          Bmv2PreJsonGroups.L1Handle[] l1handles) {
+        for (Bmv2PreJsonGroups.L1Handle l1Handle : l1handles) {
+            if (l1handlePointer == l1Handle.handle) {
+                return l1Handle;
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Retrieves L2Handle object pointed by given L2 handle pointer from L2 handles list.
+     *
+     * @param l2handlePointer pointer to a L2 handle
+     * @param l2handles       list of L2 handles
+     * @return L2 handle object if exists; null otherwise
+     */
+    private static Bmv2PreJsonGroups.L2Handle getL2Handle(int l2handlePointer,
+                                                          Bmv2PreJsonGroups.L2Handle[] l2handles) {
+        for (Bmv2PreJsonGroups.L2Handle l2handle : l2handles) {
+            if (l2handlePointer == l2handle.handle) {
+                return l2handle;
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Builds a port map string composing of 1 and 0s.
+     * BMv2 API reads a port map from most significant to least significant char.
+     * Index of 1s indicates port numbers.
+     * For example, if port numbers are 4,3 and 1, the generated port map string looks like 11010.
+     *
+     * @param outPorts set of output port numbers
+     * @return port map string
+     */
+    private static String buildPortMap(Set<PortNumber> outPorts) {
+        //Sorts port numbers in descending order
+        SortedSet<PortNumber> outPortsSorted = new TreeSet<>((o1, o2) -> (int) (o2.toLong() - o1.toLong()));
+        outPortsSorted.addAll(outPorts);
+        PortNumber biggestPort = outPortsSorted.iterator().next();
+        int portMapSize = (int) biggestPort.toLong() + 1;
+        //init and fill port map with zero characters
+        char[] portMap = new char[portMapSize];
+        Arrays.fill(portMap, '0');
+        //fill in the ports with 1
+        outPortsSorted.forEach(portNumber -> portMap[portMapSize - (int) portNumber.toLong() - 1] = '1');
+        return String.valueOf(portMap);
+    }
+
+    /**
+     * Builds a port map string composing of 1 and 0s.
+     * BMv2 API reads a port map from most significant to least significant char.
+     * The index of 1s indicates port numbers.
+     * For example, if port numbers are 4,3 and 1, the generated port map string looks like 11010.
+     *
+     * @param portArr array of output port numbers
+     * @return port map string
+     */
+    private static String buildPortMap(int[] portArr) {
+        Set<PortNumber> outPorts = new HashSet<>();
+        for (int port : portArr) {
+            outPorts.add(PortNumber.portNumber(port));
+        }
+        return buildPortMap(outPorts);
+    }
+
+    /**
+     * Retrieves output instructions out of the instruction set of the given traffic treatment.
+     *
+     * @param trafficTreatment
+     * @return set of output instructions
+     */
+    private static Set<Instructions.OutputInstruction> getOutputInstructions(TrafficTreatment trafficTreatment) {
+        if (trafficTreatment == null ||
+                trafficTreatment.allInstructions() == null) {
+            return Sets.newHashSet();
+        }
+        Set<Instructions.OutputInstruction> resultList = Sets.newHashSet();
+        trafficTreatment.allInstructions().forEach(instruction -> {
+            if (instruction instanceof Instructions.OutputInstruction) {
+                resultList.add((Instructions.OutputInstruction) instruction);
+            }
+        });
+        return resultList;
+    }
+
+    /**
+     * Checks validity of output instructions of a bucket.
+     * A bucket of a an ALL group must only have one output instruction.
+     * Other conditions can not pass the validation.
+     *
+     * @param groupId            group identifier
+     * @param outputInstructions set of output instructions
+     * @throws RuntimeException if the instructions can not be validated
+     */
+    private static void checkOutputInstructions(GroupId groupId,
+                                                Set<Instructions.OutputInstruction> outputInstructions) {
+        if (outputInstructions.isEmpty()) {
+            throw new RuntimeException(String.format("Group bucket contains no output instruction. GroupId=%s",
+                                                     groupId));
+        }
+        if (outputInstructions.size() != 1) {
+            throw new RuntimeException(String.format("Group bucket contains more than one output instructions. " +
+                                                             "Only one is supported. GroupId=%s", groupId));
+        }
+    }
+
+    /**
+     * Checks whether a port number is a valid physical BMv2 port or not.
+     * If not, throws RuntimeException; does nothing otherwise.
+     *
+     * @param portNumber port number
+     * @throws RuntimeException iff the port number can not be validated
+     */
+    private static void validatePort(PortNumber portNumber) {
+        if (portNumber.toLong() < 0 || portNumber.toLong() >= BMV2_PORT_MAP_SIZE) {
+            throw new RuntimeException(String.format("Port number %d is not a valid BMv2 physical port number." +
+                                                             "Valid port range is [0,255]", portNumber));
+        }
+    }
+
+    /**
+     * Checks whether a port number is a valid physical BMv2 port or not.
+     * If not, throws RuntimeException; does nothing otherwise.
+     *
+     * @param portNumbers port number set
+     * @throws RuntimeException iff a port number can not be validated
+     */
+    private static void validatePorts(Set<PortNumber> portNumbers) {
+        //validate one by one
+        for (PortNumber portNumber : portNumbers) {
+            validatePort(portNumber);
+        }
+    }
+}
\ No newline at end of file
diff --git a/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/impl/package-info.java b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/impl/package-info.java
new file mode 100644
index 0000000..5d03c9f
--- /dev/null
+++ b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/impl/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2018-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.
+ *
+ */
+/**
+ * Translator implementation for Group to BMv2 PRE Group translation logic.
+ */
+package org.onosproject.drivers.bmv2.impl;
\ No newline at end of file
diff --git a/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/mirror/AbstractDistributedBmv2Mirror.java b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/mirror/AbstractDistributedBmv2Mirror.java
new file mode 100644
index 0000000..d75be38
--- /dev/null
+++ b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/mirror/AbstractDistributedBmv2Mirror.java
@@ -0,0 +1,110 @@
+/*
+ * Copyright 2018-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.drivers.bmv2.mirror;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.onlab.util.KryoNamespace;
+import org.onosproject.drivers.bmv2.api.runtime.Bmv2Entity;
+import org.onosproject.drivers.bmv2.api.runtime.Bmv2Handle;
+import org.onosproject.net.DeviceId;
+import org.onosproject.store.service.EventuallyConsistentMap;
+import org.onosproject.store.service.StorageService;
+import org.onosproject.store.service.WallClockTimestamp;
+import org.slf4j.Logger;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Abstract implementation of a distributed BMv2 mirror, backed by an
+ * {@link EventuallyConsistentMap}.
+ *
+ * @param <H> Handle class
+ * @param <E> Entry class
+ */
+@Component(immediate = true)
+public abstract class AbstractDistributedBmv2Mirror
+        <H extends Bmv2Handle, E extends Bmv2Entity>
+        implements Bmv2Mirror<H, E> {
+
+
+    private final Logger log = getLogger(getClass());
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    private StorageService storageService;
+
+    private EventuallyConsistentMap<H, E> mirrorMap;
+
+    @Activate
+    public void activate() {
+        mirrorMap = storageService
+                .<H, E>eventuallyConsistentMapBuilder()
+                .withName(mapName())
+                .withSerializer(storeSerializer())
+                .withTimestampProvider((k, v) -> new WallClockTimestamp())
+                .build();
+        log.info("Started");
+    }
+
+    abstract String mapName();
+
+    abstract KryoNamespace storeSerializer();
+
+    @Deactivate
+    public void deactivate() {
+        mirrorMap.destroy();
+        mirrorMap = null;
+        log.info("Stopped");
+    }
+
+    @Override
+    public Collection<E> getAll(DeviceId deviceId) {
+        checkNotNull(deviceId);
+        return mirrorMap.entrySet().stream()
+                .filter(entry -> entry.getKey().deviceId().equals(deviceId))
+                .map(Map.Entry::getValue)
+                .collect(Collectors.toList());
+    }
+
+    @Override
+    public E get(H handle) {
+        checkNotNull(handle);
+        return mirrorMap.get(handle);
+    }
+
+    @Override
+    public void put(H handle, E entry) {
+        checkNotNull(handle);
+        checkNotNull(entry);
+        mirrorMap.put(handle, entry);
+    }
+
+    @Override
+    public void remove(H handle) {
+        checkNotNull(handle);
+        mirrorMap.remove(handle);
+    }
+}
\ No newline at end of file
diff --git a/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/mirror/Bmv2Mirror.java b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/mirror/Bmv2Mirror.java
new file mode 100644
index 0000000..9ade51c
--- /dev/null
+++ b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/mirror/Bmv2Mirror.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2018-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.drivers.bmv2.mirror;
+
+import org.onosproject.drivers.bmv2.api.runtime.Bmv2Entity;
+import org.onosproject.drivers.bmv2.api.runtime.Bmv2Handle;
+import org.onosproject.net.DeviceId;
+
+import java.util.Collection;
+
+/**
+ * Mirror of entities installed on a BMv2 device.
+ *
+ * @param <H> Handle class
+ * @param <E> Entity class
+ */
+public interface Bmv2Mirror<H extends Bmv2Handle, E extends Bmv2Entity> {
+
+    /**
+     * Returns all entries for the given device ID.
+     *
+     * @param deviceId device ID
+     * @return collection of BMv2 entries
+     */
+    Collection<E> getAll(DeviceId deviceId);
+
+    /**
+     * Returns entry associated to the given handle, if present, otherwise
+     * null.
+     *
+     * @param handle handle
+     * @return BMv2 entry
+     */
+    E get(H handle);
+
+    /**
+     * Stores the given entry associating it to the given handle.
+     *
+     * @param handle handle
+     * @param entry  entry
+     */
+    void put(H handle, E entry);
+
+    /**
+     * Removes the entry associated to the given handle.
+     *
+     * @param handle handle
+     */
+    void remove(H handle);
+}
diff --git a/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/mirror/Bmv2PreGroupMirror.java b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/mirror/Bmv2PreGroupMirror.java
new file mode 100644
index 0000000..3b4f124
--- /dev/null
+++ b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/mirror/Bmv2PreGroupMirror.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2018-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.drivers.bmv2.mirror;
+
+import org.onosproject.drivers.bmv2.api.runtime.Bmv2PreGroup;
+import org.onosproject.drivers.bmv2.api.runtime.Bmv2PreGroupHandle;
+
+/**
+ * Mirror of PRE groups installed on a BMv2 device.
+ */
+public interface Bmv2PreGroupMirror extends
+        Bmv2Mirror<Bmv2PreGroupHandle, Bmv2PreGroup> {
+}
diff --git a/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/mirror/DistributedBmv2PreGroupMirror.java b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/mirror/DistributedBmv2PreGroupMirror.java
new file mode 100644
index 0000000..1725676
--- /dev/null
+++ b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/mirror/DistributedBmv2PreGroupMirror.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2018-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.drivers.bmv2.mirror;
+
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Service;
+import org.onlab.util.KryoNamespace;
+import org.onosproject.drivers.bmv2.api.runtime.Bmv2EntityType;
+import org.onosproject.drivers.bmv2.api.runtime.Bmv2PreGroup;
+import org.onosproject.drivers.bmv2.api.runtime.Bmv2PreGroupHandle;
+import org.onosproject.drivers.bmv2.api.runtime.Bmv2PreNode;
+import org.onosproject.drivers.bmv2.api.runtime.Bmv2PreNodes;
+import org.onosproject.store.serializers.KryoNamespaces;
+
+
+/**
+ * Distributed implementation of a BMv2 PRE group mirror.
+ * We need this mirror to preserve BMv2-specific identifiers of group
+ * and nodes for further operations on them after creation.
+ */
+@Component(immediate = true)
+@Service
+public class DistributedBmv2PreGroupMirror
+        extends AbstractDistributedBmv2Mirror<Bmv2PreGroupHandle, Bmv2PreGroup>
+        implements Bmv2PreGroupMirror {
+
+    private static final String DIST_MAP_NAME = "onos-bmv2-pre-group-mirror";
+
+    @Override
+    String mapName() {
+        return DIST_MAP_NAME;
+    }
+
+    @Override
+    KryoNamespace storeSerializer() {
+        return KryoNamespace.newBuilder()
+                .register(KryoNamespaces.API)
+                .register(Bmv2EntityType.class)
+                .register(Bmv2PreNode.class)
+                .register(Bmv2PreNodes.class)
+                .register(Bmv2PreGroup.class)
+                .build();
+    }
+}
diff --git a/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/mirror/package-info.java b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/mirror/package-info.java
new file mode 100644
index 0000000..7c94e27
--- /dev/null
+++ b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/mirror/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2018-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.
+ *
+ */
+/**
+ * Mirror implementation for BMv2 driver.
+ */
+package org.onosproject.drivers.bmv2.mirror;
\ No newline at end of file
diff --git a/drivers/bmv2/src/main/resources/bmv2-drivers.xml b/drivers/bmv2/src/main/resources/bmv2-drivers.xml
index 7c1dc61..37b57e0 100644
--- a/drivers/bmv2/src/main/resources/bmv2-drivers.xml
+++ b/drivers/bmv2/src/main/resources/bmv2-drivers.xml
@@ -19,6 +19,10 @@
         <behaviour api="org.onosproject.net.behaviour.PiPipelineProgrammable"
                    impl="org.onosproject.drivers.bmv2.Bmv2PipelineProgrammable"/>
         <property name="tableDeleteBeforeUpdate">true</property>
+        <behaviour api="org.onosproject.net.group.GroupProgrammable"
+                   impl="org.onosproject.drivers.bmv2.Bmv2GroupProgrammable"/>
+        <behaviour api="org.onosproject.net.device.DeviceHandshaker"
+                   impl="org.onosproject.drivers.bmv2.Bmv2DeviceHandshaker"/>
     </driver>
 </drivers>
 
diff --git a/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/P4RuntimeGroupProgrammable.java b/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/P4RuntimeGroupProgrammable.java
index 125cd8a..dc2ec69 100644
--- a/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/P4RuntimeGroupProgrammable.java
+++ b/drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/P4RuntimeGroupProgrammable.java
@@ -76,7 +76,7 @@
     // the ONOS store.
     private boolean ignoreDeviceWhenGet = true;
 
-    private GroupStore groupStore;
+    protected GroupStore groupStore;
     private P4RuntimeGroupMirror groupMirror;
     private PiGroupTranslator translator;
 
diff --git a/modules.defs b/modules.defs
index 6161790..d1dd674 100644
--- a/modules.defs
+++ b/modules.defs
@@ -31,6 +31,7 @@
     '//protocols/bgp/bgpio:onos-protocols-bgp-bgpio',
     '//protocols/bgp/api:onos-protocols-bgp-api',
     '//protocols/bgp/ctl:onos-protocols-bgp-ctl',
+    '//protocols/bmv2/thrift-api:onos-protocols-bmv2-thrift-api',
     '//protocols/netconf/api:onos-protocols-netconf-api',
     '//protocols/netconf/ctl:onos-protocols-netconf-ctl',
     '//protocols/openflow/api:onos-protocols-openflow-api',
diff --git a/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/pipeliner/ForwardingFunctionType.java b/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/pipeliner/ForwardingFunctionType.java
index 3cf015d..0349cc7 100644
--- a/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/pipeliner/ForwardingFunctionType.java
+++ b/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/pipeliner/ForwardingFunctionType.java
@@ -19,7 +19,9 @@
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Sets;
+import org.onlab.packet.MacAddress;
 import org.onosproject.net.flow.criteria.Criterion;
+import org.onosproject.net.flow.criteria.EthCriterion;
 import org.onosproject.net.flowobjective.ForwardingObjective;
 
 import java.util.Map;
@@ -114,14 +116,35 @@
      */
     public static ForwardingFunctionType getForwardingFunctionType(ForwardingObjective fwd) {
         Set<Criterion.Type> criteriaType = Sets.newHashSet();
-        fwd.selector().criteria().stream().map(Criterion::type)
+        //omit the criterion of ethDst type with the value of MacAddress.NONE since it indicates L2 broadcast
+        //if not, the objective is treated as L2 unicast
+        fwd.selector().criteria().stream().filter(criterion -> !ethDstIndicatesBroadcast(criterion))
+                .map(Criterion::type)
                 .forEach(criteriaType::add);
 
         if (fwd.meta() != null) {
-            fwd.meta().criteria().stream().map(Criterion::type)
+            fwd.meta().criteria().stream().filter(criterion -> !ethDstIndicatesBroadcast(criterion))
+                    .map(Criterion::type)
                     .forEach(criteriaType::add);
         }
 
         return FFT_MAP.getOrDefault(criteriaType, UNSUPPORTED);
     }
+
+    /**
+     * Segment Routing (SR) app. sets ethDst criterion to MacAddress.NONE for broadcast rules
+     * and demands drivers to treat the flow rules containing this criterion as broadcast rule.
+     *
+     * This method checks the type and value of the criterion and detects whether it constitutes
+     * broadcast or not.
+     *
+     * For more details check RoutingRulePopulator.updateSubnetBroadcastRule method of SR app.
+     *
+     * @param criterion Criterion object
+     * @return true if the type is ETH_DST and the mac value equals to MacAddress.NONE; false otherwise.
+     */
+    private static boolean ethDstIndicatesBroadcast(Criterion criterion) {
+        return criterion.type().equals(Criterion.Type.ETH_DST) &&
+                ((EthCriterion) criterion).mac().equals(MacAddress.NONE);
+    }
 }
diff --git a/pipelines/fabric/src/main/resources/include/control/next.p4 b/pipelines/fabric/src/main/resources/include/control/next.p4
index 65f9375..0b22ca1 100644
--- a/pipelines/fabric/src/main/resources/include/control/next.p4
+++ b/pipelines/fabric/src/main/resources/include/control/next.p4
@@ -141,13 +141,11 @@
         counters = hashed_counter;
     }
 
-#ifdef WITH_MULTICAST
     /*
      * Work in progress
      */
-    action set_mcast_group(group_id_t gid, mac_addr_t smac) {
+    action set_mcast_group(group_id_t gid) {
         standard_metadata.mcast_grp = gid;
-        rewrite_smac(smac);
     }
 
     direct_counter(CounterType.packets_and_bytes) multicast_counter;
@@ -161,7 +159,6 @@
         }
         counters = multicast_counter;
     }
-#endif // WITH_MULTICAST
 
     apply {
         vlan_meta.apply();
@@ -178,9 +175,7 @@
             }
         }
         hashed.apply();
-#ifdef WITH_MULTICAST
         multicast.apply();
-#endif // WITH_MULTICAST
     }
 }
 
diff --git a/pipelines/fabric/src/main/resources/p4c-out/fabric-spgw/bmv2/default/bmv2.json b/pipelines/fabric/src/main/resources/p4c-out/fabric-spgw/bmv2/default/bmv2.json
index f3439fe..8a09ac2 100644
--- a/pipelines/fabric/src/main/resources/p4c-out/fabric-spgw/bmv2/default/bmv2.json
+++ b/pipelines/fabric/src/main/resources/p4c-out/fabric-spgw/bmv2/default/bmv2.json
@@ -934,8 +934,14 @@
       "binding" : "FabricIngress.next.hashed"
     },
     {
-      "name" : "FabricIngress.port_counters_control.egress_port_counter",
+      "name" : "FabricIngress.next.multicast_counter",
       "id" : 10,
+      "is_direct" : true,
+      "binding" : "FabricIngress.next.multicast"
+    },
+    {
+      "name" : "FabricIngress.port_counters_control.egress_port_counter",
+      "id" : 11,
       "source_info" : {
         "filename" : "include/control/port_counter.p4",
         "line" : 23,
@@ -947,7 +953,7 @@
     },
     {
       "name" : "FabricIngress.port_counters_control.ingress_port_counter",
-      "id" : 11,
+      "id" : 12,
       "source_info" : {
         "filename" : "include/control/port_counter.p4",
         "line" : 24,
@@ -1189,7 +1195,7 @@
       "primitives" : []
     },
     {
-      "name" : "nop",
+      "name" : "NoAction",
       "id" : 9,
       "runtime_data" : [],
       "primitives" : []
@@ -1207,9 +1213,15 @@
       "primitives" : []
     },
     {
-      "name" : "FabricIngress.spgw_ingress.drop_now",
+      "name" : "nop",
       "id" : 12,
       "runtime_data" : [],
+      "primitives" : []
+    },
+    {
+      "name" : "FabricIngress.spgw_ingress.drop_now",
+      "id" : 13,
+      "runtime_data" : [],
       "primitives" : [
         {
           "op" : "drop",
@@ -1235,7 +1247,7 @@
     },
     {
       "name" : "FabricIngress.spgw_ingress.gtpu_decap",
-      "id" : 13,
+      "id" : 14,
       "runtime_data" : [],
       "primitives" : [
         {
@@ -1287,7 +1299,7 @@
     },
     {
       "name" : "FabricIngress.spgw_ingress.set_dl_sess_info",
-      "id" : 14,
+      "id" : 15,
       "runtime_data" : [
         {
           "name" : "teid",
@@ -1364,13 +1376,13 @@
     },
     {
       "name" : "FabricIngress.spgw_ingress.update_ue_cdr",
-      "id" : 15,
+      "id" : 16,
       "runtime_data" : [],
       "primitives" : []
     },
     {
       "name" : "FabricIngress.filtering.drop",
-      "id" : 16,
+      "id" : 17,
       "runtime_data" : [],
       "primitives" : [
         {
@@ -1387,7 +1399,7 @@
     },
     {
       "name" : "FabricIngress.filtering.set_vlan",
-      "id" : 17,
+      "id" : 18,
       "runtime_data" : [
         {
           "name" : "new_vlan_id",
@@ -1418,7 +1430,7 @@
     },
     {
       "name" : "FabricIngress.filtering.push_internal_vlan",
-      "id" : 18,
+      "id" : 19,
       "runtime_data" : [
         {
           "name" : "new_vlan_id",
@@ -1569,7 +1581,7 @@
     },
     {
       "name" : "FabricIngress.filtering.set_forwarding_type",
-      "id" : 19,
+      "id" : 20,
       "runtime_data" : [
         {
           "name" : "fwd_type",
@@ -1600,7 +1612,7 @@
     },
     {
       "name" : "FabricIngress.forwarding.drop",
-      "id" : 20,
+      "id" : 21,
       "runtime_data" : [],
       "primitives" : [
         {
@@ -1617,37 +1629,6 @@
     },
     {
       "name" : "FabricIngress.forwarding.set_next_id",
-      "id" : 21,
-      "runtime_data" : [
-        {
-          "name" : "next_id",
-          "bitwidth" : 32
-        }
-      ],
-      "primitives" : [
-        {
-          "op" : "assign",
-          "parameters" : [
-            {
-              "type" : "field",
-              "value" : ["scalars", "fabric_metadata_t.next_id"]
-            },
-            {
-              "type" : "runtime_data",
-              "value" : 0
-            }
-          ],
-          "source_info" : {
-            "filename" : "include/control/forwarding.p4",
-            "line" : 40,
-            "column" : 8,
-            "source_fragment" : "fabric_metadata.next_id = next_id"
-          }
-        }
-      ]
-    },
-    {
-      "name" : "FabricIngress.forwarding.set_next_id",
       "id" : 22,
       "runtime_data" : [
         {
@@ -1709,7 +1690,7 @@
       ]
     },
     {
-      "name" : "FabricIngress.forwarding.pop_mpls_and_next",
+      "name" : "FabricIngress.forwarding.set_next_id",
       "id" : 24,
       "runtime_data" : [
         {
@@ -1719,6 +1700,37 @@
       ],
       "primitives" : [
         {
+          "op" : "assign",
+          "parameters" : [
+            {
+              "type" : "field",
+              "value" : ["scalars", "fabric_metadata_t.next_id"]
+            },
+            {
+              "type" : "runtime_data",
+              "value" : 0
+            }
+          ],
+          "source_info" : {
+            "filename" : "include/control/forwarding.p4",
+            "line" : 40,
+            "column" : 8,
+            "source_fragment" : "fabric_metadata.next_id = next_id"
+          }
+        }
+      ]
+    },
+    {
+      "name" : "FabricIngress.forwarding.pop_mpls_and_next",
+      "id" : 25,
+      "runtime_data" : [
+        {
+          "name" : "next_id",
+          "bitwidth" : 32
+        }
+      ],
+      "primitives" : [
+        {
           "op" : "remove_header",
           "parameters" : [
             {
@@ -1756,7 +1768,7 @@
     },
     {
       "name" : "FabricIngress.forwarding.duplicate_to_controller",
-      "id" : 25,
+      "id" : 26,
       "runtime_data" : [],
       "primitives" : [
         {
@@ -1782,7 +1794,7 @@
     },
     {
       "name" : "FabricIngress.next.output",
-      "id" : 26,
+      "id" : 27,
       "runtime_data" : [
         {
           "name" : "port_num",
@@ -1813,7 +1825,7 @@
     },
     {
       "name" : "FabricIngress.next.set_vlan",
-      "id" : 27,
+      "id" : 28,
       "runtime_data" : [
         {
           "name" : "new_vlan_id",
@@ -1844,7 +1856,7 @@
     },
     {
       "name" : "FabricIngress.next.set_vlan_output",
-      "id" : 28,
+      "id" : 29,
       "runtime_data" : [
         {
           "name" : "new_vlan_id",
@@ -1898,83 +1910,6 @@
     },
     {
       "name" : "FabricIngress.next.l3_routing",
-      "id" : 29,
-      "runtime_data" : [
-        {
-          "name" : "port_num",
-          "bitwidth" : 9
-        },
-        {
-          "name" : "smac",
-          "bitwidth" : 48
-        },
-        {
-          "name" : "dmac",
-          "bitwidth" : 48
-        }
-      ],
-      "primitives" : [
-        {
-          "op" : "assign",
-          "parameters" : [
-            {
-              "type" : "field",
-              "value" : ["ethernet", "src_addr"]
-            },
-            {
-              "type" : "runtime_data",
-              "value" : 1
-            }
-          ],
-          "source_info" : {
-            "filename" : "include/control/next.p4",
-            "line" : 51,
-            "column" : 8,
-            "source_fragment" : "hdr.ethernet.src_addr = smac; ..."
-          }
-        },
-        {
-          "op" : "assign",
-          "parameters" : [
-            {
-              "type" : "field",
-              "value" : ["ethernet", "dst_addr"]
-            },
-            {
-              "type" : "runtime_data",
-              "value" : 2
-            }
-          ],
-          "source_info" : {
-            "filename" : "include/control/next.p4",
-            "line" : 55,
-            "column" : 8,
-            "source_fragment" : "hdr.ethernet.dst_addr = dmac; ..."
-          }
-        },
-        {
-          "op" : "assign",
-          "parameters" : [
-            {
-              "type" : "field",
-              "value" : ["standard_metadata", "egress_spec"]
-            },
-            {
-              "type" : "runtime_data",
-              "value" : 0
-            }
-          ],
-          "source_info" : {
-            "filename" : "include/control/next.p4",
-            "line" : 33,
-            "column" : 8,
-            "source_fragment" : "standard_metadata.egress_spec = port_num; ..."
-          }
-        }
-      ]
-    },
-    {
-      "name" : "FabricIngress.next.l3_routing",
       "id" : 30,
       "runtime_data" : [
         {
@@ -2051,7 +1986,7 @@
       ]
     },
     {
-      "name" : "FabricIngress.next.l3_routing_vlan",
+      "name" : "FabricIngress.next.l3_routing",
       "id" : 31,
       "runtime_data" : [
         {
@@ -2065,6 +2000,83 @@
         {
           "name" : "dmac",
           "bitwidth" : 48
+        }
+      ],
+      "primitives" : [
+        {
+          "op" : "assign",
+          "parameters" : [
+            {
+              "type" : "field",
+              "value" : ["ethernet", "src_addr"]
+            },
+            {
+              "type" : "runtime_data",
+              "value" : 1
+            }
+          ],
+          "source_info" : {
+            "filename" : "include/control/next.p4",
+            "line" : 51,
+            "column" : 8,
+            "source_fragment" : "hdr.ethernet.src_addr = smac; ..."
+          }
+        },
+        {
+          "op" : "assign",
+          "parameters" : [
+            {
+              "type" : "field",
+              "value" : ["ethernet", "dst_addr"]
+            },
+            {
+              "type" : "runtime_data",
+              "value" : 2
+            }
+          ],
+          "source_info" : {
+            "filename" : "include/control/next.p4",
+            "line" : 55,
+            "column" : 8,
+            "source_fragment" : "hdr.ethernet.dst_addr = dmac; ..."
+          }
+        },
+        {
+          "op" : "assign",
+          "parameters" : [
+            {
+              "type" : "field",
+              "value" : ["standard_metadata", "egress_spec"]
+            },
+            {
+              "type" : "runtime_data",
+              "value" : 0
+            }
+          ],
+          "source_info" : {
+            "filename" : "include/control/next.p4",
+            "line" : 33,
+            "column" : 8,
+            "source_fragment" : "standard_metadata.egress_spec = port_num; ..."
+          }
+        }
+      ]
+    },
+    {
+      "name" : "FabricIngress.next.l3_routing_vlan",
+      "id" : 32,
+      "runtime_data" : [
+        {
+          "name" : "port_num",
+          "bitwidth" : 9
+        },
+        {
+          "name" : "smac",
+          "bitwidth" : 48
+        },
+        {
+          "name" : "dmac",
+          "bitwidth" : 48
         },
         {
           "name" : "new_vlan_id",
@@ -2152,197 +2164,6 @@
     },
     {
       "name" : "FabricIngress.next.mpls_routing_v4",
-      "id" : 32,
-      "runtime_data" : [
-        {
-          "name" : "port_num",
-          "bitwidth" : 9
-        },
-        {
-          "name" : "smac",
-          "bitwidth" : 48
-        },
-        {
-          "name" : "dmac",
-          "bitwidth" : 48
-        },
-        {
-          "name" : "label",
-          "bitwidth" : 20
-        }
-      ],
-      "primitives" : [
-        {
-          "op" : "assign",
-          "parameters" : [
-            {
-              "type" : "field",
-              "value" : ["ethernet", "src_addr"]
-            },
-            {
-              "type" : "runtime_data",
-              "value" : 1
-            }
-          ],
-          "source_info" : {
-            "filename" : "include/control/next.p4",
-            "line" : 51,
-            "column" : 8,
-            "source_fragment" : "hdr.ethernet.src_addr = smac; ..."
-          }
-        },
-        {
-          "op" : "assign",
-          "parameters" : [
-            {
-              "type" : "field",
-              "value" : ["ethernet", "dst_addr"]
-            },
-            {
-              "type" : "runtime_data",
-              "value" : 2
-            }
-          ],
-          "source_info" : {
-            "filename" : "include/control/next.p4",
-            "line" : 55,
-            "column" : 8,
-            "source_fragment" : "hdr.ethernet.dst_addr = dmac; ..."
-          }
-        },
-        {
-          "op" : "assign",
-          "parameters" : [
-            {
-              "type" : "field",
-              "value" : ["standard_metadata", "egress_spec"]
-            },
-            {
-              "type" : "runtime_data",
-              "value" : 0
-            }
-          ],
-          "source_info" : {
-            "filename" : "include/control/next.p4",
-            "line" : 33,
-            "column" : 8,
-            "source_fragment" : "standard_metadata.egress_spec = port_num; ..."
-          }
-        },
-        {
-          "op" : "add_header",
-          "parameters" : [
-            {
-              "type" : "header",
-              "value" : "mpls"
-            }
-          ],
-          "source_info" : {
-            "filename" : "include/control/next.p4",
-            "line" : 72,
-            "column" : 8,
-            "source_fragment" : "hdr.mpls.setValid()"
-          }
-        },
-        {
-          "op" : "assign",
-          "parameters" : [
-            {
-              "type" : "field",
-              "value" : ["vlan_tag", "ether_type"]
-            },
-            {
-              "type" : "hexstr",
-              "value" : "0x8847"
-            }
-          ],
-          "source_info" : {
-            "filename" : "include/control/../define.p4",
-            "line" : 67,
-            "column" : 31,
-            "source_fragment" : "0x8847; ..."
-          }
-        },
-        {
-          "op" : "assign",
-          "parameters" : [
-            {
-              "type" : "field",
-              "value" : ["mpls", "label"]
-            },
-            {
-              "type" : "runtime_data",
-              "value" : 3
-            }
-          ],
-          "source_info" : {
-            "filename" : "include/control/next.p4",
-            "line" : 74,
-            "column" : 8,
-            "source_fragment" : "hdr.mpls.label = label; ..."
-          }
-        },
-        {
-          "op" : "assign",
-          "parameters" : [
-            {
-              "type" : "field",
-              "value" : ["mpls", "tc"]
-            },
-            {
-              "type" : "hexstr",
-              "value" : "0x00"
-            }
-          ],
-          "source_info" : {
-            "filename" : "include/control/next.p4",
-            "line" : 75,
-            "column" : 8,
-            "source_fragment" : "hdr.mpls.tc = tc; ..."
-          }
-        },
-        {
-          "op" : "assign",
-          "parameters" : [
-            {
-              "type" : "field",
-              "value" : ["mpls", "bos"]
-            },
-            {
-              "type" : "hexstr",
-              "value" : "0x01"
-            }
-          ],
-          "source_info" : {
-            "filename" : "include/control/next.p4",
-            "line" : 76,
-            "column" : 8,
-            "source_fragment" : "hdr.mpls.bos = 1w1"
-          }
-        },
-        {
-          "op" : "assign",
-          "parameters" : [
-            {
-              "type" : "field",
-              "value" : ["mpls", "ttl"]
-            },
-            {
-              "type" : "hexstr",
-              "value" : "0x40"
-            }
-          ],
-          "source_info" : {
-            "filename" : "include/control/../define.p4",
-            "line" : 87,
-            "column" : 32,
-            "source_fragment" : "64; ..."
-          }
-        }
-      ]
-    },
-    {
-      "name" : "FabricIngress.next.mpls_routing_v4",
       "id" : 33,
       "runtime_data" : [
         {
@@ -2533,7 +2354,7 @@
       ]
     },
     {
-      "name" : "FabricIngress.next.mpls_routing_v6",
+      "name" : "FabricIngress.next.mpls_routing_v4",
       "id" : 34,
       "runtime_data" : [
         {
@@ -2724,8 +2545,230 @@
       ]
     },
     {
-      "name" : "act",
+      "name" : "FabricIngress.next.mpls_routing_v6",
       "id" : 35,
+      "runtime_data" : [
+        {
+          "name" : "port_num",
+          "bitwidth" : 9
+        },
+        {
+          "name" : "smac",
+          "bitwidth" : 48
+        },
+        {
+          "name" : "dmac",
+          "bitwidth" : 48
+        },
+        {
+          "name" : "label",
+          "bitwidth" : 20
+        }
+      ],
+      "primitives" : [
+        {
+          "op" : "assign",
+          "parameters" : [
+            {
+              "type" : "field",
+              "value" : ["ethernet", "src_addr"]
+            },
+            {
+              "type" : "runtime_data",
+              "value" : 1
+            }
+          ],
+          "source_info" : {
+            "filename" : "include/control/next.p4",
+            "line" : 51,
+            "column" : 8,
+            "source_fragment" : "hdr.ethernet.src_addr = smac; ..."
+          }
+        },
+        {
+          "op" : "assign",
+          "parameters" : [
+            {
+              "type" : "field",
+              "value" : ["ethernet", "dst_addr"]
+            },
+            {
+              "type" : "runtime_data",
+              "value" : 2
+            }
+          ],
+          "source_info" : {
+            "filename" : "include/control/next.p4",
+            "line" : 55,
+            "column" : 8,
+            "source_fragment" : "hdr.ethernet.dst_addr = dmac; ..."
+          }
+        },
+        {
+          "op" : "assign",
+          "parameters" : [
+            {
+              "type" : "field",
+              "value" : ["standard_metadata", "egress_spec"]
+            },
+            {
+              "type" : "runtime_data",
+              "value" : 0
+            }
+          ],
+          "source_info" : {
+            "filename" : "include/control/next.p4",
+            "line" : 33,
+            "column" : 8,
+            "source_fragment" : "standard_metadata.egress_spec = port_num; ..."
+          }
+        },
+        {
+          "op" : "add_header",
+          "parameters" : [
+            {
+              "type" : "header",
+              "value" : "mpls"
+            }
+          ],
+          "source_info" : {
+            "filename" : "include/control/next.p4",
+            "line" : 72,
+            "column" : 8,
+            "source_fragment" : "hdr.mpls.setValid()"
+          }
+        },
+        {
+          "op" : "assign",
+          "parameters" : [
+            {
+              "type" : "field",
+              "value" : ["vlan_tag", "ether_type"]
+            },
+            {
+              "type" : "hexstr",
+              "value" : "0x8847"
+            }
+          ],
+          "source_info" : {
+            "filename" : "include/control/../define.p4",
+            "line" : 67,
+            "column" : 31,
+            "source_fragment" : "0x8847; ..."
+          }
+        },
+        {
+          "op" : "assign",
+          "parameters" : [
+            {
+              "type" : "field",
+              "value" : ["mpls", "label"]
+            },
+            {
+              "type" : "runtime_data",
+              "value" : 3
+            }
+          ],
+          "source_info" : {
+            "filename" : "include/control/next.p4",
+            "line" : 74,
+            "column" : 8,
+            "source_fragment" : "hdr.mpls.label = label; ..."
+          }
+        },
+        {
+          "op" : "assign",
+          "parameters" : [
+            {
+              "type" : "field",
+              "value" : ["mpls", "tc"]
+            },
+            {
+              "type" : "hexstr",
+              "value" : "0x00"
+            }
+          ],
+          "source_info" : {
+            "filename" : "include/control/next.p4",
+            "line" : 75,
+            "column" : 8,
+            "source_fragment" : "hdr.mpls.tc = tc; ..."
+          }
+        },
+        {
+          "op" : "assign",
+          "parameters" : [
+            {
+              "type" : "field",
+              "value" : ["mpls", "bos"]
+            },
+            {
+              "type" : "hexstr",
+              "value" : "0x01"
+            }
+          ],
+          "source_info" : {
+            "filename" : "include/control/next.p4",
+            "line" : 76,
+            "column" : 8,
+            "source_fragment" : "hdr.mpls.bos = 1w1"
+          }
+        },
+        {
+          "op" : "assign",
+          "parameters" : [
+            {
+              "type" : "field",
+              "value" : ["mpls", "ttl"]
+            },
+            {
+              "type" : "hexstr",
+              "value" : "0x40"
+            }
+          ],
+          "source_info" : {
+            "filename" : "include/control/../define.p4",
+            "line" : 87,
+            "column" : 32,
+            "source_fragment" : "64; ..."
+          }
+        }
+      ]
+    },
+    {
+      "name" : "FabricIngress.next.set_mcast_group",
+      "id" : 36,
+      "runtime_data" : [
+        {
+          "name" : "gid",
+          "bitwidth" : 16
+        }
+      ],
+      "primitives" : [
+        {
+          "op" : "assign",
+          "parameters" : [
+            {
+              "type" : "field",
+              "value" : ["standard_metadata", "mcast_grp"]
+            },
+            {
+              "type" : "runtime_data",
+              "value" : 0
+            }
+          ],
+          "source_info" : {
+            "filename" : "include/control/next.p4",
+            "line" : 148,
+            "column" : 8,
+            "source_fragment" : "standard_metadata.mcast_grp = gid"
+          }
+        }
+      ]
+    },
+    {
+      "name" : "act",
+      "id" : 37,
       "runtime_data" : [],
       "primitives" : [
         {
@@ -2766,7 +2809,7 @@
     },
     {
       "name" : "act_0",
-      "id" : 36,
+      "id" : 38,
       "runtime_data" : [],
       "primitives" : [
         {
@@ -2796,7 +2839,7 @@
     },
     {
       "name" : "act_1",
-      "id" : 37,
+      "id" : 39,
       "runtime_data" : [],
       "primitives" : [
         {
@@ -2826,7 +2869,7 @@
     },
     {
       "name" : "act_2",
-      "id" : 38,
+      "id" : 40,
       "runtime_data" : [],
       "primitives" : [
         {
@@ -2909,7 +2952,7 @@
     },
     {
       "name" : "act_3",
-      "id" : 39,
+      "id" : 41,
       "runtime_data" : [],
       "primitives" : [
         {
@@ -2964,7 +3007,7 @@
     },
     {
       "name" : "act_4",
-      "id" : 40,
+      "id" : 42,
       "runtime_data" : [],
       "primitives" : [
         {
@@ -2994,7 +3037,7 @@
     },
     {
       "name" : "act_5",
-      "id" : 41,
+      "id" : 43,
       "runtime_data" : [],
       "primitives" : [
         {
@@ -3024,7 +3067,7 @@
     },
     {
       "name" : "act_6",
-      "id" : 42,
+      "id" : 44,
       "runtime_data" : [],
       "primitives" : [
         {
@@ -3079,7 +3122,7 @@
     },
     {
       "name" : "act_7",
-      "id" : 43,
+      "id" : 45,
       "runtime_data" : [],
       "primitives" : [
         {
@@ -3121,7 +3164,7 @@
                   "left" : null,
                   "right" : {
                     "type" : "bool",
-                    "value" : true
+                    "value" : false
                   }
                 }
               }
@@ -3131,14 +3174,14 @@
             "filename" : "include/spgw.p4",
             "line" : 146,
             "column" : 8,
-            "source_fragment" : "spgw_meta.do_spgw = true"
+            "source_fragment" : "spgw_meta.do_spgw = false"
           }
         }
       ]
     },
     {
       "name" : "act_8",
-      "id" : 44,
+      "id" : 46,
       "runtime_data" : [],
       "primitives" : [
         {
@@ -3174,7 +3217,7 @@
     },
     {
       "name" : "act_9",
-      "id" : 45,
+      "id" : 47,
       "runtime_data" : [],
       "primitives" : [
         {
@@ -3204,7 +3247,7 @@
     },
     {
       "name" : "act_10",
-      "id" : 46,
+      "id" : 48,
       "runtime_data" : [],
       "primitives" : [
         {
@@ -3234,7 +3277,7 @@
     },
     {
       "name" : "act_11",
-      "id" : 47,
+      "id" : 49,
       "runtime_data" : [],
       "primitives" : [
         {
@@ -3260,7 +3303,7 @@
     },
     {
       "name" : "act_12",
-      "id" : 48,
+      "id" : 50,
       "runtime_data" : [],
       "primitives" : [
         {
@@ -3305,7 +3348,7 @@
     },
     {
       "name" : "act_13",
-      "id" : 49,
+      "id" : 51,
       "runtime_data" : [],
       "primitives" : [
         {
@@ -3335,7 +3378,7 @@
     },
     {
       "name" : "act_14",
-      "id" : 50,
+      "id" : 52,
       "runtime_data" : [],
       "primitives" : [
         {
@@ -3365,7 +3408,7 @@
     },
     {
       "name" : "act_15",
-      "id" : 51,
+      "id" : 53,
       "runtime_data" : [],
       "primitives" : [
         {
@@ -3405,7 +3448,7 @@
           ],
           "source_info" : {
             "filename" : "include/control/next.p4",
-            "line" : 171,
+            "line" : 168,
             "column" : 20,
             "source_fragment" : "hdr.ipv4.ttl = hdr.ipv4.ttl - 1"
           }
@@ -3414,7 +3457,7 @@
     },
     {
       "name" : "act_16",
-      "id" : 52,
+      "id" : 54,
       "runtime_data" : [],
       "primitives" : [
         {
@@ -3472,7 +3515,7 @@
     },
     {
       "name" : "act_17",
-      "id" : 53,
+      "id" : 55,
       "runtime_data" : [],
       "primitives" : [
         {
@@ -3530,13 +3573,13 @@
     },
     {
       "name" : "nop",
-      "id" : 54,
+      "id" : 56,
       "runtime_data" : [],
       "primitives" : []
     },
     {
       "name" : "FabricEgress.spgw_egress.gtpu_encap",
-      "id" : 55,
+      "id" : 57,
       "runtime_data" : [],
       "primitives" : [
         {
@@ -4109,7 +4152,7 @@
     },
     {
       "name" : "FabricEgress.pkt_io_egress.pop_vlan",
-      "id" : 56,
+      "id" : 58,
       "runtime_data" : [],
       "primitives" : [
         {
@@ -4150,7 +4193,7 @@
     },
     {
       "name" : "FabricEgress.egress_next.pop_vlan",
-      "id" : 57,
+      "id" : 59,
       "runtime_data" : [],
       "primitives" : [
         {
@@ -4167,7 +4210,7 @@
           ],
           "source_info" : {
             "filename" : "include/control/next.p4",
-            "line" : 193,
+            "line" : 188,
             "column" : 8,
             "source_fragment" : "hdr.ethernet.ether_type = hdr.vlan_tag.ether_type"
           }
@@ -4182,7 +4225,7 @@
           ],
           "source_info" : {
             "filename" : "include/control/next.p4",
-            "line" : 194,
+            "line" : 189,
             "column" : 8,
             "source_fragment" : "hdr.vlan_tag.setInvalid()"
           }
@@ -4191,7 +4234,7 @@
     },
     {
       "name" : "act_18",
-      "id" : 58,
+      "id" : 60,
       "runtime_data" : [],
       "primitives" : [
         {
@@ -4232,7 +4275,7 @@
     },
     {
       "name" : "act_19",
-      "id" : 59,
+      "id" : 61,
       "runtime_data" : [],
       "primitives" : [
         {
@@ -4305,14 +4348,14 @@
           "with_counters" : false,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [35],
+          "action_ids" : [37],
           "actions" : ["act"],
           "base_default_next" : null,
           "next_tables" : {
             "act" : null
           },
           "default_entry" : {
-            "action_id" : 35,
+            "action_id" : 37,
             "action_const" : true,
             "action_data" : [],
             "action_entry_const" : true
@@ -4328,14 +4371,14 @@
           "with_counters" : false,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [43],
+          "action_ids" : [45],
           "actions" : ["act_7"],
           "base_default_next" : "node_5",
           "next_tables" : {
             "act_7" : "node_5"
           },
           "default_entry" : {
-            "action_id" : 43,
+            "action_id" : 45,
             "action_const" : true,
             "action_data" : [],
             "action_entry_const" : true
@@ -4351,14 +4394,14 @@
           "with_counters" : false,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [38],
+          "action_ids" : [40],
           "actions" : ["act_2"],
           "base_default_next" : "FabricIngress.spgw_ingress.s1u_filter_table",
           "next_tables" : {
             "act_2" : "FabricIngress.spgw_ingress.s1u_filter_table"
           },
           "default_entry" : {
-            "action_id" : 38,
+            "action_id" : 40,
             "action_const" : true,
             "action_data" : [],
             "action_entry_const" : true
@@ -4411,14 +4454,14 @@
           "with_counters" : false,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [36],
+          "action_ids" : [38],
           "actions" : ["act_0"],
           "base_default_next" : "node_10",
           "next_tables" : {
             "act_0" : "node_10"
           },
           "default_entry" : {
-            "action_id" : 36,
+            "action_id" : 38,
             "action_const" : true,
             "action_data" : [],
             "action_entry_const" : true
@@ -4434,14 +4477,14 @@
           "with_counters" : false,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [37],
+          "action_ids" : [39],
           "actions" : ["act_1"],
           "base_default_next" : "node_10",
           "next_tables" : {
             "act_1" : "node_10"
           },
           "default_entry" : {
-            "action_id" : 37,
+            "action_id" : 39,
             "action_const" : true,
             "action_data" : [],
             "action_entry_const" : true
@@ -4457,14 +4500,14 @@
           "with_counters" : false,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [39],
+          "action_ids" : [41],
           "actions" : ["act_3"],
           "base_default_next" : "node_17",
           "next_tables" : {
             "act_3" : "node_17"
           },
           "default_entry" : {
-            "action_id" : 39,
+            "action_id" : 41,
             "action_const" : true,
             "action_data" : [],
             "action_entry_const" : true
@@ -4517,14 +4560,14 @@
           "with_counters" : false,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [40],
+          "action_ids" : [42],
           "actions" : ["act_4"],
           "base_default_next" : "node_15",
           "next_tables" : {
             "act_4" : "node_15"
           },
           "default_entry" : {
-            "action_id" : 40,
+            "action_id" : 42,
             "action_const" : true,
             "action_data" : [],
             "action_entry_const" : true
@@ -4540,14 +4583,14 @@
           "with_counters" : false,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [41],
+          "action_ids" : [43],
           "actions" : ["act_5"],
           "base_default_next" : "node_15",
           "next_tables" : {
             "act_5" : "node_15"
           },
           "default_entry" : {
-            "action_id" : 41,
+            "action_id" : 43,
             "action_const" : true,
             "action_data" : [],
             "action_entry_const" : true
@@ -4563,14 +4606,14 @@
           "with_counters" : false,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [42],
+          "action_ids" : [44],
           "actions" : ["act_6"],
           "base_default_next" : "node_17",
           "next_tables" : {
             "act_6" : "node_17"
           },
           "default_entry" : {
-            "action_id" : 42,
+            "action_id" : 44,
             "action_const" : true,
             "action_data" : [],
             "action_entry_const" : true
@@ -4586,14 +4629,14 @@
           "with_counters" : false,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [44],
+          "action_ids" : [46],
           "actions" : ["act_8"],
           "base_default_next" : "node_19",
           "next_tables" : {
             "act_8" : "node_19"
           },
           "default_entry" : {
-            "action_id" : 44,
+            "action_id" : 46,
             "action_const" : true,
             "action_data" : [],
             "action_entry_const" : true
@@ -4609,14 +4652,14 @@
           "with_counters" : false,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [13],
+          "action_ids" : [14],
           "actions" : ["FabricIngress.spgw_ingress.gtpu_decap"],
           "base_default_next" : "node_22",
           "next_tables" : {
             "FabricIngress.spgw_ingress.gtpu_decap" : "node_22"
           },
           "default_entry" : {
-            "action_id" : 13,
+            "action_id" : 14,
             "action_const" : true,
             "action_data" : [],
             "action_entry_const" : true
@@ -4645,7 +4688,7 @@
           "with_counters" : false,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [14, 2],
+          "action_ids" : [15, 2],
           "actions" : ["FabricIngress.spgw_ingress.set_dl_sess_info", "NoAction"],
           "base_default_next" : null,
           "next_tables" : {
@@ -4669,14 +4712,14 @@
           "with_counters" : false,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [45],
+          "action_ids" : [47],
           "actions" : ["act_9"],
           "base_default_next" : "node_26",
           "next_tables" : {
             "act_9" : "node_26"
           },
           "default_entry" : {
-            "action_id" : 45,
+            "action_id" : 47,
             "action_const" : true,
             "action_data" : [],
             "action_entry_const" : true
@@ -4692,14 +4735,14 @@
           "with_counters" : false,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [46],
+          "action_ids" : [48],
           "actions" : ["act_10"],
           "base_default_next" : "node_26",
           "next_tables" : {
             "act_10" : "node_26"
           },
           "default_entry" : {
-            "action_id" : 46,
+            "action_id" : 48,
             "action_const" : true,
             "action_data" : [],
             "action_entry_const" : true
@@ -4715,14 +4758,14 @@
           "with_counters" : false,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [12],
+          "action_ids" : [13],
           "actions" : ["FabricIngress.spgw_ingress.drop_now"],
           "base_default_next" : "FabricIngress.spgw_ingress.ue_cdr_table",
           "next_tables" : {
             "FabricIngress.spgw_ingress.drop_now" : "FabricIngress.spgw_ingress.ue_cdr_table"
           },
           "default_entry" : {
-            "action_id" : 12,
+            "action_id" : 13,
             "action_const" : true,
             "action_data" : [],
             "action_entry_const" : true
@@ -4751,7 +4794,7 @@
           "with_counters" : true,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [15, 3],
+          "action_ids" : [16, 3],
           "actions" : ["FabricIngress.spgw_ingress.update_ue_cdr", "NoAction"],
           "base_default_next" : "tbl_act_11",
           "next_tables" : {
@@ -4775,14 +4818,14 @@
           "with_counters" : false,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [47],
+          "action_ids" : [49],
           "actions" : ["act_11"],
           "base_default_next" : "FabricIngress.filtering.ingress_port_vlan",
           "next_tables" : {
             "act_11" : "FabricIngress.filtering.ingress_port_vlan"
           },
           "default_entry" : {
-            "action_id" : 47,
+            "action_id" : 49,
             "action_const" : true,
             "action_data" : [],
             "action_entry_const" : true
@@ -4823,7 +4866,7 @@
           "with_counters" : true,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [18, 17, 9, 16],
+          "action_ids" : [19, 18, 10, 17],
           "actions" : ["FabricIngress.filtering.push_internal_vlan", "FabricIngress.filtering.set_vlan", "nop", "FabricIngress.filtering.drop"],
           "base_default_next" : "FabricIngress.filtering.fwd_classifier",
           "next_tables" : {
@@ -4833,7 +4876,7 @@
             "FabricIngress.filtering.drop" : "FabricIngress.filtering.fwd_classifier"
           },
           "default_entry" : {
-            "action_id" : 9,
+            "action_id" : 10,
             "action_const" : true,
             "action_data" : [],
             "action_entry_const" : true
@@ -4874,14 +4917,14 @@
           "with_counters" : true,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [19],
+          "action_ids" : [20],
           "actions" : ["FabricIngress.filtering.set_forwarding_type"],
           "base_default_next" : "node_32",
           "next_tables" : {
             "FabricIngress.filtering.set_forwarding_type" : "node_32"
           },
           "default_entry" : {
-            "action_id" : 19,
+            "action_id" : 20,
             "action_const" : true,
             "action_data" : ["0x0"],
             "action_entry_const" : true
@@ -4916,7 +4959,7 @@
           "with_counters" : true,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [21, 4],
+          "action_ids" : [22, 4],
           "actions" : ["FabricIngress.forwarding.set_next_id", "NoAction"],
           "base_default_next" : "FabricIngress.forwarding.acl",
           "next_tables" : {
@@ -4953,7 +4996,7 @@
           "with_counters" : true,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [24, 5],
+          "action_ids" : [25, 5],
           "actions" : ["FabricIngress.forwarding.pop_mpls_and_next", "NoAction"],
           "base_default_next" : "tbl_act_12",
           "next_tables" : {
@@ -4977,14 +5020,14 @@
           "with_counters" : false,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [48],
+          "action_ids" : [50],
           "actions" : ["act_12"],
           "base_default_next" : "FabricIngress.forwarding.acl",
           "next_tables" : {
             "act_12" : "FabricIngress.forwarding.acl"
           },
           "default_entry" : {
-            "action_id" : 48,
+            "action_id" : 50,
             "action_const" : true,
             "action_data" : [],
             "action_entry_const" : true
@@ -5013,7 +5056,7 @@
           "with_counters" : true,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [22, 6],
+          "action_ids" : [23, 6],
           "actions" : ["FabricIngress.forwarding.set_next_id", "NoAction"],
           "base_default_next" : "FabricIngress.forwarding.acl",
           "next_tables" : {
@@ -5116,7 +5159,7 @@
           "with_counters" : true,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [23, 25, 20, 10],
+          "action_ids" : [24, 26, 21, 11],
           "actions" : ["FabricIngress.forwarding.set_next_id", "FabricIngress.forwarding.duplicate_to_controller", "FabricIngress.forwarding.drop", "nop"],
           "base_default_next" : "FabricIngress.next.vlan_meta",
           "next_tables" : {
@@ -5126,7 +5169,7 @@
             "nop" : "FabricIngress.next.vlan_meta"
           },
           "default_entry" : {
-            "action_id" : 10,
+            "action_id" : 11,
             "action_const" : true,
             "action_data" : [],
             "action_entry_const" : true
@@ -5155,7 +5198,7 @@
           "with_counters" : true,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [27, 11],
+          "action_ids" : [28, 12],
           "actions" : ["FabricIngress.next.set_vlan", "nop"],
           "base_default_next" : "FabricIngress.next.simple",
           "next_tables" : {
@@ -5163,7 +5206,7 @@
             "nop" : "FabricIngress.next.simple"
           },
           "default_entry" : {
-            "action_id" : 11,
+            "action_id" : 12,
             "action_const" : false,
             "action_data" : [],
             "action_entry_const" : false
@@ -5192,7 +5235,7 @@
           "with_counters" : true,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [26, 28, 29, 32, 31, 7],
+          "action_ids" : [27, 29, 30, 33, 32, 7],
           "actions" : ["FabricIngress.next.output", "FabricIngress.next.set_vlan_output", "FabricIngress.next.l3_routing", "FabricIngress.next.mpls_routing_v4", "FabricIngress.next.l3_routing_vlan", "NoAction"],
           "base_default_next" : null,
           "next_tables" : {
@@ -5216,14 +5259,14 @@
           "with_counters" : false,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [49],
+          "action_ids" : [51],
           "actions" : ["act_13"],
           "base_default_next" : "node_44",
           "next_tables" : {
             "act_13" : "node_44"
           },
           "default_entry" : {
-            "action_id" : 49,
+            "action_id" : 51,
             "action_const" : true,
             "action_data" : [],
             "action_entry_const" : true
@@ -5239,14 +5282,14 @@
           "with_counters" : false,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [50],
+          "action_ids" : [52],
           "actions" : ["act_14"],
           "base_default_next" : "node_44",
           "next_tables" : {
             "act_14" : "node_44"
           },
           "default_entry" : {
-            "action_id" : 50,
+            "action_id" : 52,
             "action_const" : true,
             "action_data" : [],
             "action_entry_const" : true
@@ -5262,14 +5305,14 @@
           "with_counters" : false,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [51],
+          "action_ids" : [53],
           "actions" : ["act_15"],
           "base_default_next" : "FabricIngress.next.hashed",
           "next_tables" : {
             "act_15" : "FabricIngress.next.hashed"
           },
           "default_entry" : {
-            "action_id" : 51,
+            "action_id" : 53,
             "action_const" : true,
             "action_data" : [],
             "action_entry_const" : true
@@ -5299,41 +5342,55 @@
           "with_counters" : true,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [30, 33, 34, 8],
+          "action_ids" : [31, 34, 35, 8],
           "actions" : ["FabricIngress.next.l3_routing", "FabricIngress.next.mpls_routing_v4", "FabricIngress.next.mpls_routing_v6", "NoAction"],
-          "base_default_next" : "node_49",
+          "base_default_next" : "FabricIngress.next.multicast",
           "next_tables" : {
-            "FabricIngress.next.l3_routing" : "node_49",
-            "FabricIngress.next.mpls_routing_v4" : "node_49",
-            "FabricIngress.next.mpls_routing_v6" : "node_49",
-            "NoAction" : "node_49"
+            "FabricIngress.next.l3_routing" : "FabricIngress.next.multicast",
+            "FabricIngress.next.mpls_routing_v4" : "FabricIngress.next.multicast",
+            "FabricIngress.next.mpls_routing_v6" : "FabricIngress.next.multicast",
+            "NoAction" : "FabricIngress.next.multicast"
+          }
+        },
+        {
+          "name" : "FabricIngress.next.multicast",
+          "id" : 32,
+          "source_info" : {
+            "filename" : "include/control/next.p4",
+            "line" : 153,
+            "column" : 10,
+            "source_fragment" : "multicast"
+          },
+          "key" : [
+            {
+              "match_type" : "exact",
+              "name" : "fabric_metadata.next_id",
+              "target" : ["scalars", "fabric_metadata_t.next_id"],
+              "mask" : null
+            }
+          ],
+          "match_type" : "exact",
+          "type" : "simple",
+          "max_size" : 1024,
+          "with_counters" : true,
+          "support_timeout" : false,
+          "direct_meters" : null,
+          "action_ids" : [36, 9],
+          "actions" : ["FabricIngress.next.set_mcast_group", "NoAction"],
+          "base_default_next" : "node_50",
+          "next_tables" : {
+            "FabricIngress.next.set_mcast_group" : "node_50",
+            "NoAction" : "node_50"
+          },
+          "default_entry" : {
+            "action_id" : 9,
+            "action_const" : false,
+            "action_data" : [],
+            "action_entry_const" : false
           }
         },
         {
           "name" : "tbl_act_16",
-          "id" : 32,
-          "key" : [],
-          "match_type" : "exact",
-          "type" : "simple",
-          "max_size" : 1024,
-          "with_counters" : false,
-          "support_timeout" : false,
-          "direct_meters" : null,
-          "action_ids" : [52],
-          "actions" : ["act_16"],
-          "base_default_next" : "node_51",
-          "next_tables" : {
-            "act_16" : "node_51"
-          },
-          "default_entry" : {
-            "action_id" : 52,
-            "action_const" : true,
-            "action_data" : [],
-            "action_entry_const" : true
-          }
-        },
-        {
-          "name" : "tbl_act_17",
           "id" : 33,
           "key" : [],
           "match_type" : "exact",
@@ -5342,14 +5399,37 @@
           "with_counters" : false,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [53],
+          "action_ids" : [54],
+          "actions" : ["act_16"],
+          "base_default_next" : "node_52",
+          "next_tables" : {
+            "act_16" : "node_52"
+          },
+          "default_entry" : {
+            "action_id" : 54,
+            "action_const" : true,
+            "action_data" : [],
+            "action_entry_const" : true
+          }
+        },
+        {
+          "name" : "tbl_act_17",
+          "id" : 34,
+          "key" : [],
+          "match_type" : "exact",
+          "type" : "simple",
+          "max_size" : 1024,
+          "with_counters" : false,
+          "support_timeout" : false,
+          "direct_meters" : null,
+          "action_ids" : [55],
           "actions" : ["act_17"],
           "base_default_next" : null,
           "next_tables" : {
             "act_17" : null
           },
           "default_entry" : {
-            "action_id" : 53,
+            "action_id" : 55,
             "action_const" : true,
             "action_data" : [],
             "action_entry_const" : true
@@ -5476,7 +5556,7 @@
             "filename" : "include/spgw.p4",
             "line" : 167,
             "column" : 12,
-            "source_fragment" : "spgw_meta.do_spgw == true"
+            "source_fragment" : "spgw_meta.do_spgw == false"
           },
           "expression" : {
             "type" : "expression",
@@ -5495,7 +5575,7 @@
               },
               "right" : {
                 "type" : "bool",
-                "value" : true
+                "value" : false
               }
             }
           },
@@ -5708,7 +5788,7 @@
           "id" : 13,
           "source_info" : {
             "filename" : "include/control/next.p4",
-            "line" : 169,
+            "line" : 166,
             "column" : 16,
             "source_fragment" : "!hdr.mpls.isValid()"
           },
@@ -5738,7 +5818,7 @@
           "id" : 14,
           "source_info" : {
             "filename" : "include/control/next.p4",
-            "line" : 170,
+            "line" : 167,
             "column" : 19,
             "source_fragment" : "hdr.ipv4.isValid()"
           },
@@ -5757,7 +5837,7 @@
           "false_next" : "FabricIngress.next.hashed"
         },
         {
-          "name" : "node_49",
+          "name" : "node_50",
           "id" : 15,
           "source_info" : {
             "filename" : "include/control/port_counter.p4",
@@ -5780,10 +5860,10 @@
             }
           },
           "true_next" : "tbl_act_16",
-          "false_next" : "node_51"
+          "false_next" : "node_52"
         },
         {
-          "name" : "node_51",
+          "name" : "node_52",
           "id" : 16,
           "source_info" : {
             "filename" : "include/control/port_counter.p4",
@@ -5823,10 +5903,10 @@
       "tables" : [
         {
           "name" : "FabricEgress.egress_next.egress_vlan",
-          "id" : 34,
+          "id" : 35,
           "source_info" : {
             "filename" : "include/control/next.p4",
-            "line" : 197,
+            "line" : 192,
             "column" : 10,
             "source_fragment" : "egress_vlan"
           },
@@ -5850,15 +5930,15 @@
           "with_counters" : false,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [57, 54],
+          "action_ids" : [59, 56],
           "actions" : ["FabricEgress.egress_next.pop_vlan", "nop"],
-          "base_default_next" : "node_56",
+          "base_default_next" : "node_57",
           "next_tables" : {
-            "FabricEgress.egress_next.pop_vlan" : "node_56",
-            "nop" : "node_56"
+            "FabricEgress.egress_next.pop_vlan" : "node_57",
+            "nop" : "node_57"
           },
           "default_entry" : {
-            "action_id" : 54,
+            "action_id" : 56,
             "action_const" : false,
             "action_data" : [],
             "action_entry_const" : false
@@ -5866,29 +5946,6 @@
         },
         {
           "name" : "tbl_pkt_io_egress_pop_vlan",
-          "id" : 35,
-          "key" : [],
-          "match_type" : "exact",
-          "type" : "simple",
-          "max_size" : 1024,
-          "with_counters" : false,
-          "support_timeout" : false,
-          "direct_meters" : null,
-          "action_ids" : [56],
-          "actions" : ["FabricEgress.pkt_io_egress.pop_vlan"],
-          "base_default_next" : "tbl_act_18",
-          "next_tables" : {
-            "FabricEgress.pkt_io_egress.pop_vlan" : "tbl_act_18"
-          },
-          "default_entry" : {
-            "action_id" : 56,
-            "action_const" : true,
-            "action_data" : [],
-            "action_entry_const" : true
-          }
-        },
-        {
-          "name" : "tbl_act_18",
           "id" : 36,
           "key" : [],
           "match_type" : "exact",
@@ -5898,10 +5955,10 @@
           "support_timeout" : false,
           "direct_meters" : null,
           "action_ids" : [58],
-          "actions" : ["act_18"],
-          "base_default_next" : "tbl_act_19",
+          "actions" : ["FabricEgress.pkt_io_egress.pop_vlan"],
+          "base_default_next" : "tbl_act_18",
           "next_tables" : {
-            "act_18" : "tbl_act_19"
+            "FabricEgress.pkt_io_egress.pop_vlan" : "tbl_act_18"
           },
           "default_entry" : {
             "action_id" : 58,
@@ -5911,7 +5968,7 @@
           }
         },
         {
-          "name" : "tbl_act_19",
+          "name" : "tbl_act_18",
           "id" : 37,
           "key" : [],
           "match_type" : "exact",
@@ -5920,21 +5977,21 @@
           "with_counters" : false,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [59],
-          "actions" : ["act_19"],
-          "base_default_next" : "node_61",
+          "action_ids" : [60],
+          "actions" : ["act_18"],
+          "base_default_next" : "tbl_act_19",
           "next_tables" : {
-            "act_19" : "node_61"
+            "act_18" : "tbl_act_19"
           },
           "default_entry" : {
-            "action_id" : 59,
+            "action_id" : 60,
             "action_const" : true,
             "action_data" : [],
             "action_entry_const" : true
           }
         },
         {
-          "name" : "tbl_spgw_egress_gtpu_encap",
+          "name" : "tbl_act_19",
           "id" : 38,
           "key" : [],
           "match_type" : "exact",
@@ -5943,14 +6000,37 @@
           "with_counters" : false,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [55],
+          "action_ids" : [61],
+          "actions" : ["act_19"],
+          "base_default_next" : "node_62",
+          "next_tables" : {
+            "act_19" : "node_62"
+          },
+          "default_entry" : {
+            "action_id" : 61,
+            "action_const" : true,
+            "action_data" : [],
+            "action_entry_const" : true
+          }
+        },
+        {
+          "name" : "tbl_spgw_egress_gtpu_encap",
+          "id" : 39,
+          "key" : [],
+          "match_type" : "exact",
+          "type" : "simple",
+          "max_size" : 1024,
+          "with_counters" : false,
+          "support_timeout" : false,
+          "direct_meters" : null,
+          "action_ids" : [57],
           "actions" : ["FabricEgress.spgw_egress.gtpu_encap"],
           "base_default_next" : null,
           "next_tables" : {
             "FabricEgress.spgw_egress.gtpu_encap" : null
           },
           "default_entry" : {
-            "action_id" : 55,
+            "action_id" : 57,
             "action_const" : true,
             "action_data" : [],
             "action_entry_const" : true
@@ -5960,7 +6040,7 @@
       "action_profiles" : [],
       "conditionals" : [
         {
-          "name" : "node_56",
+          "name" : "node_57",
           "id" : 17,
           "source_info" : {
             "filename" : "include/control/packetio.p4",
@@ -5982,11 +6062,11 @@
               }
             }
           },
-          "true_next" : "node_57",
+          "true_next" : "node_58",
           "false_next" : "tbl_act_19"
         },
         {
-          "name" : "node_57",
+          "name" : "node_58",
           "id" : 18,
           "source_info" : {
             "filename" : "include/control/packetio.p4",
@@ -6036,7 +6116,7 @@
           "false_next" : "tbl_act_18"
         },
         {
-          "name" : "node_61",
+          "name" : "node_62",
           "id" : 19,
           "source_info" : {
             "filename" : "include/spgw.p4",
diff --git a/pipelines/fabric/src/main/resources/p4c-out/fabric-spgw/bmv2/default/p4info.txt b/pipelines/fabric/src/main/resources/p4c-out/fabric-spgw/bmv2/default/p4info.txt
index 7be8a3f..3b7c27c 100644
--- a/pipelines/fabric/src/main/resources/p4c-out/fabric-spgw/bmv2/default/p4info.txt
+++ b/pipelines/fabric/src/main/resources/p4c-out/fabric-spgw/bmv2/default/p4info.txt
@@ -411,6 +411,29 @@
 }
 tables {
   preamble {
+    id: 33606828
+    name: "FabricIngress.next.multicast"
+    alias: "multicast"
+  }
+  match_fields {
+    id: 1
+    name: "fabric_metadata.next_id"
+    bitwidth: 32
+    match_type: EXACT
+  }
+  action_refs {
+    id: 16789575
+  }
+  action_refs {
+    id: 16800567
+    annotations: "@defaultonly()"
+  }
+  direct_resource_ids: 318801752
+  size: 1024
+  idle_timeout_behavior: NO_TIMEOUT
+}
+tables {
+  preamble {
     id: 33599342
     name: "FabricEgress.egress_next.egress_vlan"
     alias: "egress_vlan"
@@ -720,6 +743,18 @@
 }
 actions {
   preamble {
+    id: 16789575
+    name: "FabricIngress.next.set_mcast_group"
+    alias: "set_mcast_group"
+  }
+  params {
+    id: 1
+    name: "gid"
+    bitwidth: 16
+  }
+}
+actions {
+  preamble {
     id: 16829135
     name: "FabricEgress.spgw_egress.gtpu_encap"
     alias: "gtpu_encap"
@@ -881,6 +916,17 @@
   }
   direct_table_id: 33608588
 }
+direct_counters {
+  preamble {
+    id: 318801752
+    name: "FabricIngress.next.multicast_counter"
+    alias: "multicast_counter"
+  }
+  spec {
+    unit: BOTH
+  }
+  direct_table_id: 33606828
+}
 controller_packet_metadata {
   preamble {
     id: 67146229
diff --git a/pipelines/fabric/src/main/resources/p4c-out/fabric/bmv2/default/bmv2.json b/pipelines/fabric/src/main/resources/p4c-out/fabric/bmv2/default/bmv2.json
index 52fab79..53a7735 100644
--- a/pipelines/fabric/src/main/resources/p4c-out/fabric/bmv2/default/bmv2.json
+++ b/pipelines/fabric/src/main/resources/p4c-out/fabric/bmv2/default/bmv2.json
@@ -753,8 +753,14 @@
       "binding" : "FabricIngress.next.hashed"
     },
     {
-      "name" : "FabricIngress.port_counters_control.egress_port_counter",
+      "name" : "FabricIngress.next.multicast_counter",
       "id" : 9,
+      "is_direct" : true,
+      "binding" : "FabricIngress.next.multicast"
+    },
+    {
+      "name" : "FabricIngress.port_counters_control.egress_port_counter",
+      "id" : 10,
       "source_info" : {
         "filename" : "include/control/port_counter.p4",
         "line" : 23,
@@ -766,7 +772,7 @@
     },
     {
       "name" : "FabricIngress.port_counters_control.ingress_port_counter",
-      "id" : 10,
+      "id" : 11,
       "source_info" : {
         "filename" : "include/control/port_counter.p4",
         "line" : 24,
@@ -945,9 +951,15 @@
       "primitives" : []
     },
     {
-      "name" : "FabricIngress.filtering.drop",
+      "name" : "NoAction",
       "id" : 8,
       "runtime_data" : [],
+      "primitives" : []
+    },
+    {
+      "name" : "FabricIngress.filtering.drop",
+      "id" : 9,
+      "runtime_data" : [],
       "primitives" : [
         {
           "op" : "drop",
@@ -963,7 +975,7 @@
     },
     {
       "name" : "FabricIngress.filtering.set_vlan",
-      "id" : 9,
+      "id" : 10,
       "runtime_data" : [
         {
           "name" : "new_vlan_id",
@@ -994,7 +1006,7 @@
     },
     {
       "name" : "FabricIngress.filtering.push_internal_vlan",
-      "id" : 10,
+      "id" : 11,
       "runtime_data" : [
         {
           "name" : "new_vlan_id",
@@ -1145,7 +1157,7 @@
     },
     {
       "name" : "FabricIngress.filtering.set_forwarding_type",
-      "id" : 11,
+      "id" : 12,
       "runtime_data" : [
         {
           "name" : "fwd_type",
@@ -1176,7 +1188,7 @@
     },
     {
       "name" : "FabricIngress.forwarding.drop",
-      "id" : 12,
+      "id" : 13,
       "runtime_data" : [],
       "primitives" : [
         {
@@ -1193,37 +1205,6 @@
     },
     {
       "name" : "FabricIngress.forwarding.set_next_id",
-      "id" : 13,
-      "runtime_data" : [
-        {
-          "name" : "next_id",
-          "bitwidth" : 32
-        }
-      ],
-      "primitives" : [
-        {
-          "op" : "assign",
-          "parameters" : [
-            {
-              "type" : "field",
-              "value" : ["scalars", "fabric_metadata_t.next_id"]
-            },
-            {
-              "type" : "runtime_data",
-              "value" : 0
-            }
-          ],
-          "source_info" : {
-            "filename" : "include/control/forwarding.p4",
-            "line" : 40,
-            "column" : 8,
-            "source_fragment" : "fabric_metadata.next_id = next_id"
-          }
-        }
-      ]
-    },
-    {
-      "name" : "FabricIngress.forwarding.set_next_id",
       "id" : 14,
       "runtime_data" : [
         {
@@ -1285,7 +1266,7 @@
       ]
     },
     {
-      "name" : "FabricIngress.forwarding.pop_mpls_and_next",
+      "name" : "FabricIngress.forwarding.set_next_id",
       "id" : 16,
       "runtime_data" : [
         {
@@ -1295,6 +1276,37 @@
       ],
       "primitives" : [
         {
+          "op" : "assign",
+          "parameters" : [
+            {
+              "type" : "field",
+              "value" : ["scalars", "fabric_metadata_t.next_id"]
+            },
+            {
+              "type" : "runtime_data",
+              "value" : 0
+            }
+          ],
+          "source_info" : {
+            "filename" : "include/control/forwarding.p4",
+            "line" : 40,
+            "column" : 8,
+            "source_fragment" : "fabric_metadata.next_id = next_id"
+          }
+        }
+      ]
+    },
+    {
+      "name" : "FabricIngress.forwarding.pop_mpls_and_next",
+      "id" : 17,
+      "runtime_data" : [
+        {
+          "name" : "next_id",
+          "bitwidth" : 32
+        }
+      ],
+      "primitives" : [
+        {
           "op" : "remove_header",
           "parameters" : [
             {
@@ -1332,7 +1344,7 @@
     },
     {
       "name" : "FabricIngress.forwarding.duplicate_to_controller",
-      "id" : 17,
+      "id" : 18,
       "runtime_data" : [],
       "primitives" : [
         {
@@ -1358,7 +1370,7 @@
     },
     {
       "name" : "FabricIngress.next.output",
-      "id" : 18,
+      "id" : 19,
       "runtime_data" : [
         {
           "name" : "port_num",
@@ -1389,7 +1401,7 @@
     },
     {
       "name" : "FabricIngress.next.set_vlan",
-      "id" : 19,
+      "id" : 20,
       "runtime_data" : [
         {
           "name" : "new_vlan_id",
@@ -1420,7 +1432,7 @@
     },
     {
       "name" : "FabricIngress.next.set_vlan_output",
-      "id" : 20,
+      "id" : 21,
       "runtime_data" : [
         {
           "name" : "new_vlan_id",
@@ -1474,83 +1486,6 @@
     },
     {
       "name" : "FabricIngress.next.l3_routing",
-      "id" : 21,
-      "runtime_data" : [
-        {
-          "name" : "port_num",
-          "bitwidth" : 9
-        },
-        {
-          "name" : "smac",
-          "bitwidth" : 48
-        },
-        {
-          "name" : "dmac",
-          "bitwidth" : 48
-        }
-      ],
-      "primitives" : [
-        {
-          "op" : "assign",
-          "parameters" : [
-            {
-              "type" : "field",
-              "value" : ["ethernet", "src_addr"]
-            },
-            {
-              "type" : "runtime_data",
-              "value" : 1
-            }
-          ],
-          "source_info" : {
-            "filename" : "include/control/next.p4",
-            "line" : 51,
-            "column" : 8,
-            "source_fragment" : "hdr.ethernet.src_addr = smac; ..."
-          }
-        },
-        {
-          "op" : "assign",
-          "parameters" : [
-            {
-              "type" : "field",
-              "value" : ["ethernet", "dst_addr"]
-            },
-            {
-              "type" : "runtime_data",
-              "value" : 2
-            }
-          ],
-          "source_info" : {
-            "filename" : "include/control/next.p4",
-            "line" : 55,
-            "column" : 8,
-            "source_fragment" : "hdr.ethernet.dst_addr = dmac; ..."
-          }
-        },
-        {
-          "op" : "assign",
-          "parameters" : [
-            {
-              "type" : "field",
-              "value" : ["standard_metadata", "egress_spec"]
-            },
-            {
-              "type" : "runtime_data",
-              "value" : 0
-            }
-          ],
-          "source_info" : {
-            "filename" : "include/control/next.p4",
-            "line" : 33,
-            "column" : 8,
-            "source_fragment" : "standard_metadata.egress_spec = port_num; ..."
-          }
-        }
-      ]
-    },
-    {
-      "name" : "FabricIngress.next.l3_routing",
       "id" : 22,
       "runtime_data" : [
         {
@@ -1627,7 +1562,7 @@
       ]
     },
     {
-      "name" : "FabricIngress.next.l3_routing_vlan",
+      "name" : "FabricIngress.next.l3_routing",
       "id" : 23,
       "runtime_data" : [
         {
@@ -1641,6 +1576,83 @@
         {
           "name" : "dmac",
           "bitwidth" : 48
+        }
+      ],
+      "primitives" : [
+        {
+          "op" : "assign",
+          "parameters" : [
+            {
+              "type" : "field",
+              "value" : ["ethernet", "src_addr"]
+            },
+            {
+              "type" : "runtime_data",
+              "value" : 1
+            }
+          ],
+          "source_info" : {
+            "filename" : "include/control/next.p4",
+            "line" : 51,
+            "column" : 8,
+            "source_fragment" : "hdr.ethernet.src_addr = smac; ..."
+          }
+        },
+        {
+          "op" : "assign",
+          "parameters" : [
+            {
+              "type" : "field",
+              "value" : ["ethernet", "dst_addr"]
+            },
+            {
+              "type" : "runtime_data",
+              "value" : 2
+            }
+          ],
+          "source_info" : {
+            "filename" : "include/control/next.p4",
+            "line" : 55,
+            "column" : 8,
+            "source_fragment" : "hdr.ethernet.dst_addr = dmac; ..."
+          }
+        },
+        {
+          "op" : "assign",
+          "parameters" : [
+            {
+              "type" : "field",
+              "value" : ["standard_metadata", "egress_spec"]
+            },
+            {
+              "type" : "runtime_data",
+              "value" : 0
+            }
+          ],
+          "source_info" : {
+            "filename" : "include/control/next.p4",
+            "line" : 33,
+            "column" : 8,
+            "source_fragment" : "standard_metadata.egress_spec = port_num; ..."
+          }
+        }
+      ]
+    },
+    {
+      "name" : "FabricIngress.next.l3_routing_vlan",
+      "id" : 24,
+      "runtime_data" : [
+        {
+          "name" : "port_num",
+          "bitwidth" : 9
+        },
+        {
+          "name" : "smac",
+          "bitwidth" : 48
+        },
+        {
+          "name" : "dmac",
+          "bitwidth" : 48
         },
         {
           "name" : "new_vlan_id",
@@ -1728,197 +1740,6 @@
     },
     {
       "name" : "FabricIngress.next.mpls_routing_v4",
-      "id" : 24,
-      "runtime_data" : [
-        {
-          "name" : "port_num",
-          "bitwidth" : 9
-        },
-        {
-          "name" : "smac",
-          "bitwidth" : 48
-        },
-        {
-          "name" : "dmac",
-          "bitwidth" : 48
-        },
-        {
-          "name" : "label",
-          "bitwidth" : 20
-        }
-      ],
-      "primitives" : [
-        {
-          "op" : "assign",
-          "parameters" : [
-            {
-              "type" : "field",
-              "value" : ["ethernet", "src_addr"]
-            },
-            {
-              "type" : "runtime_data",
-              "value" : 1
-            }
-          ],
-          "source_info" : {
-            "filename" : "include/control/next.p4",
-            "line" : 51,
-            "column" : 8,
-            "source_fragment" : "hdr.ethernet.src_addr = smac; ..."
-          }
-        },
-        {
-          "op" : "assign",
-          "parameters" : [
-            {
-              "type" : "field",
-              "value" : ["ethernet", "dst_addr"]
-            },
-            {
-              "type" : "runtime_data",
-              "value" : 2
-            }
-          ],
-          "source_info" : {
-            "filename" : "include/control/next.p4",
-            "line" : 55,
-            "column" : 8,
-            "source_fragment" : "hdr.ethernet.dst_addr = dmac; ..."
-          }
-        },
-        {
-          "op" : "assign",
-          "parameters" : [
-            {
-              "type" : "field",
-              "value" : ["standard_metadata", "egress_spec"]
-            },
-            {
-              "type" : "runtime_data",
-              "value" : 0
-            }
-          ],
-          "source_info" : {
-            "filename" : "include/control/next.p4",
-            "line" : 33,
-            "column" : 8,
-            "source_fragment" : "standard_metadata.egress_spec = port_num; ..."
-          }
-        },
-        {
-          "op" : "add_header",
-          "parameters" : [
-            {
-              "type" : "header",
-              "value" : "mpls"
-            }
-          ],
-          "source_info" : {
-            "filename" : "include/control/next.p4",
-            "line" : 72,
-            "column" : 8,
-            "source_fragment" : "hdr.mpls.setValid()"
-          }
-        },
-        {
-          "op" : "assign",
-          "parameters" : [
-            {
-              "type" : "field",
-              "value" : ["vlan_tag", "ether_type"]
-            },
-            {
-              "type" : "hexstr",
-              "value" : "0x8847"
-            }
-          ],
-          "source_info" : {
-            "filename" : "include/control/../define.p4",
-            "line" : 67,
-            "column" : 31,
-            "source_fragment" : "0x8847; ..."
-          }
-        },
-        {
-          "op" : "assign",
-          "parameters" : [
-            {
-              "type" : "field",
-              "value" : ["mpls", "label"]
-            },
-            {
-              "type" : "runtime_data",
-              "value" : 3
-            }
-          ],
-          "source_info" : {
-            "filename" : "include/control/next.p4",
-            "line" : 74,
-            "column" : 8,
-            "source_fragment" : "hdr.mpls.label = label; ..."
-          }
-        },
-        {
-          "op" : "assign",
-          "parameters" : [
-            {
-              "type" : "field",
-              "value" : ["mpls", "tc"]
-            },
-            {
-              "type" : "hexstr",
-              "value" : "0x00"
-            }
-          ],
-          "source_info" : {
-            "filename" : "include/control/next.p4",
-            "line" : 75,
-            "column" : 8,
-            "source_fragment" : "hdr.mpls.tc = tc; ..."
-          }
-        },
-        {
-          "op" : "assign",
-          "parameters" : [
-            {
-              "type" : "field",
-              "value" : ["mpls", "bos"]
-            },
-            {
-              "type" : "hexstr",
-              "value" : "0x01"
-            }
-          ],
-          "source_info" : {
-            "filename" : "include/control/next.p4",
-            "line" : 76,
-            "column" : 8,
-            "source_fragment" : "hdr.mpls.bos = 1w1"
-          }
-        },
-        {
-          "op" : "assign",
-          "parameters" : [
-            {
-              "type" : "field",
-              "value" : ["mpls", "ttl"]
-            },
-            {
-              "type" : "hexstr",
-              "value" : "0x40"
-            }
-          ],
-          "source_info" : {
-            "filename" : "include/control/../define.p4",
-            "line" : 87,
-            "column" : 32,
-            "source_fragment" : "64; ..."
-          }
-        }
-      ]
-    },
-    {
-      "name" : "FabricIngress.next.mpls_routing_v4",
       "id" : 25,
       "runtime_data" : [
         {
@@ -2109,7 +1930,7 @@
       ]
     },
     {
-      "name" : "FabricIngress.next.mpls_routing_v6",
+      "name" : "FabricIngress.next.mpls_routing_v4",
       "id" : 26,
       "runtime_data" : [
         {
@@ -2300,8 +2121,230 @@
       ]
     },
     {
-      "name" : "act",
+      "name" : "FabricIngress.next.mpls_routing_v6",
       "id" : 27,
+      "runtime_data" : [
+        {
+          "name" : "port_num",
+          "bitwidth" : 9
+        },
+        {
+          "name" : "smac",
+          "bitwidth" : 48
+        },
+        {
+          "name" : "dmac",
+          "bitwidth" : 48
+        },
+        {
+          "name" : "label",
+          "bitwidth" : 20
+        }
+      ],
+      "primitives" : [
+        {
+          "op" : "assign",
+          "parameters" : [
+            {
+              "type" : "field",
+              "value" : ["ethernet", "src_addr"]
+            },
+            {
+              "type" : "runtime_data",
+              "value" : 1
+            }
+          ],
+          "source_info" : {
+            "filename" : "include/control/next.p4",
+            "line" : 51,
+            "column" : 8,
+            "source_fragment" : "hdr.ethernet.src_addr = smac; ..."
+          }
+        },
+        {
+          "op" : "assign",
+          "parameters" : [
+            {
+              "type" : "field",
+              "value" : ["ethernet", "dst_addr"]
+            },
+            {
+              "type" : "runtime_data",
+              "value" : 2
+            }
+          ],
+          "source_info" : {
+            "filename" : "include/control/next.p4",
+            "line" : 55,
+            "column" : 8,
+            "source_fragment" : "hdr.ethernet.dst_addr = dmac; ..."
+          }
+        },
+        {
+          "op" : "assign",
+          "parameters" : [
+            {
+              "type" : "field",
+              "value" : ["standard_metadata", "egress_spec"]
+            },
+            {
+              "type" : "runtime_data",
+              "value" : 0
+            }
+          ],
+          "source_info" : {
+            "filename" : "include/control/next.p4",
+            "line" : 33,
+            "column" : 8,
+            "source_fragment" : "standard_metadata.egress_spec = port_num; ..."
+          }
+        },
+        {
+          "op" : "add_header",
+          "parameters" : [
+            {
+              "type" : "header",
+              "value" : "mpls"
+            }
+          ],
+          "source_info" : {
+            "filename" : "include/control/next.p4",
+            "line" : 72,
+            "column" : 8,
+            "source_fragment" : "hdr.mpls.setValid()"
+          }
+        },
+        {
+          "op" : "assign",
+          "parameters" : [
+            {
+              "type" : "field",
+              "value" : ["vlan_tag", "ether_type"]
+            },
+            {
+              "type" : "hexstr",
+              "value" : "0x8847"
+            }
+          ],
+          "source_info" : {
+            "filename" : "include/control/../define.p4",
+            "line" : 67,
+            "column" : 31,
+            "source_fragment" : "0x8847; ..."
+          }
+        },
+        {
+          "op" : "assign",
+          "parameters" : [
+            {
+              "type" : "field",
+              "value" : ["mpls", "label"]
+            },
+            {
+              "type" : "runtime_data",
+              "value" : 3
+            }
+          ],
+          "source_info" : {
+            "filename" : "include/control/next.p4",
+            "line" : 74,
+            "column" : 8,
+            "source_fragment" : "hdr.mpls.label = label; ..."
+          }
+        },
+        {
+          "op" : "assign",
+          "parameters" : [
+            {
+              "type" : "field",
+              "value" : ["mpls", "tc"]
+            },
+            {
+              "type" : "hexstr",
+              "value" : "0x00"
+            }
+          ],
+          "source_info" : {
+            "filename" : "include/control/next.p4",
+            "line" : 75,
+            "column" : 8,
+            "source_fragment" : "hdr.mpls.tc = tc; ..."
+          }
+        },
+        {
+          "op" : "assign",
+          "parameters" : [
+            {
+              "type" : "field",
+              "value" : ["mpls", "bos"]
+            },
+            {
+              "type" : "hexstr",
+              "value" : "0x01"
+            }
+          ],
+          "source_info" : {
+            "filename" : "include/control/next.p4",
+            "line" : 76,
+            "column" : 8,
+            "source_fragment" : "hdr.mpls.bos = 1w1"
+          }
+        },
+        {
+          "op" : "assign",
+          "parameters" : [
+            {
+              "type" : "field",
+              "value" : ["mpls", "ttl"]
+            },
+            {
+              "type" : "hexstr",
+              "value" : "0x40"
+            }
+          ],
+          "source_info" : {
+            "filename" : "include/control/../define.p4",
+            "line" : 87,
+            "column" : 32,
+            "source_fragment" : "64; ..."
+          }
+        }
+      ]
+    },
+    {
+      "name" : "FabricIngress.next.set_mcast_group",
+      "id" : 28,
+      "runtime_data" : [
+        {
+          "name" : "gid",
+          "bitwidth" : 16
+        }
+      ],
+      "primitives" : [
+        {
+          "op" : "assign",
+          "parameters" : [
+            {
+              "type" : "field",
+              "value" : ["standard_metadata", "mcast_grp"]
+            },
+            {
+              "type" : "runtime_data",
+              "value" : 0
+            }
+          ],
+          "source_info" : {
+            "filename" : "include/control/next.p4",
+            "line" : 148,
+            "column" : 8,
+            "source_fragment" : "standard_metadata.mcast_grp = gid"
+          }
+        }
+      ]
+    },
+    {
+      "name" : "act",
+      "id" : 29,
       "runtime_data" : [],
       "primitives" : [
         {
@@ -2342,7 +2385,7 @@
     },
     {
       "name" : "act_0",
-      "id" : 28,
+      "id" : 30,
       "runtime_data" : [],
       "primitives" : [
         {
@@ -2387,7 +2430,7 @@
     },
     {
       "name" : "act_1",
-      "id" : 29,
+      "id" : 31,
       "runtime_data" : [],
       "primitives" : [
         {
@@ -2417,7 +2460,7 @@
     },
     {
       "name" : "act_2",
-      "id" : 30,
+      "id" : 32,
       "runtime_data" : [],
       "primitives" : [
         {
@@ -2447,7 +2490,7 @@
     },
     {
       "name" : "act_3",
-      "id" : 31,
+      "id" : 33,
       "runtime_data" : [],
       "primitives" : [
         {
@@ -2487,7 +2530,7 @@
           ],
           "source_info" : {
             "filename" : "include/control/next.p4",
-            "line" : 171,
+            "line" : 168,
             "column" : 20,
             "source_fragment" : "hdr.ipv4.ttl = hdr.ipv4.ttl - 1"
           }
@@ -2496,7 +2539,7 @@
     },
     {
       "name" : "act_4",
-      "id" : 32,
+      "id" : 34,
       "runtime_data" : [],
       "primitives" : [
         {
@@ -2554,7 +2597,7 @@
     },
     {
       "name" : "act_5",
-      "id" : 33,
+      "id" : 35,
       "runtime_data" : [],
       "primitives" : [
         {
@@ -2612,13 +2655,13 @@
     },
     {
       "name" : "nop",
-      "id" : 34,
+      "id" : 36,
       "runtime_data" : [],
       "primitives" : []
     },
     {
       "name" : "FabricEgress.pkt_io_egress.pop_vlan",
-      "id" : 35,
+      "id" : 37,
       "runtime_data" : [],
       "primitives" : [
         {
@@ -2659,7 +2702,7 @@
     },
     {
       "name" : "FabricEgress.egress_next.pop_vlan",
-      "id" : 36,
+      "id" : 38,
       "runtime_data" : [],
       "primitives" : [
         {
@@ -2676,7 +2719,7 @@
           ],
           "source_info" : {
             "filename" : "include/control/next.p4",
-            "line" : 193,
+            "line" : 188,
             "column" : 8,
             "source_fragment" : "hdr.ethernet.ether_type = hdr.vlan_tag.ether_type"
           }
@@ -2691,7 +2734,7 @@
           ],
           "source_info" : {
             "filename" : "include/control/next.p4",
-            "line" : 194,
+            "line" : 189,
             "column" : 8,
             "source_fragment" : "hdr.vlan_tag.setInvalid()"
           }
@@ -2700,7 +2743,7 @@
     },
     {
       "name" : "act_6",
-      "id" : 37,
+      "id" : 39,
       "runtime_data" : [],
       "primitives" : [
         {
@@ -2762,14 +2805,14 @@
           "with_counters" : false,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [27],
+          "action_ids" : [29],
           "actions" : ["act"],
           "base_default_next" : null,
           "next_tables" : {
             "act" : null
           },
           "default_entry" : {
-            "action_id" : 27,
+            "action_id" : 29,
             "action_const" : true,
             "action_data" : [],
             "action_entry_const" : true
@@ -2810,7 +2853,7 @@
           "with_counters" : true,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [10, 9, 0, 8],
+          "action_ids" : [11, 10, 0, 9],
           "actions" : ["FabricIngress.filtering.push_internal_vlan", "FabricIngress.filtering.set_vlan", "nop", "FabricIngress.filtering.drop"],
           "base_default_next" : "FabricIngress.filtering.fwd_classifier",
           "next_tables" : {
@@ -2861,14 +2904,14 @@
           "with_counters" : true,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [11],
+          "action_ids" : [12],
           "actions" : ["FabricIngress.filtering.set_forwarding_type"],
           "base_default_next" : "node_6",
           "next_tables" : {
             "FabricIngress.filtering.set_forwarding_type" : "node_6"
           },
           "default_entry" : {
-            "action_id" : 11,
+            "action_id" : 12,
             "action_const" : true,
             "action_data" : ["0x0"],
             "action_entry_const" : true
@@ -2903,7 +2946,7 @@
           "with_counters" : true,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [13, 3],
+          "action_ids" : [14, 3],
           "actions" : ["FabricIngress.forwarding.set_next_id", "NoAction"],
           "base_default_next" : "FabricIngress.forwarding.acl",
           "next_tables" : {
@@ -2940,7 +2983,7 @@
           "with_counters" : true,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [16, 4],
+          "action_ids" : [17, 4],
           "actions" : ["FabricIngress.forwarding.pop_mpls_and_next", "NoAction"],
           "base_default_next" : "tbl_act_0",
           "next_tables" : {
@@ -2964,14 +3007,14 @@
           "with_counters" : false,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [28],
+          "action_ids" : [30],
           "actions" : ["act_0"],
           "base_default_next" : "FabricIngress.forwarding.acl",
           "next_tables" : {
             "act_0" : "FabricIngress.forwarding.acl"
           },
           "default_entry" : {
-            "action_id" : 28,
+            "action_id" : 30,
             "action_const" : true,
             "action_data" : [],
             "action_entry_const" : true
@@ -3000,7 +3043,7 @@
           "with_counters" : true,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [14, 5],
+          "action_ids" : [15, 5],
           "actions" : ["FabricIngress.forwarding.set_next_id", "NoAction"],
           "base_default_next" : "FabricIngress.forwarding.acl",
           "next_tables" : {
@@ -3103,7 +3146,7 @@
           "with_counters" : true,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [15, 17, 12, 1],
+          "action_ids" : [16, 18, 13, 1],
           "actions" : ["FabricIngress.forwarding.set_next_id", "FabricIngress.forwarding.duplicate_to_controller", "FabricIngress.forwarding.drop", "nop"],
           "base_default_next" : "FabricIngress.next.vlan_meta",
           "next_tables" : {
@@ -3142,7 +3185,7 @@
           "with_counters" : true,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [19, 2],
+          "action_ids" : [20, 2],
           "actions" : ["FabricIngress.next.set_vlan", "nop"],
           "base_default_next" : "FabricIngress.next.simple",
           "next_tables" : {
@@ -3179,7 +3222,7 @@
           "with_counters" : true,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [18, 20, 21, 24, 23, 6],
+          "action_ids" : [19, 21, 22, 25, 24, 6],
           "actions" : ["FabricIngress.next.output", "FabricIngress.next.set_vlan_output", "FabricIngress.next.l3_routing", "FabricIngress.next.mpls_routing_v4", "FabricIngress.next.l3_routing_vlan", "NoAction"],
           "base_default_next" : null,
           "next_tables" : {
@@ -3203,14 +3246,14 @@
           "with_counters" : false,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [29],
+          "action_ids" : [31],
           "actions" : ["act_1"],
           "base_default_next" : "node_18",
           "next_tables" : {
             "act_1" : "node_18"
           },
           "default_entry" : {
-            "action_id" : 29,
+            "action_id" : 31,
             "action_const" : true,
             "action_data" : [],
             "action_entry_const" : true
@@ -3226,14 +3269,14 @@
           "with_counters" : false,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [30],
+          "action_ids" : [32],
           "actions" : ["act_2"],
           "base_default_next" : "node_18",
           "next_tables" : {
             "act_2" : "node_18"
           },
           "default_entry" : {
-            "action_id" : 30,
+            "action_id" : 32,
             "action_const" : true,
             "action_data" : [],
             "action_entry_const" : true
@@ -3249,14 +3292,14 @@
           "with_counters" : false,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [31],
+          "action_ids" : [33],
           "actions" : ["act_3"],
           "base_default_next" : "FabricIngress.next.hashed",
           "next_tables" : {
             "act_3" : "FabricIngress.next.hashed"
           },
           "default_entry" : {
-            "action_id" : 31,
+            "action_id" : 33,
             "action_const" : true,
             "action_data" : [],
             "action_entry_const" : true
@@ -3286,41 +3329,55 @@
           "with_counters" : true,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [22, 25, 26, 7],
+          "action_ids" : [23, 26, 27, 7],
           "actions" : ["FabricIngress.next.l3_routing", "FabricIngress.next.mpls_routing_v4", "FabricIngress.next.mpls_routing_v6", "NoAction"],
-          "base_default_next" : "node_23",
+          "base_default_next" : "FabricIngress.next.multicast",
           "next_tables" : {
-            "FabricIngress.next.l3_routing" : "node_23",
-            "FabricIngress.next.mpls_routing_v4" : "node_23",
-            "FabricIngress.next.mpls_routing_v6" : "node_23",
-            "NoAction" : "node_23"
+            "FabricIngress.next.l3_routing" : "FabricIngress.next.multicast",
+            "FabricIngress.next.mpls_routing_v4" : "FabricIngress.next.multicast",
+            "FabricIngress.next.mpls_routing_v6" : "FabricIngress.next.multicast",
+            "NoAction" : "FabricIngress.next.multicast"
+          }
+        },
+        {
+          "name" : "FabricIngress.next.multicast",
+          "id" : 14,
+          "source_info" : {
+            "filename" : "include/control/next.p4",
+            "line" : 153,
+            "column" : 10,
+            "source_fragment" : "multicast"
+          },
+          "key" : [
+            {
+              "match_type" : "exact",
+              "name" : "fabric_metadata.next_id",
+              "target" : ["scalars", "fabric_metadata_t.next_id"],
+              "mask" : null
+            }
+          ],
+          "match_type" : "exact",
+          "type" : "simple",
+          "max_size" : 1024,
+          "with_counters" : true,
+          "support_timeout" : false,
+          "direct_meters" : null,
+          "action_ids" : [28, 8],
+          "actions" : ["FabricIngress.next.set_mcast_group", "NoAction"],
+          "base_default_next" : "node_24",
+          "next_tables" : {
+            "FabricIngress.next.set_mcast_group" : "node_24",
+            "NoAction" : "node_24"
+          },
+          "default_entry" : {
+            "action_id" : 8,
+            "action_const" : false,
+            "action_data" : [],
+            "action_entry_const" : false
           }
         },
         {
           "name" : "tbl_act_4",
-          "id" : 14,
-          "key" : [],
-          "match_type" : "exact",
-          "type" : "simple",
-          "max_size" : 1024,
-          "with_counters" : false,
-          "support_timeout" : false,
-          "direct_meters" : null,
-          "action_ids" : [32],
-          "actions" : ["act_4"],
-          "base_default_next" : "node_25",
-          "next_tables" : {
-            "act_4" : "node_25"
-          },
-          "default_entry" : {
-            "action_id" : 32,
-            "action_const" : true,
-            "action_data" : [],
-            "action_entry_const" : true
-          }
-        },
-        {
-          "name" : "tbl_act_5",
           "id" : 15,
           "key" : [],
           "match_type" : "exact",
@@ -3329,14 +3386,37 @@
           "with_counters" : false,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [33],
+          "action_ids" : [34],
+          "actions" : ["act_4"],
+          "base_default_next" : "node_26",
+          "next_tables" : {
+            "act_4" : "node_26"
+          },
+          "default_entry" : {
+            "action_id" : 34,
+            "action_const" : true,
+            "action_data" : [],
+            "action_entry_const" : true
+          }
+        },
+        {
+          "name" : "tbl_act_5",
+          "id" : 16,
+          "key" : [],
+          "match_type" : "exact",
+          "type" : "simple",
+          "max_size" : 1024,
+          "with_counters" : false,
+          "support_timeout" : false,
+          "direct_meters" : null,
+          "action_ids" : [35],
           "actions" : ["act_5"],
           "base_default_next" : null,
           "next_tables" : {
             "act_5" : null
           },
           "default_entry" : {
-            "action_id" : 33,
+            "action_id" : 35,
             "action_const" : true,
             "action_data" : [],
             "action_entry_const" : true
@@ -3499,7 +3579,7 @@
           "id" : 5,
           "source_info" : {
             "filename" : "include/control/next.p4",
-            "line" : 169,
+            "line" : 166,
             "column" : 16,
             "source_fragment" : "!hdr.mpls.isValid()"
           },
@@ -3529,7 +3609,7 @@
           "id" : 6,
           "source_info" : {
             "filename" : "include/control/next.p4",
-            "line" : 170,
+            "line" : 167,
             "column" : 19,
             "source_fragment" : "hdr.ipv4.isValid()"
           },
@@ -3548,7 +3628,7 @@
           "false_next" : "FabricIngress.next.hashed"
         },
         {
-          "name" : "node_23",
+          "name" : "node_24",
           "id" : 7,
           "source_info" : {
             "filename" : "include/control/port_counter.p4",
@@ -3571,10 +3651,10 @@
             }
           },
           "true_next" : "tbl_act_4",
-          "false_next" : "node_25"
+          "false_next" : "node_26"
         },
         {
-          "name" : "node_25",
+          "name" : "node_26",
           "id" : 8,
           "source_info" : {
             "filename" : "include/control/port_counter.p4",
@@ -3614,10 +3694,10 @@
       "tables" : [
         {
           "name" : "FabricEgress.egress_next.egress_vlan",
-          "id" : 16,
+          "id" : 17,
           "source_info" : {
             "filename" : "include/control/next.p4",
-            "line" : 197,
+            "line" : 192,
             "column" : 10,
             "source_fragment" : "egress_vlan"
           },
@@ -3641,15 +3721,15 @@
           "with_counters" : false,
           "support_timeout" : false,
           "direct_meters" : null,
-          "action_ids" : [36, 34],
+          "action_ids" : [38, 36],
           "actions" : ["FabricEgress.egress_next.pop_vlan", "nop"],
-          "base_default_next" : "node_30",
+          "base_default_next" : "node_31",
           "next_tables" : {
-            "FabricEgress.egress_next.pop_vlan" : "node_30",
-            "nop" : "node_30"
+            "FabricEgress.egress_next.pop_vlan" : "node_31",
+            "nop" : "node_31"
           },
           "default_entry" : {
-            "action_id" : 34,
+            "action_id" : 36,
             "action_const" : false,
             "action_data" : [],
             "action_entry_const" : false
@@ -3657,29 +3737,6 @@
         },
         {
           "name" : "tbl_pkt_io_egress_pop_vlan",
-          "id" : 17,
-          "key" : [],
-          "match_type" : "exact",
-          "type" : "simple",
-          "max_size" : 1024,
-          "with_counters" : false,
-          "support_timeout" : false,
-          "direct_meters" : null,
-          "action_ids" : [35],
-          "actions" : ["FabricEgress.pkt_io_egress.pop_vlan"],
-          "base_default_next" : "tbl_act_6",
-          "next_tables" : {
-            "FabricEgress.pkt_io_egress.pop_vlan" : "tbl_act_6"
-          },
-          "default_entry" : {
-            "action_id" : 35,
-            "action_const" : true,
-            "action_data" : [],
-            "action_entry_const" : true
-          }
-        },
-        {
-          "name" : "tbl_act_6",
           "id" : 18,
           "key" : [],
           "match_type" : "exact",
@@ -3689,13 +3746,36 @@
           "support_timeout" : false,
           "direct_meters" : null,
           "action_ids" : [37],
+          "actions" : ["FabricEgress.pkt_io_egress.pop_vlan"],
+          "base_default_next" : "tbl_act_6",
+          "next_tables" : {
+            "FabricEgress.pkt_io_egress.pop_vlan" : "tbl_act_6"
+          },
+          "default_entry" : {
+            "action_id" : 37,
+            "action_const" : true,
+            "action_data" : [],
+            "action_entry_const" : true
+          }
+        },
+        {
+          "name" : "tbl_act_6",
+          "id" : 19,
+          "key" : [],
+          "match_type" : "exact",
+          "type" : "simple",
+          "max_size" : 1024,
+          "with_counters" : false,
+          "support_timeout" : false,
+          "direct_meters" : null,
+          "action_ids" : [39],
           "actions" : ["act_6"],
           "base_default_next" : null,
           "next_tables" : {
             "act_6" : null
           },
           "default_entry" : {
-            "action_id" : 37,
+            "action_id" : 39,
             "action_const" : true,
             "action_data" : [],
             "action_entry_const" : true
@@ -3705,7 +3785,7 @@
       "action_profiles" : [],
       "conditionals" : [
         {
-          "name" : "node_30",
+          "name" : "node_31",
           "id" : 9,
           "source_info" : {
             "filename" : "include/control/packetio.p4",
@@ -3728,10 +3808,10 @@
             }
           },
           "false_next" : null,
-          "true_next" : "node_31"
+          "true_next" : "node_32"
         },
         {
-          "name" : "node_31",
+          "name" : "node_32",
           "id" : 10,
           "source_info" : {
             "filename" : "include/control/packetio.p4",
diff --git a/pipelines/fabric/src/main/resources/p4c-out/fabric/bmv2/default/p4info.txt b/pipelines/fabric/src/main/resources/p4c-out/fabric/bmv2/default/p4info.txt
index bae8224..ce76fa7 100644
--- a/pipelines/fabric/src/main/resources/p4c-out/fabric/bmv2/default/p4info.txt
+++ b/pipelines/fabric/src/main/resources/p4c-out/fabric/bmv2/default/p4info.txt
@@ -330,6 +330,29 @@
 }
 tables {
   preamble {
+    id: 33606828
+    name: "FabricIngress.next.multicast"
+    alias: "multicast"
+  }
+  match_fields {
+    id: 1
+    name: "fabric_metadata.next_id"
+    bitwidth: 32
+    match_type: EXACT
+  }
+  action_refs {
+    id: 16789575
+  }
+  action_refs {
+    id: 16800567
+    annotations: "@defaultonly()"
+  }
+  direct_resource_ids: 318801752
+  size: 1024
+  idle_timeout_behavior: NO_TIMEOUT
+}
+tables {
+  preamble {
     id: 33599342
     name: "FabricEgress.egress_next.egress_vlan"
     alias: "egress_vlan"
@@ -596,6 +619,18 @@
 }
 actions {
   preamble {
+    id: 16789575
+    name: "FabricIngress.next.set_mcast_group"
+    alias: "set_mcast_group"
+  }
+  params {
+    id: 1
+    name: "gid"
+    bitwidth: 16
+  }
+}
+actions {
+  preamble {
     id: 16801047
     name: "FabricEgress.pkt_io_egress.pop_vlan"
     alias: "pkt_io_egress.pop_vlan"
@@ -739,6 +774,17 @@
   }
   direct_table_id: 33608588
 }
+direct_counters {
+  preamble {
+    id: 318801752
+    name: "FabricIngress.next.multicast_counter"
+    alias: "multicast_counter"
+  }
+  spec {
+    unit: BOTH
+  }
+  direct_table_id: 33606828
+}
 controller_packet_metadata {
   preamble {
     id: 67146229
diff --git a/protocols/bmv2/pom.xml b/protocols/bmv2/pom.xml
new file mode 100644
index 0000000..13c545e
--- /dev/null
+++ b/protocols/bmv2/pom.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  ~
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>onos-protocols</artifactId>
+        <groupId>org.onosproject</groupId>
+        <version>1.13.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>onos-bmv2-protocol</artifactId>
+
+    <modules>
+        <module>thrift-api</module>
+    </modules>
+
+    <packaging>pom</packaging>
+
+    <description>BMv2 protocol subsystem</description>
+
+</project>
\ No newline at end of file
diff --git a/protocols/bmv2/thrift-api/BUCK b/protocols/bmv2/thrift-api/BUCK
new file mode 100644
index 0000000..b1d766a
--- /dev/null
+++ b/protocols/bmv2/thrift-api/BUCK
@@ -0,0 +1,102 @@
+COMPILE_DEPS = [
+    '//lib:CORE_DEPS',
+    '//lib:libthrift',
+]
+
+# BMV2_COMMIT should be set to the same value as specified in install-p4-tools.sh
+BMV2_COMMIT = 'ed130d01be985d814c17de949839d484e76400b1'
+BMV2_BASEURL = 'https://cdn.rawgit.com/p4lang/behavioral-model/' + BMV2_COMMIT
+BMV2_NAMESPACE = 'org.onosproject.bmv2.thriftapi'
+
+THRIFT_EXE_BASEURL = 'https://cdn.rawgit.com/ccascone/mvn-thrift-compiler/1.1_0.9.3/exe/'
+THRIFT_EXE_SHA1S = {
+    'thrift-linux-x86_64.exe':'9b7b5d6eabc9552b8227e8f63981bc15c0985dd5',
+    'thrift-osx-x86_64.exe':'b9215c5141f56fd277b7cf41d9745af847afe498'
+}
+
+def prebuilt_thrift_compiler():
+    import platform
+    os_name = platform.system().lower()
+    if os_name == 'darwin':
+        os_name = 'osx'
+    arch = '%s-%s' % (os_name, platform.machine())
+    fname = 'thrift-%s.exe' % arch
+    if fname not in THRIFT_EXE_SHA1S:
+        raise Exception('Cannot download thrift compiler, architecture %s not supported' % arch)
+    remote_file(
+        name = 'thrift-binary',
+        out = 'thrift.binary',
+        url = THRIFT_EXE_BASEURL + fname,
+        sha1 = THRIFT_EXE_SHA1S[fname],
+    )
+    genrule (
+        name = 'thrift-exe',
+        srcs = [ ':thrift-binary' ],
+        bash = 'cp $(location :thrift-binary) $OUT && chmod +x $OUT',
+        executable = True,
+        out = 'thrift.exe'
+    )
+
+prebuilt_thrift_compiler()
+
+# TODO: or export local thrift executable
+# export_file(
+#       name = 'thrift-exe',
+#       src = '/usr/bin/thrift',
+#     )
+
+def remote_thrift_def(
+    name,
+    url,
+    sha1):
+    # Download *.thrift definition file.
+    remote_file(
+        name = name + '-rem',
+        out = name + '.thrift',
+        url = url,
+        sha1 = sha1,
+    )
+    # Add java namespace.
+    genrule (
+        name = name+'-ns',
+        srcs = [':' + name + '-rem'],
+        bash = 'cp $(location :' + name + '-rem) $OUT && '
+                + 'echo "namespace java ' + BMV2_NAMESPACE + '" | '
+                + 'cat - $OUT > temp && mv temp $OUT',
+        out = name + '.thrift',
+    )
+    # Generate Java sources.
+    genrule (
+        name = name+'-gen',
+        srcs = [':' + name + '-ns'],
+        # FIXME: is there a better way to get just the output dir of this rule?
+        # ...not the full file path in $OUT
+        cmd = '$(exe :thrift-exe) -o $SRCDIR/../' + name + '-gen '
+                + '--gen java $SRCDIR/' + name + '.thrift',
+        out = 'gen-java',
+    )
+    # Zip them.
+    zip_file(
+        name = name,
+        out = name + '.src.zip',
+        srcs = [':' + name + '-gen']
+    )
+
+
+remote_thrift_def(
+    name = 'simple_pre_lag',
+    url = BMV2_BASEURL + '/thrift_src/simple_pre_lag.thrift',
+    sha1 = 'f468ebebc7bb8577f11ca950939f34add5f5634c',
+)
+
+osgi_jar(
+    # If a source ending with *.src.zip is passed, Buck automatically looks for *.java files inside.
+    srcs = [':simple_pre_lag'],
+    deps = COMPILE_DEPS,
+    do_javadocs = False,
+    do_checkstyle = False
+)
+
+project_config(
+    src_target = ':onos-protocols-bmv2-thrift-api'
+)
\ No newline at end of file
diff --git a/protocols/bmv2/thrift-api/pom.xml b/protocols/bmv2/thrift-api/pom.xml
new file mode 100644
index 0000000..f595b68
--- /dev/null
+++ b/protocols/bmv2/thrift-api/pom.xml
@@ -0,0 +1,240 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Copyright 2018-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.
+  ~
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>onos-bmv2-protocol</artifactId>
+        <groupId>org.onosproject</groupId>
+        <version>1.13.0-SNAPSHOT</version>
+    </parent>
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>onos-bmv2-protocol-thrift-api</artifactId>
+
+    <packaging>bundle</packaging>
+
+    <properties>
+        <!-- BMv2 Commit ID and Thrift version -->
+        <bmv2.commit>8f675d0284e9e014f1b8ed502ba54e61d68108cf</bmv2.commit>
+        <bmv2.thrift.version>0.9.3</bmv2.thrift.version>
+        <bmv2.baseurl>https://cdn.rawgit.com/opennetworkinglab/onos-bmv2/${bmv2.commit}</bmv2.baseurl>
+        <bmv2.thrift.javanamespace>org.onosproject.bmv2.thriftapi</bmv2.thrift.javanamespace>
+        <bmv2.thrift.srcdir>${project.build.directory}/thrift-sources/${bmv2.commit}/</bmv2.thrift.srcdir>
+        <thrift.exedir>${project.build.directory}/thrift-compiler/</thrift.exedir>
+        <thrift.exefilename>thrift-${os.detected.classifier}.exe</thrift.exefilename>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.thrift</groupId>
+            <artifactId>libthrift</artifactId>
+            <version>0.9.3</version>
+        </dependency>
+    </dependencies>
+
+    <repositories>
+        <!-- Needed for thrift-compiler, which is hosted on GitHub -->
+        <repository>
+            <id>jitpack.io</id>
+            <url>https://jitpack.io</url>
+        </repository>
+    </repositories>
+
+    <build>
+        <extensions>
+            <extension>
+                <groupId>kr.motd.maven</groupId>
+                <artifactId>os-maven-plugin</artifactId>
+                <version>1.4.0.Final</version>
+            </extension>
+        </extensions>
+
+        <plugins>
+            <!-- Download Thrift source files from BMv2 Github repo -->
+            <plugin>
+                <groupId>com.googlecode.maven-download-plugin</groupId>
+                <artifactId>download-maven-plugin</artifactId>
+                <version>1.3.0</version>
+                <executions>
+                    <execution>
+                        <id>download-bmv2-thrift-standard</id>
+                        <phase>initialize</phase>
+                        <goals>
+                            <goal>wget</goal>
+                        </goals>
+                        <configuration>
+                            <url>${bmv2.baseurl}/thrift_src/standard.thrift</url>
+                            <outputDirectory>${bmv2.thrift.srcdir}</outputDirectory>
+                        </configuration>
+                    </execution>
+                    <execution>
+                        <id>download-bmv2-thrift-simple_pre</id>
+                        <phase>initialize</phase>
+                        <goals>
+                            <goal>wget</goal>
+                        </goals>
+                        <configuration>
+                            <url>${bmv2.baseurl}/thrift_src/simple_pre.thrift</url>
+                            <outputDirectory>${bmv2.thrift.srcdir}</outputDirectory>
+                        </configuration>
+                    </execution>
+                    <execution>
+                        <id>download-bmv2-thrift-simple_pre_lag</id>
+                        <phase>initialize</phase>
+                        <goals>
+                            <goal>wget</goal>
+                        </goals>
+                        <configuration>
+                            <url>${bmv2.baseurl}/thrift_src/simple_pre_lag.thrift</url>
+                            <outputDirectory>${bmv2.thrift.srcdir}</outputDirectory>
+                        </configuration>
+                    </execution>
+                    <execution>
+                        <id>download-bmv2-thrift-simple_switch</id>
+                        <phase>initialize</phase>
+                        <goals>
+                            <goal>wget</goal>
+                        </goals>
+                        <configuration>
+                            <url>${bmv2.baseurl}/targets/simple_switch/thrift/simple_switch.thrift</url>
+                            <outputDirectory>${bmv2.thrift.srcdir}</outputDirectory>
+                        </configuration>
+                    </execution>
+                    <execution>
+                        <id>download-bmv2-thrift-simple_switch-cpservice</id>
+                        <phase>initialize</phase>
+                        <goals>
+                            <goal>wget</goal>
+                        </goals>
+                        <configuration>
+                            <url>${bmv2.baseurl}/targets/simple_switch/thrift/control_plane.thrift</url>
+                            <outputDirectory>${bmv2.thrift.srcdir}</outputDirectory>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+            <!-- Extract Thrift compiler -->
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-dependency-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>unpack</id>
+                        <phase>initialize</phase>
+                        <goals>
+                            <goal>unpack</goal>
+                        </goals>
+                        <configuration>
+                            <artifactItems>
+                                <artifactItem>
+                                    <groupId>com.github.ccascone</groupId>
+                                    <artifactId>mvn-thrift-compiler</artifactId>
+                                    <version>1.1_${bmv2.thrift.version}</version>
+                                    <type>jar</type>
+                                    <includes>${thrift.exefilename}</includes>
+                                    <outputDirectory>${project.build.directory}/thrift-compiler</outputDirectory>
+                                </artifactItem>
+                            </artifactItems>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+            <!-- Add missing java namespace to Thrift files -->
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>exec-maven-plugin</artifactId>
+                <version>1.4.0</version>
+                <executions>
+                    <execution>
+                        <id>add-bmv2-thrift-java-namespace</id>
+                        <phase>initialize</phase>
+                        <goals>
+                            <goal>exec</goal>
+                        </goals>
+                        <configuration>
+                            <executable>${project.basedir}/src/patch.sh</executable>
+                            <arguments>
+                                <argument>${bmv2.thrift.srcdir}</argument>
+                                <argument>${bmv2.thrift.javanamespace}</argument>
+                            </arguments>
+                        </configuration>
+                    </execution>
+                    <execution>
+                        <id>set-thrift-compiler-permissions</id>
+                        <phase>initialize</phase>
+                        <goals>
+                            <goal>exec</goal>
+                        </goals>
+                        <configuration>
+                            <executable>chmod</executable>
+                            <arguments>
+                                <argument>+x</argument>
+                                <argument>${thrift.exedir}/${thrift.exefilename}</argument>
+                            </arguments>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+            <!-- Compile Thrift files -->
+            <plugin>
+                <groupId>org.apache.thrift.tools</groupId>
+                <artifactId>maven-thrift-plugin</artifactId>
+                <version>0.1.11</version>
+                <configuration>
+                    <thriftSourceRoot>${bmv2.thrift.srcdir}</thriftSourceRoot>
+                    <thriftExecutable>${thrift.exedir}/${thrift.exefilename}</thriftExecutable>
+                    <outputDirectory>${project.build.directory}/generated-sources</outputDirectory>
+                </configuration>
+                <executions>
+                    <execution>
+                        <id>thrift-sources</id>
+                        <phase>initialize</phase>
+                        <goals>
+                            <goal>compile</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+            <!-- Make generated sources visible -->
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>build-helper-maven-plugin</artifactId>
+                <version>1.4</version>
+                <executions>
+                    <execution>
+                        <id>add-thrift-sources-to-path</id>
+                        <phase>generate-sources</phase>
+                        <goals>
+                            <goal>add-source</goal>
+                        </goals>
+                        <configuration>
+                            <sources>
+                                <source>
+                                    ${project.build.directory}/generated-sources
+                                </source>
+                            </sources>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+</project>
\ No newline at end of file
diff --git a/tools/dev/mininet/bmv2.py b/tools/dev/mininet/bmv2.py
index c4ec15f..0c0fc15 100644
--- a/tools/dev/mininet/bmv2.py
+++ b/tools/dev/mininet/bmv2.py
@@ -145,6 +145,10 @@
                     "port": self.grpcPort,
                     "deviceId": BMV2_DEFAULT_DEVICE_ID,
                     "deviceKeyId": "p4runtime:%s" % self.onosDeviceId
+                },
+                "bmv2-thrift": {
+                    "ip": srcIP,
+                    "port": self.thriftPort
                 }
             },
             "piPipeconf": {
diff --git a/tools/dev/p4vm/install-p4-tools.sh b/tools/dev/p4vm/install-p4-tools.sh
index 04b9bc6..8807e06 100755
--- a/tools/dev/p4vm/install-p4-tools.sh
+++ b/tools/dev/p4vm/install-p4-tools.sh
@@ -15,6 +15,8 @@
 set -e
 
 BUILD_DIR=~/p4tools
+# in case BMV2_COMMIT value is updated, the same variable in
+# protocols/bmv2/thrift-api/BUCK file should also be updated
 BMV2_COMMIT="ed130d01be985d814c17de949839d484e76400b1"
 PI_COMMIT="59c940916b4f5b182f33b4788d8c410972eaecce"
 P4C_COMMIT="618d15155dcc2d784cc14a8e83131b407cf893e2"