Basic BBSimCtl implementation

Change-Id: Ib5e6f7f462cdb10a3d976b99812658bf7e225dfb
diff --git a/Makefile b/Makefile
index bfb85fd..04f7f15 100644
--- a/Makefile
+++ b/Makefile
@@ -30,13 +30,7 @@
 dep: # @HELP Download the dependencies to the vendor folder
 	GO111MODULE=on go mod vendor
 
-build: dep protos # @HELP Build the binary
-	GO111MODULE=on go build -i -v -mod vendor \
-	-ldflags "-X main.buildTime=$(shell date +”%Y/%m/%d-%H:%M:%S”) \
-		-X main.commitHash=$(shell git log --pretty=format:%H -n 1) \
-		-X main.gitStatus=${GIT_STATUS} \
-		-X main.version=${VERSION}" \
-	-o ./cmd/bbsim ./internal/bbsim
+build: dep protos build-bbsim build-bbsimctl# @HELP Build the binary
 
 test: dep protos # @HELP Execute unit tests
 	GO111MODULE=on go test -v -mod vendor ./internal/bbsim/... -covermode count -coverprofile ./tests/results/go-test-coverage.out 2>&1 | tee ./tests/results/go-test-results.out
@@ -65,6 +59,21 @@
 
 
 # Internals
+build-bbsim:
+	GO111MODULE=on go build -i -v -mod vendor \
+    	-ldflags "-X main.buildTime=$(shell date +”%Y/%m/%d-%H:%M:%S”) \
+    		-X main.commitHash=$(shell git log --pretty=format:%H -n 1) \
+    		-X main.gitStatus=${GIT_STATUS} \
+    		-X main.version=${VERSION}" \
+    	-o ./cmd/bbsim ./internal/bbsim
+
+build-bbsimctl:
+	GO111MODULE=on go build -i -v -mod vendor \
+        	-ldflags "-X github.com/opencord/bbsim/internal/bbsimctl/config.BuildTime=$(shell date +”%Y/%m/%d-%H:%M:%S”) \
+        		-X github.com/opencord/bbsim/internal/bbsimctl/config.CommitHash=$(shell git log --pretty=format:%H -n 1) \
+        		-X github.com/opencord/bbsim/internal/bbsimctl/config.GitStatus=${GIT_STATUS} \
+        		-X github.com/opencord/bbsim/internal/bbsimctl/config.Version=${VERSION}" \
+        	./cmd/bbsimctl
 
 api/openolt/openolt.pb.go: api/openolt/openolt.proto
 	@protoc -I . \
