summaryrefslogtreecommitdiffstats
path: root/extras/hs-test/netconfig.go
diff options
context:
space:
mode:
authorMaros Ondrejicka <mondreji@cisco.com>2023-02-07 20:40:27 +0100
committerFlorin Coras <florin.coras@gmail.com>2023-02-10 05:23:32 +0000
commit7550dd268f80334cbb9127feefe35319b9c7e572 (patch)
tree08350b3d4dcf5453941312565c63303d95735903 /extras/hs-test/netconfig.go
parent2908f8cf07c21f385f80d83fdad826a0eea98977 (diff)
hs-test: refactor test cases from no-topo suite
This converts remaining tests to configation of VPP from test context. Type: test Change-Id: I386714f6b290e03d1757c2a033a25fae0340f5d6 Signed-off-by: Maros Ondrejicka <mondreji@cisco.com>
Diffstat (limited to 'extras/hs-test/netconfig.go')
-rw-r--r--extras/hs-test/netconfig.go213
1 files changed, 69 insertions, 144 deletions
diff --git a/extras/hs-test/netconfig.go b/extras/hs-test/netconfig.go
index 45ff3790eaf..d94b3269889 100644
--- a/extras/hs-test/netconfig.go
+++ b/extras/hs-test/netconfig.go
@@ -12,16 +12,10 @@ import (
)
type (
- MacAddress = ethernet_types.MacAddress
- AddressWithPrefix = ip_types.AddressWithPrefix
- InterfaceIndex = interface_types.InterfaceIndex
-
- LegacyNetConfig struct {
- Configure func() error
- Unconfigure func()
- }
-
- NetTopology []LegacyNetConfig
+ MacAddress = ethernet_types.MacAddress
+ AddressWithPrefix = ip_types.AddressWithPrefix
+ IP4AddressWithPrefix = ip_types.IP4AddressWithPrefix
+ InterfaceIndex = interface_types.InterfaceIndex
NetConfig interface {
Configure() error
@@ -38,8 +32,9 @@ type (
NetInterface interface {
NetConfig
SetAddress(string)
- Ip4AddressWithPrefix() AddressWithPrefix
- Ip4AddressString() string
+ AddressWithPrefix() AddressWithPrefix
+ IP4AddressWithPrefix() IP4AddressWithPrefix
+ IP4AddressString() string
SetIndex(InterfaceIndex)
Index() InterfaceIndex
HwAddress() MacAddress
@@ -102,12 +97,18 @@ func (b *NetInterfaceBase) Index() InterfaceIndex {
return b.index
}
-func (b *NetInterfaceBase) Ip4AddressWithPrefix() AddressWithPrefix {
+func (b *NetInterfaceBase) AddressWithPrefix() AddressWithPrefix {
address, _ := ip_types.ParseAddressWithPrefix(b.ip4address)
return address
}
-func (b *NetInterfaceBase) Ip4AddressString() string {
+func (b *NetInterfaceBase) IP4AddressWithPrefix() IP4AddressWithPrefix {
+ IP4Prefix, _ := ip_types.ParseIP4Prefix(b.ip4address)
+ IP4AddressWithPrefix := ip_types.IP4AddressWithPrefix(IP4Prefix)
+ return IP4AddressWithPrefix
+}
+
+func (b *NetInterfaceBase) IP4AddressString() string {
return strings.Split(b.ip4address, "/")[0]
}
@@ -137,136 +138,6 @@ func (iface *NetworkInterfaceVeth) Configure() error {
return nil
}
-func (iface *NetworkInterfaceVeth) Unconfigure() {
- DelLink(iface.name)
-}
-
-func (iface *NetworkInterfaceVeth) PeerIp4AddressString() string {
- return strings.Split(iface.peerIp4Address, "/")[0]
-}
-
-func (iface *NetworkInterfaceTap) Configure() error {
- err := AddTap(iface.name, iface.Ip4AddressString())
- if err != nil {
- return err
- }
- return nil
-}
-
-func (iface *NetworkInterfaceTap) Unconfigure() {
- DelLink(iface.name)
-}
-
-func (ns *NetworkNamespace) Configure() error {
- return addDelNetns(ns.name, true)
-}
-
-func (ns *NetworkNamespace) Unconfigure() {
- addDelNetns(ns.name, false)
-}
-
-func (b *NetworkBridge) Configure() error {
- return AddBridge(b.name, b.interfaces, b.networkNamespace)
-}
-
-func (b *NetworkBridge) Unconfigure() {
- DelBridge(b.name, b.networkNamespace)
-}
-
-func (t *NetTopology) Configure() error {
- for _, c := range *t {
- err := c.Configure()
- if err != nil {
- return err
- }
- }
- return nil
-}
-
-func (t *NetTopology) Unconfigure() {
- for _, c := range *t {
- c.Unconfigure()
- }
-}
-
-func newConfigFn(cfg NetDevConfig) func() error {
- t := cfg["type"]
- if t == "netns" {
- return func() error { return AddNetns(cfg["name"].(string)) }
- } else if t == "veth" {
- return func() error {
- var peerNs string
- peer := cfg["peer"].(NetDevConfig)
- peerName := peer["name"].(string)
- err := AddVethPair(cfg["name"].(string), peerName)
- if err != nil {
- return err
- }
-
- if peer["netns"] != nil {
- peerNs = peer["netns"].(string)
- if peerNs != "" {
- err := LinkSetNetns(peerName, peerNs)
- if err != nil {
- return err
- }
- }
- }
- if peer["ip4"] != nil {
- err = AddAddress(peerName, peer["ip4"].(string), peerNs)
- if err != nil {
- return fmt.Errorf("failed to add configure address for %s: %v", peerName, err)
- }
- }
- return nil
- }
- } else if t == "bridge" {
- return func() error { return configureBridge(cfg) }
- }
- return nil
-}
-
-func newUnconfigFn(cfg NetDevConfig) func() {
- t := cfg["type"]
- name := cfg["name"].(string)
-
- if t == "netns" {
- return func() { DelNetns(name) }
- } else if t == "veth" {
- return func() { DelLink(name) }
- } else if t == "bridge" {
- return func() { DelBridge(name, cfg["netns"].(string)) }
- }
- return nil
-}
-
-func NewNetConfig(cfg NetDevConfig) LegacyNetConfig {
- var nc LegacyNetConfig
-
- nc.Configure = newConfigFn(cfg)
- nc.Unconfigure = newUnconfigFn(cfg)
-
- return nc
-}
-
-func NewNetNamespace(cfg NetDevConfig) (NetworkNamespace, error) {
- var networkNamespace NetworkNamespace
- networkNamespace.name = cfg["name"].(string)
- networkNamespace.category = "netns"
- return networkNamespace, nil
-}
-
-func NewBridge(cfg NetDevConfig) (NetworkBridge, error) {
- var bridge NetworkBridge
- bridge.name = cfg["name"].(string)
- bridge.category = "bridge"
- for _, v := range cfg["interfaces"].([]interface{}) {
- bridge.interfaces = append(bridge.interfaces, v.(string))
- }
- bridge.networkNamespace = cfg["netns"].(string)
- return bridge, nil
-}
-
func NewVeth(cfg NetDevConfig, a *Addresser) (NetworkInterfaceVeth, error) {
var veth NetworkInterfaceVeth
var err error
@@ -300,6 +171,14 @@ func NewVeth(cfg NetDevConfig, a *Addresser) (NetworkInterfaceVeth, error) {
return veth, nil
}
+func (iface *NetworkInterfaceVeth) Unconfigure() {
+ DelLink(iface.name)
+}
+
+func (iface *NetworkInterfaceVeth) PeerIp4AddressString() string {
+ return strings.Split(iface.peerIp4Address, "/")[0]
+}
+
func NewTap(cfg NetDevConfig, a *Addresser) (NetworkInterfaceTap, error) {
var tap NetworkInterfaceTap
tap.addresser = a
@@ -313,6 +192,52 @@ func NewTap(cfg NetDevConfig, a *Addresser) (NetworkInterfaceTap, error) {
return tap, nil
}
+func (iface *NetworkInterfaceTap) Configure() error {
+ err := AddTap(iface.name, iface.IP4AddressString())
+ if err != nil {
+ return err
+ }
+ return nil
+}
+
+func (iface *NetworkInterfaceTap) Unconfigure() {
+ DelLink(iface.name)
+}
+
+func NewNetNamespace(cfg NetDevConfig) (NetworkNamespace, error) {
+ var networkNamespace NetworkNamespace
+ networkNamespace.name = cfg["name"].(string)
+ networkNamespace.category = "netns"
+ return networkNamespace, nil
+}
+
+func (ns *NetworkNamespace) Configure() error {
+ return addDelNetns(ns.name, true)
+}
+
+func (ns *NetworkNamespace) Unconfigure() {
+ addDelNetns(ns.name, false)
+}
+
+func NewBridge(cfg NetDevConfig) (NetworkBridge, error) {
+ var bridge NetworkBridge
+ bridge.name = cfg["name"].(string)
+ bridge.category = "bridge"
+ for _, v := range cfg["interfaces"].([]interface{}) {
+ bridge.interfaces = append(bridge.interfaces, v.(string))
+ }
+ bridge.networkNamespace = cfg["netns"].(string)
+ return bridge, nil
+}
+
+func (b *NetworkBridge) Configure() error {
+ return AddBridge(b.name, b.interfaces, b.networkNamespace)
+}
+
+func (b *NetworkBridge) Unconfigure() {
+ DelBridge(b.name, b.networkNamespace)
+}
+
func DelBridge(brName, ns string) error {
err := SetDevDown(brName, ns)
if err != err {