diff --git a/flake.nix b/flake.nix index 5ea13f1..6d2ee90 100644 --- a/flake.nix +++ b/flake.nix @@ -218,6 +218,21 @@ ]; }; + # TODO: extract from kea! + networks.home-lan = { + name = "Home LAN"; + cidrv4 = "192.168.1.0/24"; + color = "#78dba9"; + }; + networks.home-fritzbox = { + name = "Home Fritzbox"; + cidrv4 = "192.168.178.0/24"; + color = "#f1cf8a"; + }; + nodes.ward.interfaces.lan.network = "home-lan"; + nodes.ward.interfaces.wan.network = "home-fritzbox"; + nodes.fritzbox.interfaces.eth0.network = "home-fritzbox"; + nodes.switch-attic = { name = "Switch Attic"; deviceType = "switch"; diff --git a/topology/options/networks.nix b/topology/options/networks.nix index c5c1d81..188c398 100644 --- a/topology/options/networks.nix +++ b/topology/options/networks.nix @@ -40,6 +40,10 @@ in color = mkOption { description = "The color of this network"; default = "random"; + apply = x: + if x == "random" + then "#ff00ff" # FIXME: TODO: lookuptable linear probing hashing into palette + else x; type = types.either (types.strMatching "^#[0-9a-f]{6}$") (types.enum ["random"]); }; diff --git a/topology/topology/renderers/elk/default.nix b/topology/topology/renderers/elk/default.nix index ba57f72..00d820b 100644 --- a/topology/topology/renderers/elk/default.nix +++ b/topology/topology/renderers/elk/default.nix @@ -99,24 +99,30 @@ }; width = 8; height = 8; - style.stroke = "#70a5eb"; - style.fill = "#74bee9"; + style.stroke = "#485263"; # FIXME: TODO color based on attached network color (autoshade)? + style.fill = "#b6beca"; labels = { "00-name" = mkLabel interface.id 1 {}; } // optionalAttrs (interface.mac != null) { "50-mac" = mkLabel interface.mac 1 {fill = "#70a5eb";}; + } + // optionalAttrs (interface.addresses != []) { + "60-addrs" = mkLabel (toString interface.addresses) 1 {fill = "#f9a872";}; }; }; } # Interface for node in network-centric view { children.network.children."node:${node.id}".ports."interface:${interface.id}" = { + # FIXME: TODO: deduplicate, same as above + # FIXME: TODO: deduplicate, same as above + # FIXME: TODO: deduplicate, same as above width = 8; height = 8; - style.stroke = "#70a5eb"; - style.fill = "#74bee9"; + style.stroke = "#485263"; # FIXME: TODO color based on attached network color (autoshade)? + style.fill = "#b6beca"; labels = { "00-name" = mkLabel interface.id 1 {}; @@ -132,7 +138,9 @@ # Edge in network-centric view (optionalAttrs (interface.network != null) ( - mkEdge ("children.network." + idForInterface node interface.id) "children.network.children.net:${interface.network}" {} + mkEdge ("children.network." + idForInterface node interface.id) "children.network.children.net:${interface.network}" { + style.stroke = config.networks.${interface.network}.color; + } )) ] ++ optionals (!interface.virtual) (flip map interface.physicalConnections ( @@ -145,7 +153,12 @@ mkEdge (idForInterface node interface.id) (idForInterface config.nodes.${conn.node} conn.interface) - {} + { + # FIXME: in interface definition ensure that the two ends of physical connections don't have different networks (output warning only) + style = optionalAttrs (interface.network != null) { + stroke = config.networks.${interface.network}.color; + }; + } ) )); diff --git a/topology/topology/renderers/svg/default.nix b/topology/topology/renderers/svg/default.nix index 8bcb456..c54a104 100644 --- a/topology/topology/renderers/svg/default.nix +++ b/topology/topology/renderers/svg/default.nix @@ -1,11 +1,12 @@ # TODO: +# - stack interfaces horizontally, information is now on the ports anyway. # - systemd extractor remove cidr mask # - address port label render make newline capable (multiple port labels) # - mac address show! # - split network layout or make rectpacking of childs # - NAT indication # - bottom hw image distorted in card view (move to top anyway) -# - embed font +# - embed font globally, try removing satori embed? # - network overview card (list all networks with name and cidr, legend style) # - colors! # - ip labels on edges @@ -115,20 +116,25 @@
''; - net = rec { + net = { mkCard = net: { width = 480; - html = + html = let + netColor = + if net.color != null + then net.color + else "#b6beca"; + in mkCardContainer /* html */ ''
- ${mkImageMaybe "w-8 h-8 mr-4" (config.lib.icons.get net.icon)} +

${net.name}

-
+ ${mkImageMaybe "w-12 h-12 ml-4" (config.lib.icons.get net.icon)}
${optionalString (net.cidrv4 != null) ''
CIDRv4${net.cidrv4}
''}