network: Introduce constants for the network model strings

Introduce constants for the network model strings, so as to
avoid using the strings directly at multiple places.

Signed-off-by: Archana Shinde <archana.m.shinde@intel.com>
This commit is contained in:
Archana Shinde 2018-10-22 09:53:09 -07:00
parent 5da973d465
commit 17be8e37f5
2 changed files with 25 additions and 11 deletions

View File

@ -68,22 +68,36 @@ func (n NetInterworkingModel) IsValid() bool {
return 0 <= int(n) && int(n) < int(NetXConnectInvalidModel) return 0 <= int(n) && int(n) < int(NetXConnectInvalidModel)
} }
const (
defaultNetModelStr = "default"
bridgedNetModelStr = "bridged"
macvtapNetModelStr = "macvtap"
enlightenedNetModelStr = "enlightened"
tcFilterNetModelStr = "tcfilter"
noneNetModelStr = "none"
)
//SetModel change the model string value //SetModel change the model string value
func (n *NetInterworkingModel) SetModel(modelName string) error { func (n *NetInterworkingModel) SetModel(modelName string) error {
switch modelName { switch modelName {
case "default": case defaultNetModelStr:
*n = DefaultNetInterworkingModel *n = DefaultNetInterworkingModel
return nil return nil
case "bridged": case bridgedNetModelStr:
*n = NetXConnectBridgedModel *n = NetXConnectBridgedModel
return nil return nil
case "macvtap": case macvtapNetModelStr:
*n = NetXConnectMacVtapModel *n = NetXConnectMacVtapModel
return nil return nil
case "enlightened": case enlightenedNetModelStr:
*n = NetXConnectEnlightenedModel *n = NetXConnectEnlightenedModel
return nil return nil
case "tcfilter": case tcFilterNetModelStr:
*n = NetXConnectTCFilterModel *n = NetXConnectTCFilterModel
return nil return nil
case "none": case "none":

View File

@ -213,12 +213,12 @@ func TestNetInterworkingModelSetModel(t *testing.T) {
wantErr bool wantErr bool
}{ }{
{"Invalid Model", "Invalid", true}, {"Invalid Model", "Invalid", true},
{"default Model", "default", false}, {"default Model", defaultNetModelStr, false},
{"bridged Model", "bridged", false}, {"bridged Model", bridgedNetModelStr, false},
{"macvtap Model", "macvtap", false}, {"macvtap Model", macvtapNetModelStr, false},
{"enlightened Model", "enlightened", false}, {"enlightened Model", enlightenedNetModelStr, false},
{"tcfilter Model", "tcfilter", false}, {"tcfilter Model", tcFilterNetModelStr, false},
{"none Model", "none", false}, {"none Model", noneNetModelStr, false},
} }
for _, tt := range tests { for _, tt := range tests {