summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2022-06-04 22:14:40 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2022-06-05 17:57:19 +0200
commit7c97b1c35ae35a17aa0ee65ca4fd4ef793849b07 (patch)
tree3aca0141d0e2b71022c2009230dd20493ddf315f /src
parent384d1bddebc3909ebd5dc16ca9a9cd0b64c8786c (diff)
Variables containing IP addresses of nodes
Diffstat (limited to 'src')
-rw-r--r--src/Main.hs30
1 files changed, 17 insertions, 13 deletions
diff --git a/src/Main.hs b/src/Main.hs
index dc1cc42..3fa3468 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -181,7 +181,7 @@ exitNetwork net = do
getNode :: Network -> NodeName -> TestRun Node
getNode net nname@(NodeName tnname) = (find ((nname==).nodeName) <$> liftIO (readMVar (netNodes net))) >>= \case
Just node -> return node
- _ -> liftIO $ do
+ _ -> do
let name = T.unpack tnname
dir = netDir net </> ("erebos_" ++ name)
node = Node { nodeName = nname
@@ -189,18 +189,22 @@ getNode net nname@(NodeName tnname) = (find ((nname==).nodeName) <$> liftIO (rea
, nodeDir = dir
}
- exists <- doesPathExist dir
- when exists $ ioError $ userError $ dir ++ " exists"
- createDirectoryIfMissing True dir
-
- modifyMVar_ (netNodes net) $ \nodes -> do
- callCommand $ "ip netns add \""++ name ++ "\""
- callCommand $ "ip link add \"veth_" ++ name ++ ".0\" group 1 type veth peer name \"veth_" ++ name ++ ".1\" netns \"" ++ name ++ "\""
- callCommand $ "ip link set dev \"veth_" ++ name ++ ".0\" master br0 up"
- callOn node $ "ip addr add 192.168.0." ++ show (11 + length nodes) ++ "/24 broadcast 192.168.0.255 dev \"veth_" ++ name ++ ".1\""
- callOn node $ "ip link set dev \"veth_" ++ name++ ".1\" up"
- callOn node $ "ip link set dev lo up"
- return $ node : nodes
+ ip <- liftIO $ do
+ exists <- doesPathExist dir
+ when exists $ ioError $ userError $ dir ++ " exists"
+ createDirectoryIfMissing True dir
+
+ modifyMVar (netNodes net) $ \nodes -> do
+ let ip = "192.168.0." ++ show (11 + length nodes)
+ callCommand $ "ip netns add \""++ name ++ "\""
+ callCommand $ "ip link add \"veth_" ++ name ++ ".0\" group 1 type veth peer name \"veth_" ++ name ++ ".1\" netns \"" ++ name ++ "\""
+ callCommand $ "ip link set dev \"veth_" ++ name ++ ".0\" master br0 up"
+ callOn node $ "ip addr add " ++ ip ++ "/24 broadcast 192.168.0.255 dev \"veth_" ++ name ++ ".1\""
+ callOn node $ "ip link set dev \"veth_" ++ name++ ".1\" up"
+ callOn node $ "ip link set dev lo up"
+ return $ (node : nodes, ip)
+
+ modify $ \s -> s { tsVars = (VarName [tnname, T.pack "ip"], T.pack ip) : tsVars s }
return node
callOn :: Node -> String -> IO ()