aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremias Stotter <jeremias@stotter.eu>2023-11-22 03:21:47 +0100
committerJeremias Stotter <jeremias@stotter.eu>2023-11-22 03:21:47 +0100
commitb225dcc82101a4237932b37b93f559cd3cbf0c02 (patch)
treea9a030d0f97dab284ea700d9603def98dc5a4130
parente9a47d2847a4b65e2d59bdd1b68f38235d45265a (diff)
downloadnetwork-simulator-b225dcc82101a4237932b37b93f559cd3cbf0c02.tar.gz
network-simulator-b225dcc82101a4237932b37b93f559cd3cbf0c02.tar.bz2
network-simulator-b225dcc82101a4237932b37b93f559cd3cbf0c02.zip
Do some http work
This doesnt work, also tcp need a lot of work still
-rw-r--r--templates/genericdev/device.lua40
-rw-r--r--templates/tcplib/tcplib.lua10
2 files changed, 45 insertions, 5 deletions
diff --git a/templates/genericdev/device.lua b/templates/genericdev/device.lua
index 5435172..c5cb6be 100644
--- a/templates/genericdev/device.lua
+++ b/templates/genericdev/device.lua
@@ -169,6 +169,26 @@ function cmdline(cmdline)
connect_tcp(sock, 80, parse_ip(argt[2]), htget, {sock, parse_ip(argt[2])})
end
+ if(argt[1] == "httpserver") then
+ if(argt[2] == "start") then
+ http_sock = socket_tcp(80, ip_addr[0][0])
+ if(http_sock) then
+ listen_tcp(http_sock)
+ else
+ nsprint("Error starting httpserver")
+ end
+ elseif(argt[2] == "stop") then
+ if(http_sock == nil) then
+ nsprint("httpserver already stopped!")
+ return 1
+ end
+ close_tcp(http_sock)
+ http_sock = nil
+ else
+ nsprint "Unknown httpserver argument"
+ end
+ end
+
ip_arguments = {"address", "help", "link", "route"}
ip_addr_arguments = {"add", "delete", "show", "help"}
ip_route_arguments = {"add", "delete", "show", "help"}
@@ -285,7 +305,7 @@ function cmdline(cmdline)
addr = parse_ip(argt[3])
sock_number = tonumber(argt[4])
local open_sock = socket_tcp(l_sock_number)
- connect_tcp(open_sock, l_sock_number, sock_number, addr, tcpopen_success, {open_sock})
+ connect_tcp(open_sock, sock_number, addr, tcpopen_success, {open_sock})
nsprint("Socket no: "..open_sock)
elseif(argt[1] == "tcpsend") then
sock_number = tonumber(argt[2])
@@ -361,6 +381,8 @@ function recv_frame(interface_index, data, data_size)
devlib_handle_frame(interface_index, data, data_size)
end
+local http_accepted = {}
+
-- This gets called every timestamp
function timestamp()
devlib_timestep()
@@ -376,12 +398,24 @@ function timestamp()
for k,v in pairs(listening_sockets) do
accept_sock = accept_tcp(v)
if(accept_sock > 0) then
- nsprint("Socket no: "..accept_sock)
table.insert(communicating_sockets, accept_sock)
end
-
end
+ if(http_sock ~= nil) then
+ accept_sock = accept_tcp(http_sock)
+ if(accept_sock > 0) then
+ table.insert(http_accepted, accept_sock)
+ end
+ end
+
+ for k,v in pairs(http_accepted) do
+ data = read_tcp(v, 65535)
+ nsprint("Recvd http request: "..data)
+ close_tcp(v)
+ table_uninsert(http_accepted, v)
+ end
+
for k,v in pairs(communicating_sockets) do
data = read_tcp(v, 65535)
if(#data > 0) then
diff --git a/templates/tcplib/tcplib.lua b/templates/tcplib/tcplib.lua
index 5c85c5f..8b9315c 100644
--- a/templates/tcplib/tcplib.lua
+++ b/templates/tcplib/tcplib.lua
@@ -180,7 +180,7 @@ function accept_tcp(sock)
return #tcp_sockets
end
-function connect_tcp(sock, port, r_port, addr, after_connect, after_connect_vals)
+function connect_tcp(sock, r_port, addr, after_connect, after_connect_vals)
if(not tcp_sockets[sock]) then
nsprint("Is not a port")
return -1
@@ -202,7 +202,7 @@ function connect_tcp(sock, port, r_port, addr, after_connect, after_connect_vals
tcp_sockets[sock]["r_addr"] = addr
tcp_sockets[sock]["r_port"] = r_port
- tcp_sockets[sock]["port"] = port
+ tcp_sockets[sock]["port"] = tcp_sockets[sock]["port"]
tcp_sockets[sock]["recv_func"] = connect_waiting
tcp_sockets[sock]["recv_func_vals"] = {sock, after_connect, after_connect_vals}
@@ -325,6 +325,12 @@ function handle_tcp(interface_index, data, source, dest)
sock = full_match
end
+ if(tcp_sockets[sock]["passive"]) then
+ nsprint("HANDLING PASSIVE SOCKET")
+ else
+ nsprint("HANDLING ACTIVE SOCKET")
+ end
+
-- No matching socket found
if(not sock) then
nsprint("No matching sock found")
Jeremias Stotters git repositories generated by CGIT