Git Product home page Git Product logo

hans's Introduction

HaNS

The Haskell Network Stack.

Running Echo-Server Examples in Xen

NOTE: This example is out of date

You first need to set up a bridge device, br0; the echo servers are configured to use this bridge in Xen. The configuration files are udp-test/udp-test.config and tcp-test/tcp-test.config.

Assuming you are working in a Cabal sandbox at the top-level of the repo, and have done halvm-cabal install hans, you can run the TCP and UDP echo server examples with

sudo xl create -c ../udp-test/udp-test.config

and

sudo xl create -c ../tcpp-test/tcpp-test.config

where -c makes them print their log messages to standard out. They are configured to use DHCP and will log the IP address they receive after start up; they listen on port 9001.

You can then test them with NetCat, using

nc -u <ip addr> 9001

for UDP and

nc <ip addr> 9001

for TCP. Whatever you enter will be echoed back.

hans's People

Contributors

acw avatar aycanirican avatar cleverca22 avatar dmjio avatar elliottt avatar mhuesch avatar ntc2 avatar trofi avatar utdemir avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hans's Issues

hans-pcap

Hi, there is a naive implementation for working with real devices on Linux it uses PCAP.

I would love to see one which talks to the network directly, maybe based on virtualbox net; or even one which can use it directly.

Forwarding table entries

As the forwarding table is currently separate from the connection tables for UDP and TCP, there is the possibility that ports could be reused, clobbering existing entries in the forwarding table. It would be nice to merge the forwarding and connection tables, or find a better strategy for port management.

Installation failed due to "tcp-test-client"

When I halvm-cabal install, it failed like this after installing some packages:

Resolving dependencies...
Configuring hans-2.4.0.0...
cabal: No 'main-is' field found for executable tcp-test-client
Failed to install hans-2.4.0.0
cabal: Error: some packages failed to install:
hans-2.4.0.0 failed during the configure step. The exception was:
ExitFailure 1

The connect function of TCP doesn't work

Running a simple demo like this:

import Hans.Address.IP4
import Hans.Device.Xen
import Hans.DhcpClient
import Hans.Layer.Dns(DnsException)
import qualified Hans.NetworkStack as NS

import Network.Socket
import Network.Socket.Internal(setNetworkHansStack)
import Control.Monad
import Control.Concurrent
import System.IO

import Hypervisor.Debug
import Hypervisor.Console
import Hypervisor.XenStore
import XenDevice.NIC

main = do
  con <- initXenConsole

  xs <- initXenStore
  nics <- listNICs xs
  let macstr = head nics
      mac = read macstr

  ns <- NS.newNetworkStack
  nic <- openNIC xs macstr
  NS.addDevice ns mac (xenSend nic) (xenReceiveLoop nic)
  NS.deviceUp ns mac

  ipMV <- newEmptyMVar
  dhcpDiscover ns mac (putMVar ipMV)
  ipaddr <- takeMVar ipMV

  setNetworkHansStack ns

  addr:_ <- getAddrInfo (Just defaultHints) (Just $ show ipaddr) (Just "2222")
  ssock <- socket (addrFamily addr) Stream defaultProtocol
  bind ssock (addrAddress addr)
  listen ssock 5
  writeDebugConsole $ "listen on " ++ show (addrAddress addr) ++ "\n"

  forkIO $ do
    (connsock, caddr) <- accept ssock
    writeDebugConsole $ "connection from " ++ show caddr ++ "\n"
    h <- socketToHandle connsock WriteMode
    hPutStrLn h "hello, world"
    hClose h
    close ssock

  threadDelay 500000
  -- NS.startTcpLayer ns
  csock <- NS.connect ns ipaddr (fromIntegral 2222) Nothing
  writeDebugConsole "csock created\n"

{-
  csock <- socket (addrFamily addr) Stream defaultProtocol
  connect csock (addrAddress addr)
  h <- socketToHandle csock ReadMode
  msg <- hGetLine h
  hClose h
  writeDebugConsole msg
-}

The server part, including bind, listen, accept from network-hans, and the WebServer example all work, tested using telnet on my build of HaLVM. But the client part, in particular the connect function seems to block and can not return. Is my way of calling the socket api wrong ? Or I may just miss some setup step ?

Possible bug found in TCP receive

Possible bug in master branch at src/Hans/Tcp/RecvWindow.hs:77:
There is:

case trimSeg (fromTcpSeqNum (segEnd x - segStart y)) x of

Shouldn't it be:

case trimSeg (fromTcpSeqNum (segEnd x - segStart y)) y of

?
And later:

Just x' -> [x', y]

Shouldn't it be:

Just y' -> [x, y']

?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.