aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorRastislav Szabo <raszabo@cisco.com>2017-05-22 13:59:34 +0200
committerRastislav Szabo <raszabo@cisco.com>2017-05-22 14:00:46 +0200
commitc38cb25d746736f062ee16e87f553c8a4ec5fced (patch)
tree231a1befaff3b83b020461e584e9de27a39d06a4 /core
parentc60a4ee4e6114ff0dc3cbc9fd9a58321ca2a8abc (diff)
binapi-generator renamed & moved, finished documentation
Change-Id: I7d3b53fa238e822b36a6a82c61ffb792da3898bf Signed-off-by: Rastislav Szabo <raszabo@cisco.com>
Diffstat (limited to 'core')
-rw-r--r--core/core.go16
-rw-r--r--core/core_test.go14
2 files changed, 28 insertions, 2 deletions
diff --git a/core/core.go b/core/core.go
index 550b6a7..5b14a42 100644
--- a/core/core.go
+++ b/core/core.go
@@ -14,7 +14,7 @@
package core
-//go:generate binapi_generator --input-file=/usr/share/vpp/api/vpe.api.json --output-dir=./bin_api
+//go:generate binapi-generator --input-file=/usr/share/vpp/api/vpe.api.json --output-dir=./bin_api
import (
"errors"
@@ -40,7 +40,7 @@ type Connection struct {
vpp adapter.VppAdapter // VPP adapter
codec *MsgCodec // message codec
- msgIDs map[string]uint16 // map os message IDs indexed by message name + CRC
+ msgIDs map[string]uint16 // map of message IDs indexed by message name + CRC
msgIDsLock sync.RWMutex // lock for the message IDs map
channels map[uint32]*api.Channel // map of all API channels indexed by the channel ID
@@ -112,6 +112,9 @@ func Connect(vppAdapter adapter.VppAdapter) (*Connection, error) {
// Disconnect disconnects from VPP.
func (c *Connection) Disconnect() {
+ if c == nil {
+ return
+ }
connLock.Lock()
defer connLock.Unlock()
@@ -124,12 +127,18 @@ func (c *Connection) Disconnect() {
// NewAPIChannel returns a new API channel for communication with VPP via govpp core.
// It uses default buffer sizes for the request and reply Go channels.
func (c *Connection) NewAPIChannel() (*api.Channel, error) {
+ if c == nil {
+ return nil, errors.New("nil connection passed in")
+ }
return c.NewAPIChannelBuffered(requestChannelBufSize, replyChannelBufSize)
}
// NewAPIChannelBuffered returns a new API channel for communication with VPP via govpp core.
// It allows to specify custom buffer sizes for the request and reply Go channels.
func (c *Connection) NewAPIChannelBuffered(reqChanBufSize, replyChanBufSize int) (*api.Channel, error) {
+ if c == nil {
+ return nil, errors.New("nil connection passed in")
+ }
chID := atomic.AddUint32(&c.maxChannelID, 1)
chMeta := &channelMetadata{id: chID}
@@ -311,6 +320,9 @@ func sendReply(ch *api.Channel, reply *api.VppReply) {
// GetMessageID returns message identifier of given API message.
func (c *Connection) GetMessageID(msg api.Message) (uint16, error) {
+ if c == nil {
+ return 0, errors.New("nil connection passed in")
+ }
return c.messageNameToID(msg.GetMessageName(), msg.GetCrcString())
}
diff --git a/core/core_test.go b/core/core_test.go
index 8bf9311..d3c2e2c 100644
--- a/core/core_test.go
+++ b/core/core_test.go
@@ -144,6 +144,20 @@ func TestNotifications(t *testing.T) {
Expect(err).ShouldNot(HaveOccurred())
}
+func TestNilConnection(t *testing.T) {
+ var conn *Connection
+
+ ch, err := conn.NewAPIChannel()
+ Expect(ch).Should(BeNil())
+ Expect(err).Should(HaveOccurred())
+ Expect(err.Error()).To(ContainSubstring("nil"))
+
+ ch, err = conn.NewAPIChannelBuffered(1, 1)
+ Expect(ch).Should(BeNil())
+ Expect(err).Should(HaveOccurred())
+ Expect(err.Error()).To(ContainSubstring("nil"))
+}
+
func TestDoubleConnection(t *testing.T) {
ctx := setupTest(t)
defer ctx.teardownTest()