@@ -7,16 +7,12 @@ package service
77import (
88 "encoding/binary"
99 "fmt"
10- gtpLink "my5G-RANTester/internal/cmd/gogtp5g-link"
11- gtpTunnel "my5G-RANTester/internal/cmd/gogtp5g-tunnel"
1210 gnbContext "my5G-RANTester/internal/control_test_engine/gnb/context"
1311 "my5G-RANTester/internal/control_test_engine/ue/context"
1412 "my5G-RANTester/lib/eupf/ebpf"
1513 "net"
1614 "os/exec"
1715 "strconv"
18- "strings"
19- "time"
2016 "unsafe"
2117
2218 "github.com/cilium/ebpf/link"
@@ -282,138 +278,3 @@ func AttachXdpProgram(ifaceName string, bpfObjects *ebpf.BpfObjects) {
282278 log .Fatal (err )
283279 }
284280}
285-
286- func SetupGtpInterfaceOld (ue * context.UEContext , msg gnbContext.UEMessage ) {
287- gnbPduSession := msg .GNBPduSessions [0 ]
288- pduSession , err := ue .GetPduSession (uint8 (gnbPduSession .GetPduSessionId ()))
289- pduSession .GnbPduSession = gnbPduSession
290- if err != nil {
291- log .Error ("[GNB][GTP] " , err )
292- return
293- }
294-
295- if ! ue .IsTunnelEnabled () {
296- log .Info (fmt .Sprintf ("[UE][GTP] Interface for UE %s has not been created. Tunnel has been disabled." , ue .GetMsin ()))
297- return
298- }
299-
300- if pduSession .Id != 1 {
301- log .Warn ("[GNB][GTP] Only one tunnel per UE is supported for now, no tunnel will be created for second PDU Session of given UE" )
302- return
303- }
304-
305- // get UE GNB IP.
306- pduSession .SetGnbIp (net .ParseIP (msg .GnbIp ))
307-
308- ueGnbIp := pduSession .GetGnbIp ()
309- upfIp := pduSession .GnbPduSession .GetUpfIp ()
310- ueIp := pduSession .GetIp ()
311- msin := ue .GetMsin ()
312- nameInf := fmt .Sprintf ("val%s" , msin )
313- vrfInf := fmt .Sprintf ("vrf%s" , msin )
314- stopSignal := make (chan bool )
315-
316- _ = gtpLink .CmdDel (nameInf )
317-
318- go func () {
319- // This function should not return as long as the GTP-U UDP socket is open
320- if err := gtpLink .CmdAdd (nameInf , 1 , ueGnbIp .String (), stopSignal ); err != nil {
321- log .Fatal ("[GNB][GTP] Unable to create Kernel GTP interface: " , err , msin , nameInf )
322- return
323- }
324- }()
325-
326- pduSession .SetStopSignal (stopSignal )
327-
328- time .Sleep (time .Second )
329-
330- cmdAddFar := []string {nameInf , "1" , "--action" , "2" }
331- log .Debug ("[UE][GTP] Setting up GTP Forwarding Action Rule for " , strings .Join (cmdAddFar , " " ))
332- if err := gtpTunnel .CmdAddFAR (cmdAddFar ); err != nil {
333- log .Fatal ("[GNB][GTP] Unable to create FAR: " , err )
334- return
335- }
336-
337- cmdAddFar = []string {nameInf , "2" , "--action" , "2" , "--hdr-creation" , "0" , fmt .Sprint (gnbPduSession .GetTeidUplink ()), upfIp , "2152" }
338- log .Debug ("[UE][GTP] Setting up GTP Forwarding Action Rule for " , strings .Join (cmdAddFar , " " ))
339- if err := gtpTunnel .CmdAddFAR (cmdAddFar ); err != nil {
340- log .Fatal ("[UE][GTP] Unable to create FAR " , err )
341- return
342- }
343-
344- cmdAddPdr := []string {nameInf , "1" , "--pcd" , "1" , "--hdr-rm" , "0" , "--ue-ipv4" , ueIp , "--f-teid" , fmt .Sprint (gnbPduSession .GetTeidDownlink ()), msg .GnbIp , "--far-id" , "1" }
345- log .Debug ("[UE][GTP] Setting up GTP Packet Detection Rule for " , strings .Join (cmdAddPdr , " " ))
346-
347- if err := gtpTunnel .CmdAddPDR (cmdAddPdr ); err != nil {
348- log .Fatal ("[GNB][GTP] Unable to create FAR: " , err )
349- return
350- }
351-
352- cmdAddPdr = []string {nameInf , "2" , "--pcd" , "2" , "--ue-ipv4" , ueIp , "--far-id" , "2" }
353- log .Debug ("[UE][GTP] Setting Up GTP Packet Detection Rule for " , strings .Join (cmdAddPdr , " " ))
354- if err := gtpTunnel .CmdAddPDR (cmdAddPdr ); err != nil {
355- log .Fatal ("[UE][GTP] Unable to create FAR " , err )
356- return
357- }
358-
359- netUeIp := net .ParseIP (ueIp )
360- // add an IP address to a link device.
361- addrTun := & netlink.Addr {
362- IPNet : & net.IPNet {
363- IP : netUeIp .To4 (),
364- Mask : net .IPv4Mask (255 , 255 , 255 , 255 ),
365- },
366- }
367-
368- link , _ := netlink .LinkByName (nameInf )
369- pduSession .SetTunInterface (link )
370-
371- if err := netlink .AddrAdd (link , addrTun ); err != nil {
372- log .Fatal ("[UE][DATA] Error in adding IP for virtual interface" , err )
373- return
374- }
375-
376- tableId , _ := strconv .Atoi (fmt .Sprint (gnbPduSession .GetTeidUplink ()))
377-
378- vrfDevice := & netlink.Vrf {
379- LinkAttrs : netlink.LinkAttrs {
380- Name : vrfInf ,
381- },
382- Table : uint32 (tableId ),
383- }
384- _ = netlink .LinkDel (vrfDevice )
385-
386- if err := netlink .LinkAdd (vrfDevice ); err != nil {
387- log .Fatal ("[UE][DATA] Unable to create VRF for UE" , err )
388- return
389- }
390-
391- if err := netlink .LinkSetMaster (link , vrfDevice ); err != nil {
392- log .Fatal ("[UE][DATA] Unable to set GTP tunnel as slave of VRF interface" , err )
393- return
394- }
395-
396- if err := netlink .LinkSetUp (vrfDevice ); err != nil {
397- log .Fatal ("[UE][DATA] Unable to set interface VRF UP" , err )
398- return
399- }
400- pduSession .SetVrfDevice (vrfDevice )
401-
402- route := & netlink.Route {
403- Dst : & net.IPNet {IP : net .IPv4zero , Mask : net .CIDRMask (0 , 32 )}, // default
404- LinkIndex : link .Attrs ().Index , // dev gtp-<ECI>
405- Scope : netlink .SCOPE_LINK , // scope link
406- Protocol : 4 , // proto static
407- Priority : 1 , // metric 1
408- Table : tableId , // table <ECI>
409- }
410-
411- if err := netlink .RouteReplace (route ); err != nil {
412- log .Fatal ("[GNB][GTP] Unable to create Kernel Route " , err )
413- }
414- pduSession .SetTunRoute (route )
415-
416- log .Info (fmt .Sprintf ("[UE][GTP] Interface %s has successfully been configured for UE %s" , nameInf , ueIp ))
417- log .Info (fmt .Sprintf ("[UE][GTP] You can do traffic for this UE using VRF %s, eg:" , vrfInf ))
418- log .Info (fmt .Sprintf ("[UE][GTP] sudo ip vrf exec %s iperf3 -c IPERF_SERVER -p PORT -t 9000" , vrfInf ))
419- }
0 commit comments