diff --git a/api/bbsim/bbsim.proto b/api/bbsim/bbsim.proto
index 4504b79..1a0134b 100644
--- a/api/bbsim/bbsim.proto
+++ b/api/bbsim/bbsim.proto
@@ -27,10 +27,11 @@
 
 message Olt {
     int32 ID = 1;
-    string OperState = 2;
-    string InternalState = 3;
-    repeated NNIPort NNIPorts = 4;
-    repeated PONPort PONPorts = 5;
+    string SerialNumber = 2;
+    string OperState = 3;
+    string InternalState = 4;
+    repeated NNIPort NNIPorts = 5;
+    repeated PONPort PONPorts = 6;
 }
 
 message ONU {
diff --git a/go.mod b/go.mod
index ffee23a..523bc1a 100644
--- a/go.mod
+++ b/go.mod
@@ -3,10 +3,14 @@
 go 1.12
 
 require (
+	github.com/fullstorydev/grpcurl v1.3.2 // indirect
 	github.com/golang/protobuf v1.3.2
 	github.com/google/gopacket v1.1.17
+	github.com/jessevdk/go-flags v1.4.0
+	github.com/jhump/protoreflect v1.5.0
 	github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024 // indirect
 	github.com/looplab/fsm v0.1.0
+	github.com/opencord/cordctl v0.0.0-20190909161711-01e9c1f04bf4
 	github.com/opencord/omci-sim v0.0.0-20190826212842-203314beba7e
 	github.com/opencord/voltha-protos v0.0.0-20190813191205-792553b747df
 	github.com/pkg/errors v0.8.1 // indirect
@@ -14,5 +18,6 @@
 	github.com/stretchr/testify v1.4.0 // indirect
 	github.com/t-yuki/gocover-cobertura v0.0.0-20180217150009-aaee18c8195c // indirect
 	google.golang.org/grpc v1.22.1
+	gopkg.in/yaml.v2 v2.2.2
 	gotest.tools v2.2.0+incompatible
 )
diff --git a/go.sum b/go.sum
index 4ce9f98..389113d 100644
--- a/go.sum
+++ b/go.sum
@@ -3,21 +3,30 @@
 github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/fullstorydev/grpcurl v1.3.2 h1:cJKWsBYMocdxXQvgbnhtLG810SL5MhKT4K7BagxRih8=
+github.com/fullstorydev/grpcurl v1.3.2/go.mod h1:kvk8xPCXOrwVd9zYdjy+xSOT4YWm6kyth4Y9NMfBns4=
 github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
 github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
 github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
+github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
 github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
 github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
 github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
 github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
-github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024 h1:rBMNdlhTLzJjJSDIjNEXX1Pz3Hmwmz91v+zycvx9PJc=
 github.com/google/gopacket v1.1.17 h1:rMrlX2ZY2UbvT+sdz3+6J+pp2z+msCq9MxTU6ymxbBY=
 github.com/google/gopacket v1.1.17/go.mod h1:UdDNZ1OO62aGYVnPhxT1U6aI7ukYtA/kB8vaU0diBUM=
+github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA=
+github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
+github.com/jhump/protoreflect v1.5.0 h1:NgpVT+dX71c8hZnxHof2M7QDK7QtohIJ7DYycjnkyfc=
+github.com/jhump/protoreflect v1.5.0/go.mod h1:eaTn3RZAmMBcV0fifFvlm6VHNz3wSkYyXYWUh7ymB74=
+github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024 h1:rBMNdlhTLzJjJSDIjNEXX1Pz3Hmwmz91v+zycvx9PJc=
 github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
 github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
 github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
 github.com/looplab/fsm v0.1.0 h1:Qte7Zdn/5hBNbXzP7yxVU4OIFHWXBovyTT2LaBTyC20=
 github.com/looplab/fsm v0.1.0/go.mod h1:m2VaOfDHxqXBBMgc26m6yUOwkFn8H2AlJDE+jd/uafI=
+github.com/opencord/cordctl v0.0.0-20190909161711-01e9c1f04bf4 h1:Odib2px8tyALzdbyztAAqdxmpmQ/pJahJ7uz8kN/rvk=
+github.com/opencord/cordctl v0.0.0-20190909161711-01e9c1f04bf4/go.mod h1:/+3S0pwQUy7HeKnH0KfKp5W6hmh/LdZzuZTNT/m7vA4=
 github.com/opencord/omci-sim v0.0.0-20190717165025-5ff7bb17f1e9 h1:qUbCkEFUDEtOBeG6JfI2oMD6dmUa/zJldvBR59RhRdM=
 github.com/opencord/omci-sim v0.0.0-20190717165025-5ff7bb17f1e9/go.mod h1:W10NTwE0xK9Kh++wrflXPfkknMCaNKkb7Io/ihO4y3k=
 github.com/opencord/omci-sim v0.0.0-20190826212842-203314beba7e h1:LHHUbAUR0LyFEHxl1KhMbSTZMDs4HvDngwIpmvvFE6U=
@@ -37,10 +46,12 @@
 github.com/t-yuki/gocover-cobertura v0.0.0-20180217150009-aaee18c8195c/go.mod h1:SbErYREK7xXdsRiigaQiQkI9McGRzYMvlKYaP3Nimdk=
 golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
 golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
+golang.org/x/net v0.0.0-20180530234432-1e491301e022/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
 golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
 golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ=
 golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
 golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
+golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
 golang.org/x/sys v0.0.0-20190405154228-4b34438f7a67/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -51,12 +62,17 @@
 golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
 golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
 google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
+google.golang.org/genproto v0.0.0-20170818010345-ee236bd376b0/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
 google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8 h1:Nw54tB0rB7hY/N0NQvRW8DG4Yk3Q6T9cu9RcFQDu1tc=
 google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
+google.golang.org/grpc v1.8.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw=
+google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
 google.golang.org/grpc v1.22.1 h1:/7cs52RnTJmD43s3uxzlq2U7nqVTd/37viQwMrMNlOM=
 google.golang.org/grpc v1.22.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
 gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
 gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
 gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
 gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
+honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
 honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
diff --git a/internal/bbsim/devices/olt.go b/internal/bbsim/devices/olt.go
index 66abe14..6ce09a1 100644
--- a/internal/bbsim/devices/olt.go
+++ b/internal/bbsim/devices/olt.go
@@ -57,6 +57,7 @@
 
 	olt = OltDevice{
 		ID: seq,
+		SerialNumber: fmt.Sprintf("BBSIM_OLT_%d", seq),
 		OperState: getOperStateFSM(func(e *fsm.Event) {
 			oltLogger.Debugf("Changing OLT OperState from %s to %s", e.Src, e.Dst)
 		}),
@@ -469,7 +470,7 @@
 	devinfo.GemportIdEnd = 65535
 	devinfo.FlowIdStart = 1
 	devinfo.FlowIdEnd = 16383
-	devinfo.DeviceSerialNumber = fmt.Sprintf("BBSIM_OLT_%d", o.ID)
+	devinfo.DeviceSerialNumber = o.SerialNumber
 
 	return devinfo, nil
 }
diff --git a/internal/bbsim/devices/types.go b/internal/bbsim/devices/types.go
index e3439f5..65aa09e 100644
--- a/internal/bbsim/devices/types.go
+++ b/internal/bbsim/devices/types.go
@@ -89,6 +89,7 @@
 type OltDevice struct {
 	// BBSIM Internals
 	ID int
+	SerialNumber string
 	NumNni int
 	NumPon int
 	NumOnuPerPon int
diff --git a/internal/bbsim/grpc_api_server.go b/internal/bbsim/grpc_api_server.go
index 3c3ab3e..304d3fa 100644
--- a/internal/bbsim/grpc_api_server.go
+++ b/internal/bbsim/grpc_api_server.go
@@ -28,22 +28,22 @@
 })
 
 var (
-	version 	string
-	buildTime  	string
-	commitHash 	string
-	gitStatus	string
+	version    string
+	buildTime  string
+	commitHash string
+	gitStatus  string
 )
 
 type BBSimServer struct {
 }
 
