Skip to content

Commit

Permalink
Adapt to multi-ip shift in API networkservicemesh/api#47
Browse files Browse the repository at this point in the history
networkservicemesh/api#47

Signed-off-by: Ed Warnicke <hagbard@gmail.com>
  • Loading branch information
edwarnicke committed May 2, 2021
1 parent ba34e96 commit a87e9c7
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 15 deletions.
33 changes: 22 additions & 11 deletions internal/tests/suite_kernel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,13 @@ func (k *kernelVerifiableEndpoint) VerifyConnection(conn *networkservice.Connect
Cls: cls.LOCAL,
Type: kernel.MECHANISM,
}
if err := checkKernelInterface(namingConn, conn.GetContext().GetIpContext().GetDstIPNet(), k.endpointNSHandle); err != nil {
if err := checkKernelInterface(namingConn, conn.GetContext().GetIpContext().GetDstIPNets(), k.endpointNSHandle); err != nil {
return err
}
if err := pingKernel(conn.GetContext().GetIpContext().GetSrcIPNet(), k.endpointNSHandle); err != nil {
return err
for _, ip := range conn.GetContext().GetIpContext().GetSrcIPNets() {
if err := pingKernel(ip, k.endpointNSHandle); err != nil {
return err
}
}
return nil
}
Expand Down Expand Up @@ -171,11 +173,13 @@ func newKernelVerifiableClient(ctx context.Context, sutCC grpc.ClientConnInterfa
}

func (k *kernelVerifiableClient) VerifyConnection(conn *networkservice.Connection) error {
if err := checkKernelInterface(conn, conn.GetContext().GetIpContext().GetSrcIPNet(), k.clientNSHandle); err != nil {
if err := checkKernelInterface(conn, conn.GetContext().GetIpContext().GetSrcIPNets(), k.clientNSHandle); err != nil {
return err
}
if err := pingKernel(conn.GetContext().GetIpContext().GetDstIPNet(), k.clientNSHandle); err != nil {
return err
for _, ip := range conn.GetContext().GetIpContext().GetDstIPNets() {
if err := pingKernel(ip, k.clientNSHandle); err != nil {
return err
}
}
return nil
}
Expand All @@ -184,7 +188,7 @@ func (k *kernelVerifiableClient) VerifyClose(conn *networkservice.Connection) er
return checkNoKernelInterface(conn, k.clientNSHandle)
}

func checkKernelInterface(conn *networkservice.Connection, ipnet *net.IPNet, nsHandle netns.NsHandle) error {
func checkKernelInterface(conn *networkservice.Connection, ipNets []*net.IPNet, nsHandle netns.NsHandle) error {
if mechanism := kernel.ToMechanism(conn.GetMechanism()); mechanism != nil {
curNetNS, err := netns.Get()
if err != nil {
Expand All @@ -203,12 +207,19 @@ func checkKernelInterface(conn *networkservice.Connection, ipnet *net.IPNet, nsH
if err != nil {
return errors.Wrapf(err, "unable to list addresses for interface %q", ifaceName)
}
for _, addr := range addrs {
if addr.IP.Equal(ipnet.IP) && addr.Mask.String() == ipnet.Mask.String() {
return nil
for _, ipNet := range ipNets {
found := false
for _, addr := range addrs {
if addr.IP.Equal(ipNet.IP) && addr.Mask.String() == ipNet.Mask.String() {
found = true
break
}
}
if !found {
return errors.Errorf("Did not find expected addr %q on interface %q", ipNet, ifaceName)
}
}
return errors.Errorf("Did not find expected addr %q on interface %q", ipnet, ifaceName)
return nil
}
return errors.New("not a kernel mechanism")
}
Expand Down
14 changes: 12 additions & 2 deletions internal/tests/suite_memif_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ func newMemifVerifiableEndpoint(ctx context.Context,
}

func (k *memifVerifiableEndpoint) VerifyConnection(conn *networkservice.Connection) error {
return pingVpp(k.ctx, k.vppConn, conn.GetContext().GetIpContext().GetSrcIpAddr())
for _, ip := range conn.GetContext().GetIpContext().GetSrcIpAddrs() {
if err := pingVpp(k.ctx, k.vppConn, ip); err != nil {
return err
}
}
return nil
}

func (k *memifVerifiableEndpoint) VerifyClose(conn *networkservice.Connection) error {
Expand Down Expand Up @@ -125,7 +130,12 @@ func newMemifVerifiableClient(ctx context.Context, sutCC grpc.ClientConnInterfac
}

func (m *memifVerifiableClient) VerifyConnection(conn *networkservice.Connection) error {
return pingVpp(m.ctx, m.vppConn, conn.GetContext().GetIpContext().GetDstIpAddr())
for _, ip := range conn.GetContext().GetIpContext().GetDstIpAddrs() {
if err := pingVpp(m.ctx, m.vppConn, ip); err != nil {
return err
}
}
return nil
}

func (m *memifVerifiableClient) VerifyClose(conn *networkservice.Connection) error {
Expand Down
14 changes: 12 additions & 2 deletions internal/tests/suite_vxlan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ func newVxlanVerifiableEndpoint(ctx context.Context,
}

func (v *vxlanVerifiableEndpoint) VerifyConnection(conn *networkservice.Connection) error {
return pingVpp(v.ctx, v.vppConn, conn.GetContext().GetIpContext().GetSrcIpAddr())
for _, ip := range conn.GetContext().GetIpContext().GetSrcIpAddrs() {
if err := pingVpp(v.ctx, v.vppConn, ip); err != nil {
return err
}
}
return nil
}

func (v *vxlanVerifiableEndpoint) VerifyClose(conn *networkservice.Connection) error {
Expand Down Expand Up @@ -103,7 +108,12 @@ func newVxlanVerifiableClient(
}

func (v *vxlanVerifiableClient) VerifyConnection(conn *networkservice.Connection) error {
return pingVpp(v.ctx, v.vppConn, conn.GetContext().GetIpContext().GetDstIpAddr())
for _, ip := range conn.GetContext().GetIpContext().GetDstIpAddrs() {
if err := pingVpp(v.ctx, v.vppConn, ip); err != nil {
return err
}
}
return nil
}

func (v *vxlanVerifiableClient) VerifyClose(conn *networkservice.Connection) error {
Expand Down

0 comments on commit a87e9c7

Please sign in to comment.