From 7c97b1c35ae35a17aa0ee65ca4fd4ef793849b07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sat, 4 Jun 2022 22:14:40 +0200 Subject: Variables containing IP addresses of nodes --- src/Main.hs | 30 +++++++++++++++++------------- 1 file 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 () -- cgit v1.2.3