Comments (4)
Thank you for your idea.
Could you show me the codes that you wrote with the older implementation of the package?
If it isn’t OSX-specific, I can try embedding into the package itself.
Just FYI, I’m working on implementing netlink support that works only on Linux where Kernel-based GTP-U is supported, which I think the most efficient way for vast majority.
#24
from go-gtp.
Yep seen that you're working on netlink based GTP-U.
Checked it on OSX and on Ubuntu. In the following way I was pushing whole traffic via tun via the session.
Two extra libraries required:
"github.com/songgao/water"
"github.com/vishvananda/netlink"
In relay.go:
// Until peer information is registered by AddPeer(), it just drops packets.
func (r *RelayToOS) Run() {
// from left to right
go func() {
buf := make([]byte, 1600)
for {
select {
case <-r.closed():
return
default:
// do nothing and go forward.
}
n, err := r.leftConn.Read(buf)
if err != nil {
continue
}
if _, err := r.rightConn.WriteToGTP(r.rightConnPeer.teid, buf[:n], r.rightConnPeer.addr); err != nil {
continue
}
}
}()
// from right to left
go func() {
buf := make([]byte, 1600)
for {
select {
case <-r.closed():
return
default:
// do nothing and go forward.
}
n, _, _, err := r.rightConn.ReadFromGTP(buf)
if err != nil {
continue
}
if _, err := r.leftConn.Write(buf[:n]); err != nil {
continue
}
}
}()
}
// Close closes Relay. It does not close the UPlaneConn given at first.
func (r *RelayToOS) Close() error {
//FIXME original line was: r.leftConn.SetReadDeadline(time.Now().Add(time.Duration(1 * time.Millisecond)))
if err := r.leftConn.Close(); err != nil {
return err
}
if err := r.rightConn.SetReadDeadline(time.Now().Add(time.Duration(1 * time.Millisecond))); err != nil {
return err
}
close(r.closeCh)
return nil
}
func (r *RelayToOS) closed() <-chan struct{} {
return r.closeCh
}
// AddPeer adds a peer information with the TEID contained in the incoming meesage.
func (r *RelayToOS) AddPeer(teid uint32, raddr net.Addr) {
r.mu.Lock()
defer r.mu.Unlock()
r.rightConnPeer = &peer{teid, raddr}
}
In examples/mme/mock.go:
func (m mockUEeNB) run(errCh chan error)
OSX (I was adding route manually via tun):
func (m mockUEeNB) run(errCh chan error) {
if uConn == nil {
// Listen on eNB S1-U interface.
enbUPlaneAddr, err := net.ResolveUDPAddr("udp", *s1enb)
if err != nil {
log.Fatal(err)
}
m.laddr = enbUPlaneAddr
uConn, err = v1.ListenAndServeUPlane(m.laddr, 0, errCh)
if err != nil {
errCh <- err
return
}
ifce, err := water.New(water.Config{
DeviceType: water.TUN,
})
if err != nil {
log.Fatal(err)
}
loggerCh <- fmt.Sprintf("Created ifce %s", ifce.Name())
//On MAC
//Assign subscriber IP to interface
_, err = exec.Command("/sbin/ifconfig", "utun2", m.subscriberIP, m.subscriberIP, "up").Output()
// handle it here
if err != nil {
fmt.Printf("%s", err)
}
relayToOS := v1.NewRelayToOS(ifce, uConn)
relayToOS.AddPeer(m.teidOut, m.raddr)
go relayToOS.Run()
}
Ubuntu:
func (m mockUEeNB) run(errCh chan error) {
if uConn == nil {
// Listen on eNB S1-U interface.
enbUPlaneAddr, err := net.ResolveUDPAddr("udp", *s1enb)
if err != nil {
log.Fatal(err)
}
m.laddr = enbUPlaneAddr
uConn, err = v1.ListenAndServeUPlane(m.laddr, 0, errCh)
if err != nil {
errCh <- err
return
}
//On MAC
/*ifce, err := water.New(water.Config{
DeviceType: water.TUN,
})
if err != nil {
log.Fatal(err)
}
loggerCh <- fmt.Sprintf("Created ifce %s", ifce.Name())
//On Linux
ifce, err := water.New(water.Config{
DeviceType: water.TUN,
})
if err != nil {
log.Fatal(err)
}
loggerCh <- fmt.Sprintf("Created ifce %s", ifce.Name())
tun, _ := netlink.LinkByName(ifce.Name())
addr, _ := netlink.ParseAddr(m.subscriberIP + "/32")
loggerCh <- fmt.Sprintf("Address for tun %s", addr)
//add IP address from subscriber session
err = netlink.AddrAdd(tun, addr)
if err != nil {
log.Fatal(err)
}
//bring up the interface
err = netlink.LinkSetUp(tun)
if err != nil {
log.Fatal(err)
}
//delete existing default route
dst := &net.IPNet{
IP: net.IPv4(0, 0, 0, 0),
Mask: net.CIDRMask(0, 0),
}
err = netlink.RouteDel(&netlink.Route{LinkIndex: tun.Attrs().Index, Dst: dst})
if err != nil {
fmt.Printf("%s", err)
}
//add new default route via tun interface
err = netlink.RouteAdd(&netlink.Route{LinkIndex: tun.Attrs().Index, Dst: dst})
if err != nil {
log.Fatal(err)
}
relayToOS := v1.NewRelayToOS(ifce, uConn)
relayToOS.AddPeer(m.teidOut, m.raddr)
go relayToOS.Run()
}
from go-gtp.
Looks so useful for testing. Thanks!
Could you please give me a PR with current implementation? Otherwise, I’ll try to add some built-in funcs and examples according to your idea in the future.
from go-gtp.
Let me know if you have anything to discuss further. Thanks.
from go-gtp.
Related Issues (20)
- BearerTFT implementation HOT 5
- Proposal: Improve printing HOT 2
- GTP version 1 with extension header HOT 2
- 5G GTP-U Load Generator HOT 3
- Delete Bearer Request - Linked EPS Bearer HOT 2
- Add parser of extension header with AddHandler HOT 4
- Multiple bearer context on one request HOT 6
- Some fields need to have multiple IEs with the same type and instance HOT 1
- Informative question regarding GTPv1-C HOT 5
- S1MME protocol buffers generation HOT 2
- Missed "Suspend Notification / Ack" and "Resume Notification / Ack" messages HOT 3
- Panic on incorrect input in gtpv2 message.Parse HOT 1
- About the GTP-U Header Length Checking HOT 2
- Extension Header Type List length field is one byte HOT 5
- Slice append copy-paste typos in gtpv2 CSR
- S1AP on top of TCP? HOT 5
- Question on Kernel GTPv1 + UPF HOT 5
- Bug report - Slice bounds out of range in GTP parsing
- Incorrect 3 digits MCC encoding in GTPv1 User Location Information IE HOT 1
- GTPv2-C sequence number overflows at the incorrect value
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-gtp.