[SEBA-853] Pipeline for BBR

Change-Id: I2a7e2fd8af4ad739593d8e87b46d9756bb507175
diff --git a/Makefile b/Makefile
index 9ff4ba7..9de0553 100644
--- a/Makefile
+++ b/Makefile
@@ -48,7 +48,7 @@
 	docker push ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}bbsim:${DOCKER_TAG}
 
 docker-run: # @HELP Run the container locally (intended for development purposes: DOCKER_RUN_ARGS="-pon 2 -onu 2" make docker-run)
-	docker run -p 50070:50070 -p 50060:50060 --privileged --rm --name bbsim ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}bbsim:${DOCKER_TAG} /app/bbsim ${DOCKER_RUN_ARGS}
+	docker run -d -p 50070:50070 -p 50060:50060 --privileged --rm --name bbsim ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}bbsim:${DOCKER_TAG} /app/bbsim ${DOCKER_RUN_ARGS}
 
 .PHONY: docs
 docs: # @HELP Generate docs and serve them in the browser
diff --git a/tests/bbr.groovy b/tests/bbr.groovy
new file mode 100644
index 0000000..205ea82
--- /dev/null
+++ b/tests/bbr.groovy
@@ -0,0 +1,90 @@
+/*
+ * 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.
+ */
+
+ pipeline {
+
+  /* no label, executor is determined by JJB */
+  agent {
+    label "${params.executorNode}"
+  }
+
+  stages {
+    stage('Build BBSim') {
+      steps {
+        sh """
+          make docker-build
+        """
+      }
+    }
+    stage('Build BBR') {
+      steps {
+        sh """
+          make build-bbr
+        """
+      }
+    }
+    stage('64 ONUs (16 ONU x 4 PONs)') {
+      steps {
+        timeout(1) {
+          sh """
+            DOCKER_RUN_ARGS="-pon 4 -onu 16" make docker-run
+            ./bbr -pon 4 -onu 16 2>&1 | tee bbr_16_4.logs
+            docker logs bbsim 2>&1 | tee bbsim_16_4.logs
+          """
+        }
+      }
+    }
+    stage('128 ONUs (32 ONU x 4 PONs)') {
+      steps {
+        timeout(1) {
+          sh """
+            docker rm -f bbsim
+            DOCKER_RUN_ARGS="-pon 4 -onu 32" make docker-run
+            ./bbr -pon 4 -onu 32 2>&1 | tee bbr_32_4.logs
+            docker logs bbsim 2>&1 | tee bbsim_32_4.logs
+          """
+        }
+      }
+    }
+    stage('256 ONUs (32 ONU x 8 PONs)') {
+      steps {
+        timeout(1) {
+          sh """
+            docker rm -f bbsim
+            DOCKER_RUN_ARGS="-pon 8 -onu 32" make docker-run
+            ./bbr -pon 8 -onu 32 2>&1 | tee bbr_32_8.logs
+            docker logs bbsim 2>&1 | tee bbsim_32_8.logs
+          """
+        }
+      }
+    }
+    post {
+      always {
+         archiveArtifacts artifacts: '*.logs'
+         step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "teo@opennetworking.org", sendToIndividuals: false])
+      }
+      failure {
+        sh '''
+        docker logs bbsim 2>&1 | tee bbsim_failed.logs
+        docker cp bbsim:/app/dhcp.logs dhcp_failed.logs
+        docker cp bbsim:/var/lib/dhcp/dhcpd.leases dhcpd_leases_failed.logs
+        docker cp bbsim:/app/tcpdump.logs tcpdump_failed.logs
+        docker exec bbsim bbsimctl onu list > onu_list.logs
+        '''
+      }
+    }
+  }
+}