@@ -22,6 +22,8 @@ import (
2222 "context"
2323 "time"
2424
25+ "github.com/networkservicemesh/sdk-vpp/pkg/tools/dumptool"
26+
2527 "git.fd.io/govpp.git/api"
2628 interfaces "github.com/edwarnicke/govpp/binapi/interface"
2729 "github.com/edwarnicke/govpp/binapi/interface_types"
@@ -38,8 +40,11 @@ import (
3840 "github.com/networkservicemesh/sdk-vpp/pkg/tools/mechutils"
3941)
4042
41- func create (ctx context.Context , conn * networkservice.Connection , vppConn api.Connection , isClient bool ) error {
43+ func create (ctx context.Context , conn * networkservice.Connection , vppConn api.Connection , dumpMap * dumptool. Map , isClient bool ) error {
4244 if mechanism := kernel .ToMechanism (conn .GetMechanism ()); mechanism != nil {
45+ if val , loaded := dumpMap .LoadAndDelete (conn .GetId ()); loaded {
46+ ifindex .Store (ctx , isClient , val .(interface_types.InterfaceIndex ))
47+ }
4348 // Construct the netlink handle for the target namespace for this kernel interface
4449 handle , err := kernellink .GetNetlinkHandle (mechanism .GetNetNSURL ())
4550 if err != nil {
@@ -53,7 +58,7 @@ func create(ctx context.Context, conn *networkservice.Connection, vppConn api.Co
5358 }
5459 }
5560 // Delete the kernel interface if there is one in the target namespace
56- _ = del (ctx , conn , vppConn , isClient )
61+ _ = del (ctx , conn , vppConn , dumpMap , isClient )
5762
5863 nsFilename , err := mechutils .ToNSFilename (mechanism )
5964 if err != nil {
@@ -141,8 +146,11 @@ func create(ctx context.Context, conn *networkservice.Connection, vppConn api.Co
141146 return nil
142147}
143148
144- func del (ctx context.Context , conn * networkservice.Connection , vppConn api.Connection , isClient bool ) error {
149+ func del (ctx context.Context , conn * networkservice.Connection , vppConn api.Connection , dumpMap * dumptool. Map , isClient bool ) error {
145150 if mechanism := kernel .ToMechanism (conn .GetMechanism ()); mechanism != nil {
151+ if val , loaded := dumpMap .LoadAndDelete (conn .GetId ()); loaded {
152+ ifindex .Store (ctx , isClient , val .(interface_types.InterfaceIndex ))
153+ }
146154 swIfIndex , ok := ifindex .LoadAndDelete (ctx , isClient )
147155 if ! ok {
148156 return nil
@@ -162,3 +170,21 @@ func del(ctx context.Context, conn *networkservice.Connection, vppConn api.Conne
162170 }
163171 return nil
164172}
173+
174+ func dump (ctx context.Context , vppConn api.Connection , podName string , timeout time.Duration , isClient bool ) (* dumptool.Map , error ) {
175+ return dumptool .DumpInterfaces (ctx , vppConn , podName , timeout , isClient ,
176+ /* Function on dump */
177+ func (details * interfaces.SwInterfaceDetails ) (interface {}, error ) {
178+ if details .InterfaceDevType == dumptool .DevTypeTap {
179+ return details .SwIfIndex , nil
180+ }
181+ return nil , errors .New ("Doesn't match the tap interface" )
182+ },
183+ /* Function on delete */
184+ func (ifindex interface {}) error {
185+ _ , err := tapv2 .NewServiceClient (vppConn ).TapDeleteV2 (ctx , & tapv2.TapDeleteV2 {
186+ SwIfIndex : ifindex .(interface_types.InterfaceIndex ),
187+ })
188+ return err
189+ })
190+ }
0 commit comments