-func (s BBSimServer) Version(ctx context.Context, req *bbsim.Empty) (*bbsim.VersionNumber, error)  {
+func (s BBSimServer) Version(ctx context.Context, req *bbsim.Empty) (*bbsim.VersionNumber, error) {
 	// TODO add a flag to specofy whether the tree was clean at this commit or not
 	return &bbsim.VersionNumber{
-		Version: version,
-		BuildTime: buildTime,
+		Version:    version,
+		BuildTime:  buildTime,
 		CommitHash: commitHash,
-		GitStatus: gitStatus,
+		GitStatus:  gitStatus,
 	}, nil
 }
 
@@ -54,7 +54,7 @@
 
 	for _, nni := range olt.Nnis {
 		n := bbsim.NNIPort{
-			ID: int32(nni.ID),
+			ID:        int32(nni.ID),
 			OperState: nni.OperState.Current(),
 		}
 		nnis = append(nnis, &n)
@@ -62,23 +62,24 @@
 
 	for _, pon := range olt.Pons {
 		p := bbsim.PONPort{
-			ID: int32(pon.ID),
+			ID:        int32(pon.ID),
 			OperState: pon.OperState.Current(),
 		}
 		pons = append(pons, &p)
 	}
 
 	res := bbsim.Olt{
-		ID: int32(olt.ID),
-		OperState: olt.OperState.Current(),
+		ID:            int32(olt.ID),
+		SerialNumber:  olt.SerialNumber,
+		OperState:     olt.OperState.Current(),
 		InternalState: olt.InternalState.Current(),
-		NNIPorts: nnis,
-		PONPorts: pons,
+		NNIPorts:      nnis,
+		PONPorts:      pons,
 	}
 	return &res, nil
 }
 
-func (s BBSimServer) GetONUs(ctx context.Context, req *bbsim.Empty) (*bbsim.ONUs, error){
+func (s BBSimServer) GetONUs(ctx context.Context, req *bbsim.Empty) (*bbsim.ONUs, error) {
 	olt := devices.GetOLT()
 	onus := bbsim.ONUs{
 		Items: []*bbsim.ONU{},
@@ -87,14 +88,14 @@
 	for _, pon := range olt.Pons {
 		for _, o := range pon.Onus {
 			onu := bbsim.ONU{
-				ID: int32(o.ID),
-				SerialNumber: o.SerialNumber.String(),
-				OperState: o.OperState.Current(),
+				ID:            int32(o.ID),
+				SerialNumber:  o.SerialNumber.String(),
+				OperState:     o.OperState.Current(),
 				InternalState: o.InternalState.Current(),
-				PonPortID: int32(o.PonPortID),
+				PonPortID:     int32(o.PonPortID),
 			}
 			onus.Items = append(onus.Items, &onu)
 		}
 	}
 	return &onus, nil
-}
\ No newline at end of file
+}
diff --git a/internal/bbsimctl/commands/config.go b/internal/bbsimctl/commands/config.go
new file mode 100644
index 0000000..b05bb5b
--- /dev/null
+++ b/internal/bbsimctl/commands/config.go
@@ -0,0 +1,68 @@
+/*
+ * Portions copyright 2019-present Open Networking Foundation
+ * Original copyright 2019-present Ciena Corporation
+ *
+ * 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 commands
+
+import (
+	"fmt"
+	"github.com/jessevdk/go-flags"
+	"github.com/opencord/bbsim/internal/bbsimctl/config"
+	"gopkg.in/yaml.v2"
+)
+
+const copyrightNotice = `
+# Portions copyright 2019-present Open Networking Foundation
+# Original copyright 2019-present Ciena Corporation
+#
+# 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.
+#
+`
+
+type ConfigOptions struct{}
+
+func RegisterConfigCommands(parent *flags.Parser) {
+	parent.AddCommand("config", "generate bbsimctl configuration", "Commands to generate bbsimctl configuration", &ConfigOptions{})
+}
+
+func (options *ConfigOptions) Execute(args []string) error {
+	//GlobalConfig
+	config.ProcessGlobalOptions()
+
+	b, err := yaml.Marshal(config.GlobalConfig)
+	if err != nil {
+		return err
+	}
+	fmt.Println(copyrightNotice)
+	fmt.Println(string(b))
+
+	fmt.Println("BBSimCtl details:")
+	fmt.Printf("\tVersion: %s \n", config.Version)
+	fmt.Printf("\tBuildTime: %s \n", config.BuildTime)
+	fmt.Printf("\tCommitHash: %s \n", config.CommitHash)
+	fmt.Printf("\tGitStatus: %s \n", config.GitStatus)
+	return nil
+}
diff --git a/internal/bbsimctl/commands/handler.go b/internal/bbsimctl/commands/handler.go
new file mode 100644
index 0000000..3c4b0ff
--- /dev/null
+++ b/internal/bbsimctl/commands/handler.go
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2019-present Ciena Corporation
+ *
+ * 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 commands
+
+import (
+	"github.com/golang/protobuf/proto"
+	"github.com/jhump/protoreflect/desc"
+	"github.com/jhump/protoreflect/dynamic"
+	"google.golang.org/grpc/metadata"
+	"google.golang.org/grpc/status"
+	"io"
+)
+
+type RpcEventHandler struct {
+	Response proto.Message
+	Status   *status.Status
+	Data     []byte
+	Fields   map[string]map[string]interface{}
+}
+
+func (h *RpcEventHandler) OnResolveMethod(*desc.MethodDescriptor) {
+}
+
+func (h *RpcEventHandler) OnSendHeaders(metadata.MD) {
+}
+
+func (h *RpcEventHandler) OnReceiveHeaders(metadata.MD) {
+}
+
+func (h *RpcEventHandler) OnReceiveResponse(m proto.Message) {
+	h.Response = m
+}
+
+func (h *RpcEventHandler) OnReceiveTrailers(s *status.Status, m metadata.MD) {
+	h.Status = s
+}
+
+func (h *RpcEventHandler) GetParams(msg proto.Message) error {
+	dmsg, err := dynamic.AsDynamicMessage(msg)
+	if err != nil {
+		return err
+	}
+
+	if h.Fields == nil || len(h.Fields) == 0 {
+		return io.EOF
+	}
+
+	fields, ok := h.Fields[dmsg.XXX_MessageName()]
+	if !ok {
+		return nil
+	}
+
+	for k, v := range fields {
+		dmsg.TrySetFieldByName(k, v)
+	}
+	delete(h.Fields, dmsg.XXX_MessageName())
+
+	return nil
+}
diff --git a/internal/bbsimctl/commands/olt.go b/internal/bbsimctl/commands/olt.go
new file mode 100644
index 0000000..7f698f1
--- /dev/null
+++ b/internal/bbsimctl/commands/olt.go
@@ -0,0 +1,111 @@
+/*
+ * Portions copyright 2019-present Open Networking Foundation
+ * Original copyright 2019-present Ciena Corporation
+ *
+ * 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 commands
+
+import (
+	"context"
+	"fmt"
+	"github.com/jessevdk/go-flags"
+	pb "github.com/opencord/bbsim/api/bbsim"
+	"github.com/opencord/bbsim/internal/bbsimctl/config"
+	"github.com/opencord/cordctl/pkg/format"
+	log "github.com/sirupsen/logrus"
+	"google.golang.org/grpc"
+	"os"
+)
+
+const (
+	DEFAULT_OLT_DEVICE_HEADER_FORMAT = "table{{ .ID }}\t{{ .SerialNumber }}\t{{ .OperState }}\t{{ .InternalState }}"
+	DEFAULT_PORT_HEADER_FORMAT       = "table{{ .ID }}\t{{ .OperState }}"
+)
+
+type OltGet struct{}
+
+type OltNNIs struct{}
+
+type OltPONs struct{}
+
+// TODO add autocomplete
+type oltOptions struct {
+	Get OltGet  `command:"get"`
+	NNI OltNNIs `command:"nnis"`
+	PON OltPONs `command:"pons"`
+}
+
+func RegisterOltCommands(parser *flags.Parser) {
+	parser.AddCommand("olt", "OLT Commands", "Commands to query and manipulate the OLT device", &oltOptions{})
+}
+
+func getOLT() *pb.Olt {
+	conn, err := grpc.Dial(config.GlobalConfig.Server, grpc.WithInsecure())
+	if err != nil {
+		log.Fatal("did not connect: %v", err)
+		return nil
+	}
+	defer conn.Close()
+	c := pb.NewBBSimClient(conn)
+
+	// Contact the server and print out its response.
+
+	ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout)
+	defer cancel()
+	olt, err := c.GetOlt(ctx, &pb.Empty{})
+	if err != nil {
+		log.Fatal("could not get OLT: %v", err)
+		return nil
+	}
+	return olt
+}
+
+func printOltHeader(prefix string, o *pb.Olt) {
+	fmt.Println(fmt.Sprintf("%s : %s", prefix, o.SerialNumber))
+	fmt.Println()
+}
+
+// TODO use voltctl or cordctl parser to print tables (this needs to be moved out of the internals package)
+func (o *OltGet) Execute(args []string) error {
+	olt := getOLT()
+
+	// print out
+	tableFormat := format.Format(DEFAULT_OLT_DEVICE_HEADER_FORMAT)
+	tableFormat.Execute(os.Stdout, true, olt)
+
+	return nil
+}
+
+func (o *OltNNIs) Execute(args []string) error {
+	olt := getOLT()
+
+	printOltHeader("NNI Ports for", olt)
+
+	tableFormat := format.Format(DEFAULT_PORT_HEADER_FORMAT)
+	tableFormat.Execute(os.Stdout, true, olt.NNIPorts)
+
+	return nil
+}
+
+func (o *OltPONs) Execute(args []string) error {
+	olt := getOLT()
+
+	printOltHeader("PON Ports for", olt)
+
+	tableFormat := format.Format(DEFAULT_PORT_HEADER_FORMAT)
+	tableFormat.Execute(os.Stdout, true, olt.PONPorts)
+
+	return nil
+}
diff --git a/internal/bbsimctl/commands/onu.go b/internal/bbsimctl/commands/onu.go
new file mode 100644
index 0000000..7d6da8e
--- /dev/null
+++ b/internal/bbsimctl/commands/onu.go
@@ -0,0 +1,73 @@
+/*
+ * Portions copyright 2019-present Open Networking Foundation
+ * Original copyright 2019-present Ciena Corporation
+ *
+ * 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 commands
+
+import (
+	"context"
+	"github.com/jessevdk/go-flags"
+	pb "github.com/opencord/bbsim/api/bbsim"
+	"github.com/opencord/bbsim/internal/bbsimctl/config"
+	"github.com/opencord/cordctl/pkg/format"
+	log "github.com/sirupsen/logrus"
+	"google.golang.org/grpc"
+	"os"
+)
+
+const (
+	DEFAULT_ONU_DEVICE_HEADER_FORMAT = "table{{ .PonPortID }}\t{{ .ID }}\t{{ .SerialNumber }}\t{{ .OperState }}\t{{ .InternalState }}"
+)
+
+type ONUOptions struct{}
+
+func RegisterONUCommands(parser *flags.Parser) {
+	parser.AddCommand("onus", "List ONU Devices", "Commands to list the ONU devices and their internal state", &ONUOptions{})
+}
+
+func getONUs() *pb.ONUs {
+	conn, err := grpc.Dial(config.GlobalConfig.Server, grpc.WithInsecure())
+
+	if err != nil {
+		log.Fatal("did not connect: %v", err)
+		return nil
+	}
+	defer conn.Close()
+	c := pb.NewBBSimClient(conn)
+
+	// Contact the server and print out its response.
+
+	ctx, cancel := context.WithTimeout(context.Background(), config.GlobalConfig.Grpc.Timeout)
+	defer cancel()
+	onus, err := c.GetONUs(ctx, &pb.Empty{})
+	if err != nil {
+		log.Fatal("could not get OLT: %v", err)
+		return nil
+	}
+	return onus
+}
+
+func (options *ONUOptions) Execute(args []string) error {
+	onus := getONUs()
+
+	// print out
+	tableFormat := format.Format(DEFAULT_ONU_DEVICE_HEADER_FORMAT)
+	if err := tableFormat.Execute(os.Stdout, true, onus.Items); err != nil {
+		log.Fatalf("Error while formatting ONUs table: %s", err)
+	}
+
+	return nil
+}
diff --git a/internal/bbsimctl/config/config.go b/internal/bbsimctl/config/config.go
new file mode 100644
index 0000000..caf0601
--- /dev/null
+++ b/internal/bbsimctl/config/config.go
@@ -0,0 +1,105 @@
+/*
+ * Portions copyright 2019-present Open Networking Foundation
+ * Original copyright 2019-present Ciena Corporation
+ *
+ * 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 config
+
+import (
+	log "github.com/sirupsen/logrus"
+	"io/ioutil"
+	"net"
+	"os"
+	"fmt"
+	"time"
+	"gopkg.in/yaml.v2"
+)
+
+var (
+	Version 	string
+	BuildTime  	string
+	CommitHash 	string
+	GitStatus	string
+)
+
+var GlobalOptions struct {
+	Config   string `short:"c" long:"config" env:"BBSIMCTL_CONFIG" value-name:"FILE" default:"" description:"Location of client config file"`
+	Server   string `short:"s" long:"server" default:"" value-name:"SERVER:PORT" description:"IP/Host and port of XOS"`
+	//Protoset string `long:"protoset" value-name:"FILENAME" description:"Load protobuf definitions from protoset instead of reflection api"`
+	Debug    bool   `short:"d" long:"debug" description:"Enable debug mode"`
+}
+
+type GrpcConfigSpec struct {
+	Timeout time.Duration `yaml:"timeout"`
+}
+
+type GlobalConfigSpec struct {
+	Server   string        `yaml:"server"`
+	Grpc     GrpcConfigSpec
+}
+
+var GlobalConfig = GlobalConfigSpec{
+	Server: "localhost:50070",
+	Grpc: GrpcConfigSpec{
+		Timeout: time.Second * 10,
+	},
+}
+
+func ProcessGlobalOptions() {
+	if len(GlobalOptions.Config) == 0 {
+		home, err := os.UserHomeDir()
+		if err != nil {
+			log.Printf("Unable to discover the users home directory: %s\n", err)
+		}
+		GlobalOptions.Config = fmt.Sprintf("%s/.bbsim/config", home)
+	}
+
+	info, err := os.Stat(GlobalOptions.Config)
+	if err == nil && !info.IsDir() {
+		configFile, err := ioutil.ReadFile(GlobalOptions.Config)
+		if err != nil {
+			log.Printf("configFile.Get err   #%v ", err)
+		}
+		err = yaml.Unmarshal(configFile, &GlobalConfig)
+		if err != nil {
+			log.Fatalf("Unmarshal: %v", err)
+		}
+	}
+
+	// Override from environment
+	//    in particualr, for passing env vars via `go test`
+	env_server, present := os.LookupEnv("BBSIMCTL_SERVER")
+	if present {
+		GlobalConfig.Server = env_server
+	}
+
+	// Override from command line
+	if GlobalOptions.Server != "" {
+		GlobalConfig.Server = GlobalOptions.Server
+	}
+
+
+	// Generate error messages for required settings
+	if GlobalConfig.Server == "" {
+		log.Fatal("Server is not set. Please update config file or use the -s option")
+	}
+
+	//Try to resolve hostname if provided for the server
+	if host, port, err := net.SplitHostPort(GlobalConfig.Server); err == nil {
+		if addrs, err := net.LookupHost(host); err == nil {
+			GlobalConfig.Server = net.JoinHostPort(addrs[0], port)
+		}
+	}
+}
\ No newline at end of file