How can I generate traffic (like Http get) and get it through GTP tunnel?

Hi all, nice to meet you! New user both to Go and to the forum here!

So, my issue is as follows:
I have a simulated 5G core network deployed in my computer (the project is Free5GC). I need to generate different kinds of traffic (I’m beginning with a simple Http get to a given URL). This traffic will be sent to a local IP address which is the simulated UE (user equipment). Then this UE would keep routing the traffic outside of the network and it would also give the response back to me. This part of the process is transparent for me (I can observe it with Wireshark).
All I have for now is the code that the project gives for testing a ping, which is as follows:

// ping IP(tunnel IP) from to
	gtpHdr, err := hex.DecodeString("32ff00340000000100000000")
	assert.Nil(t, err)
	icmpData, err := hex.DecodeString("8c870d0000000000101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f3031323334353637")
	assert.Nil(t, err)
	ipv4hdr := ipv4.Header{
		Version:  4,
		Len:      20,
		Protocol: 1,
		Flags:    0,
		TotalLen: 48,
		TTL:      64,
		Src:      net.ParseIP("").To4(),
		Dst:      net.ParseIP("").To4(),
		ID:       1,
	checksum := test.CalculateIpv4HeaderChecksum(&ipv4hdr)
	ipv4hdr.Checksum = int(checksum)

	v4HdrBuf, err := ipv4hdr.Marshal()
	assert.Nil(t, err)
	tt := append(gtpHdr, v4HdrBuf...)

	m := icmp.Message{
		Type: ipv4.ICMPTypeEcho, Code: 0,
		Body: &icmp.Echo{
			ID: 12394, Seq: 1,
			Data: icmpData,
	b, err := m.Marshal(nil)
	assert.Nil(t, err)
	b[2] = 0xaf
	b[3] = 0x88
	_, err = upfConn.Write(append(tt, b...))
	assert.Nil(t, err)

It’s quite unclear to me what I have to do, honestly. I know that to make a http get request I could use:
resp, err := http.Get(url)
But since I have to send that to an IP address which then has a GTP tunnel, I don’t know how to do it.
Should I create an ipv4 message? How would I put inside the information for it to be a http get request?
Sorry I couldn’t be any more specific, but I’m kinda lost on this topic and I haven’t been able to found useful information about it.
Waiting for your response.
Regards, Víctor.


What part do you not know how to do? Your sample essentially includes a binary blob of a GTP header as well as a binary blob of ICMP data. If you’re asking how to generate additional traffic, you should be able to put this code into a loop to keep pinging, or if you need to change the data, then you need to either find a package that lets you generate and/or parse GTP headers and/or ICMP data. I Googled for some, but the only one that I can find after 2 minutes is which is also what Oleg Butuzov recommended on your StackOverflow question.

Maybe you could find a package implemented in C/C++/Python/etc. and use it via cgo?

Thanks for your answer.
I’m currently looking into that github project but I’m not sure it actually allows me to generate the GTP header. Also, if my intention is to generate a different kind of traffic that ICMP (like HTTP petitions, or any type) I understand that I would have to build the different layers of the package.

I plan on using Go since the functions to connect with the different network functions are already implemented. How would that work with cgo as you suggested?

I’ve been coding today and, basically, I created an HTTP request. Then I appended the GTP header with the IPv4 header and finally with the HTTP request. Of course, it didn’t work since I couldn’t establish HTTP as the protocol in the IPv4 header since it’s not a listed protocol for it.
The packets’ layers are as follow:
In APP is where the ICMP stands when I run the test with pings, for example.
Any idea on what would I have to do with the HTTP message?

Now I’m able to go through the GTP tunnel. I have to manually construct the bits of both the GTP header and the IP one, which means that what I have so far is the bolded layers:
The application traffic must be a full protocol stack itself (it could be, for example, TCP/HTTP or any other kind of application traffic that uses the transport layer). However, I don’t know how to create the packets to implement that part. I’ve been looking for solutions and so far I can’t seem to find one.
Ideally, I should be able to generate not only HTTP traffic but to, for example, simulate watching a Youtube video.
Any ideas?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.