conlink 2.0.0 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Dockerfile +2 -1
- package/README.md +18 -14
- package/examples/net2dot.yaml +2 -2
- package/examples/test4-multiple/modes/all/deps +1 -0
- package/examples/test4-multiple/{base-compose.yaml → modes/base/compose.yaml} +3 -3
- package/examples/test4-multiple/{node1-compose.yaml → modes/node1/compose.yaml} +0 -3
- package/examples/test4-multiple/modes/node1/deps +1 -0
- package/examples/test4-multiple/{nodes2-compose.yaml → modes/nodes2/compose.yaml} +0 -5
- package/examples/test4-multiple/modes/nodes2/deps +1 -0
- package/examples/test4-multiple/modes/web/compose.yaml +5 -0
- package/examples/test4-multiple/modes/web/deps +1 -0
- package/examples/test6-cfn.yaml +1 -2
- package/mdc +108 -0
- package/net2dot +1 -1
- package/net2dot.cljs +113 -0
- package/package.json +6 -1
- package/scripts/copy.sh +48 -0
- package/scripts/wait.sh +73 -0
- package/shadow-cljs.edn +1 -1
- package/src/conlink/addrs.cljc +3 -0
- package/src/conlink/core.cljs +21 -7
- package/src/conlink/util.cljs +13 -2
- package/TODO +0 -34
- package/examples/test4-multiple/all-compose.yaml +0 -5
- package/examples/test4-multiple/web-network.yaml +0 -2
- package/host-build.yaml +0 -1
- package/inspect.json +0 -210
- package/notes.txt +0 -82
- package/old/Dockerfile.bak +0 -26
- package/old/add-link.sh +0 -82
- package/old/conlink +0 -12
- package/old/conlink.cljs +0 -131
- package/old/dot_gitignore +0 -1
- package/old/examples/test2-compose.yaml +0 -32
- package/old/examples/test2-network.yaml +0 -42
- package/old/move-link.sh +0 -108
- package/old/net2dot.py +0 -122
- package/old/notes-old.txt +0 -97
- package/old/package.json +0 -16
- package/old/schema.yaml +0 -138
- package/old/schema.yaml.bak +0 -76
- package/old/test2b-compose.yaml +0 -18
- package/old/veth-link.sh +0 -96
- package/schema-ish.yaml +0 -29
- package/src/conlink/net2dot.cljs +0 -158
- package/tests/invalid-schema-1.yaml +0 -6
- package/tests/invalid-schema-2.yaml +0 -6
- package/tests/invalid-schema-3.yaml +0 -17
- package/tests/invalid-schema-4.yaml +0 -14
- package/tests/invalid-schema-5.yaml +0 -12
- package/tests/invalid-schema-6.yaml +0 -12
- package/tmp/conlink/.env +0 -1
package/old/veth-link.sh
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
# Copyright (c) 2023, Viasat, Inc
|
|
4
|
-
# Licensed under MPL 2.0
|
|
5
|
-
|
|
6
|
-
set -e
|
|
7
|
-
|
|
8
|
-
usage () {
|
|
9
|
-
echo >&2 "${0} [OPTIONS] INTF0 INTF1 PID0 PID1"
|
|
10
|
-
echo >&2 ""
|
|
11
|
-
echo >&2 " INTF0 is the name of first veth interface"
|
|
12
|
-
echo >&2 " INTF1 is the name of second veth interface name"
|
|
13
|
-
echo >&2 " PID0 is the process ID of the first netns"
|
|
14
|
-
echo >&2 " PID1 is the process ID of the second netns"
|
|
15
|
-
echo >&2 ""
|
|
16
|
-
echo >&2 "OPTIONS:"
|
|
17
|
-
echo >&2 " --verbose - Verbose output (set -x)"
|
|
18
|
-
echo >&2 " --ip0 IP0 - IP (CIDR) address for INTF0"
|
|
19
|
-
echo >&2 " --ip1 IP1 - IP (CIDR) address for INTF1"
|
|
20
|
-
echo >&2 " --mac0 MAC0 - MAC address for INTF0"
|
|
21
|
-
echo >&2 " --mac1 MAC1 - MAC address for INTF1"
|
|
22
|
-
echo >&2 " --route0 'ROUTE' - route to add to INTF0"
|
|
23
|
-
echo >&2 " --route1 'ROUTE' - route to add to INTF1"
|
|
24
|
-
echo >&2 " --mtu MTU - MTU for both interfaces"
|
|
25
|
-
exit 2
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
VERBOSE=${VERBOSE:-}
|
|
29
|
-
IP0= IP1= MAC0= MAC1= ROUTE0= ROUTE1= MTU=
|
|
30
|
-
|
|
31
|
-
info() { echo "veth-link [${PID0}/${IF0} <-> ${PID1}/${IF1}] ${*}"; }
|
|
32
|
-
warn() { >&2 echo "veth-link [${PID0}/${IF0} <-> ${PID1}/${IF1}] ${*}"; }
|
|
33
|
-
die() { warn "ERROR: ${*}"; exit 1; }
|
|
34
|
-
|
|
35
|
-
# Set name, MAC, IP, ROUTE, MTU, and up state for interface within netns
|
|
36
|
-
setup_if() {
|
|
37
|
-
local SIF=$1 IF=$2 NS=$3 MAC=$4 IP=$5 ROUTE=$6 MTU=$7
|
|
38
|
-
|
|
39
|
-
ip -netns ${NS} --force -b - <<EOF
|
|
40
|
-
link set dev ${SIF} name ${IF}
|
|
41
|
-
${IP:+addr add ${IP} dev ${IF}}
|
|
42
|
-
${MAC:+link set dev ${IF} address ${MAC}}
|
|
43
|
-
${MTU:+link set dev ${IF} mtu ${MTU}}
|
|
44
|
-
link set dev ${IF} up
|
|
45
|
-
${ROUTE:+route add ${ROUTE} dev ${IF}}
|
|
46
|
-
EOF
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
# Parse arguments
|
|
50
|
-
positional=
|
|
51
|
-
while [ "${*}" ]; do
|
|
52
|
-
param=$1; OPTARG=$2
|
|
53
|
-
case ${param} in
|
|
54
|
-
--verbose) VERBOSE=1 ;;
|
|
55
|
-
--ip0) IP0="${OPTARG}"; shift ;;
|
|
56
|
-
--ip1) IP1="${OPTARG}"; shift ;;
|
|
57
|
-
--mac0) MAC0="${OPTARG}"; shift ;;
|
|
58
|
-
--mac1) MAC1="${OPTARG}"; shift ;;
|
|
59
|
-
--route0) ROUTE0="${OPTARG}"; shift ;;
|
|
60
|
-
--route1) ROUTE1="${OPTARG}"; shift ;;
|
|
61
|
-
--mtu) MTU="${OPTARG}"; shift ;;
|
|
62
|
-
-h|--help) usage ;;
|
|
63
|
-
*) positional="${positional} $1" ;;
|
|
64
|
-
esac
|
|
65
|
-
shift
|
|
66
|
-
done
|
|
67
|
-
set -- ${positional}
|
|
68
|
-
IF0=$1 IF1=$2 PID0=$3 PID1=$4
|
|
69
|
-
|
|
70
|
-
[ "${VERBOSE}" ] && set -x || true
|
|
71
|
-
|
|
72
|
-
# Check arguments
|
|
73
|
-
[ "${IF0}" -a "${IF1}" -a "${PID0}" -a "${PID1}" ] || usage
|
|
74
|
-
|
|
75
|
-
# Sanity checks
|
|
76
|
-
[ ! -d /proc/$PID0 ] && die "PID0 $PID0 is no longer running!"
|
|
77
|
-
[ ! -d /proc/$PID1 ] && die "PID1 $PID1 is no longer running!"
|
|
78
|
-
|
|
79
|
-
### Do the work
|
|
80
|
-
|
|
81
|
-
info "Creating veth pair link (${IP0}|${MAC0} <-> ${IP1}|${MAC1})"
|
|
82
|
-
|
|
83
|
-
info "Creating ip netns to pid mappings"
|
|
84
|
-
mkdir -p /var/run/netns
|
|
85
|
-
ln -sf /proc/${PID0}/ns/net /var/run/netns/ns${PID0}
|
|
86
|
-
ln -sf /proc/${PID1}/ns/net /var/run/netns/ns${PID1}
|
|
87
|
-
|
|
88
|
-
info "Creating veth pair with ends in each namespace"
|
|
89
|
-
SIF0=if0-${RANDOM} SIF1=if1-${RANDOM}
|
|
90
|
-
ip link add ${SIF0} netns ns${PID0} type veth peer ${SIF1} netns ns${PID1}
|
|
91
|
-
|
|
92
|
-
info "Setting netns, name, MAC, IP, ROUTE, MTU, and up state"
|
|
93
|
-
setup_if ${SIF0} ${IF0} ns${PID0} "${MAC0}" "${IP0}" "${ROUTE0}" "${MTU}"
|
|
94
|
-
setup_if ${SIF1} ${IF1} ns${PID1} "${MAC1}" "${IP1}" "${ROUTE1}" "${MTU}"
|
|
95
|
-
|
|
96
|
-
info "Created veth pair link (${IP0}|${MAC0} <-> ${IP1}|${MAC1})"
|
package/schema-ish.yaml
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
links:
|
|
2
|
-
- mode: local (default), host, tunnel
|
|
3
|
-
service: node1,
|
|
4
|
-
# OR
|
|
5
|
-
container: examples_node1_1
|
|
6
|
-
remote: SWITCH (local), HOST_INTF (host), REMOTE_IP (tunnel)
|
|
7
|
-
intf: eth0
|
|
8
|
-
ip: INTF_IP
|
|
9
|
-
mac: INTF_MAC
|
|
10
|
-
nat: ...
|
|
11
|
-
tc: ...
|
|
12
|
-
|
|
13
|
-
# mode local
|
|
14
|
-
ovs: ...
|
|
15
|
-
|
|
16
|
-
# mode host
|
|
17
|
-
type: vlan, macvlan, macvtap, ipvlan, ipvtap
|
|
18
|
-
host-mode: private, vepa, bridge, etc
|
|
19
|
-
vlanid: 5
|
|
20
|
-
|
|
21
|
-
# mode tunnel
|
|
22
|
-
type: geneve
|
|
23
|
-
vni: 1001
|
|
24
|
-
|
|
25
|
-
switches:
|
|
26
|
-
- name: s1
|
|
27
|
-
opts: ...
|
|
28
|
-
|
|
29
|
-
containers:
|
package/src/conlink/net2dot.cljs
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env nbb
|
|
2
|
-
|
|
3
|
-
(ns conlink.net2dot
|
|
4
|
-
(:require [clojure.string :as S]
|
|
5
|
-
[clojure.pprint :refer [pprint]]
|
|
6
|
-
[promesa.core :as P]
|
|
7
|
-
[conlink.util :refer [parse-opts Eprintln Epprint fatal]]
|
|
8
|
-
[conlink.core :as conlink]))
|
|
9
|
-
|
|
10
|
-
(def usage "
|
|
11
|
-
net2dot: convert conlink network config to GraphViz/dot representation.
|
|
12
|
-
|
|
13
|
-
Usage:
|
|
14
|
-
net2dot [options]
|
|
15
|
-
|
|
16
|
-
Options:
|
|
17
|
-
-v, --verbose Show verbose output (stderr)
|
|
18
|
-
[env: VERBOSE]
|
|
19
|
-
--network-file NETWORK-FILE... Network config file
|
|
20
|
-
--compose-file COMPOSE-FILE... Docker compose file with network config
|
|
21
|
-
")
|
|
22
|
-
|
|
23
|
-
(def DEFAULT-PROPS "shape=box fontsize=12 style=filled penwidth=1")
|
|
24
|
-
(def CONLINK-PROPS "style=\"rounded,filled\" fillcolor = \"#c1b5c7\" color = \"#9673a6\"")
|
|
25
|
-
(def BRIDGE-PROPS "style= filled fillcolor=\"#dae8fc\" color=\"#6c8ebf\"")
|
|
26
|
-
(def HOST-PROPS "style=filled fillcolor=\"#f5f5f5\" color=\"#666666\"")
|
|
27
|
-
(def TUNNEL-PROPS "fillcolor=\"#a5a5a5\" color=\"#888888\"")
|
|
28
|
-
(def CONTAINER-PROPS "style=\"rounded,filled\" fillcolor = \"#e1d5e7\" color = \"#9673a6\"")
|
|
29
|
-
(def SERVICE-PROPS (str CONTAINER-PROPS " fillcolor = \"#d1c5e7\" penwidth = 2"))
|
|
30
|
-
(def INTF-PROPS "width=0.1 height=0.1 fontsize=10 fillcolor=\"#ffbb9e\" color=\"#d7db00\"")
|
|
31
|
-
(def NIC-PROPS "fontsize=12 fillcolor=\"#ffbb9e\" color=\"#d7db00\"")
|
|
32
|
-
|
|
33
|
-
(set! conlink/INTF-MAX-LEN 100)
|
|
34
|
-
|
|
35
|
-
(defn dot-id [n]
|
|
36
|
-
(-> n
|
|
37
|
-
(S/replace #"[:]" "_COLON_")
|
|
38
|
-
(S/replace #"[-]" "_DASH_")
|
|
39
|
-
(S/replace #"[*]" "_STAR_")
|
|
40
|
-
(S/replace #"[$]" "_DOLLAR_")
|
|
41
|
-
(S/replace #"[{]" "_LCURLY_")
|
|
42
|
-
(S/replace #"[}]" "_LCURLY_")
|
|
43
|
-
(S/replace #"[ ]" "_SPACE_")))
|
|
44
|
-
|
|
45
|
-
(defn digraph [links tunnels]
|
|
46
|
-
(let [veth-links (filter #(= :veth (:type %)) links)
|
|
47
|
-
vlan-links (filter #(conlink/VLAN-TYPES (:type %)) links)]
|
|
48
|
-
(S/join
|
|
49
|
-
"\n"
|
|
50
|
-
(flatten
|
|
51
|
-
[(str "digraph D {")
|
|
52
|
-
(str " splines = true;")
|
|
53
|
-
(str " compound = true;")
|
|
54
|
-
(str " node [" DEFAULT-PROPS "];")
|
|
55
|
-
|
|
56
|
-
""
|
|
57
|
-
" // host system"
|
|
58
|
-
(str " subgraph cluster_host {")
|
|
59
|
-
(str " label = \"host system\";")
|
|
60
|
-
(str " " HOST-PROPS ";")
|
|
61
|
-
|
|
62
|
-
""
|
|
63
|
-
" // main link nodes"
|
|
64
|
-
(for [{:keys [dev dev-id]} links]
|
|
65
|
-
(str " " (dot-id dev-id) " [label=\"" dev "\" " INTF-PROPS "];"))
|
|
66
|
-
|
|
67
|
-
""
|
|
68
|
-
" // containers and their links/interfaces"
|
|
69
|
-
(for [[container-name links] (group-by (comp :name :container) links)]
|
|
70
|
-
[(str " subgraph cluster_" (dot-id container-name) " {")
|
|
71
|
-
(str " label = \"" (:container-label (first links)) "\";")
|
|
72
|
-
(if (:service (first links))
|
|
73
|
-
(str " " SERVICE-PROPS ";")
|
|
74
|
-
(str " " CONTAINER-PROPS ";"))
|
|
75
|
-
(for [link links]
|
|
76
|
-
(str " " (dot-id (:dev-id link))))
|
|
77
|
-
(str " }")])
|
|
78
|
-
|
|
79
|
-
""
|
|
80
|
-
" // bridges, tunnels, veth connections"
|
|
81
|
-
(str " subgraph cluster_conlink {")
|
|
82
|
-
(str " label = \"conlink/network\";")
|
|
83
|
-
(str " " CONLINK-PROPS ";")
|
|
84
|
-
(for [bridge (set (keep :bridge veth-links))
|
|
85
|
-
:let [blinks (filter #(= bridge (:bridge %)) veth-links)]]
|
|
86
|
-
[(str " subgraph cluster_bridge_" (dot-id bridge) " {")
|
|
87
|
-
(str " label = \"" bridge "\";")
|
|
88
|
-
(str " " BRIDGE-PROPS ";")
|
|
89
|
-
(str " bridge_" (dot-id bridge) " [shape=point style=invis];")
|
|
90
|
-
(for [{:keys [dev-id outer-dev]} blinks]
|
|
91
|
-
[(str " " (dot-id outer-dev)
|
|
92
|
-
" [label=\"" outer-dev "\" " INTF-PROPS "];")
|
|
93
|
-
(str " " (dot-id dev-id) " -> " (dot-id outer-dev))])
|
|
94
|
-
(for [{:keys [bridge outer-dev]} tunnels]
|
|
95
|
-
(str " " (dot-id outer-dev)
|
|
96
|
-
" [label=\"" outer-dev "\" " INTF-PROPS "];"))
|
|
97
|
-
(str " }")])
|
|
98
|
-
(str " }")
|
|
99
|
-
|
|
100
|
-
""
|
|
101
|
-
" // vlan/vtap links"
|
|
102
|
-
(for [outer-dev (set (keep :outer-dev vlan-links))
|
|
103
|
-
:let [olinks (filter #(= outer-dev (:outer-dev %)) vlan-links)]]
|
|
104
|
-
[(str " " (dot-id outer-dev) " [label=\"" outer-dev "\" " NIC-PROPS "];")
|
|
105
|
-
(for [{:keys [dev-id outer-dev type vlanid vni ip]} olinks
|
|
106
|
-
:let [label (str (name type) (when vlanid
|
|
107
|
-
(str " " vlanid)))]]
|
|
108
|
-
(str " " (dot-id dev-id) " -> " (dot-id outer-dev)
|
|
109
|
-
" [label=\"" label "\"];"))])
|
|
110
|
-
|
|
111
|
-
" // end of host system"
|
|
112
|
-
(str " }")
|
|
113
|
-
|
|
114
|
-
""
|
|
115
|
-
" // remote hosts and tunnels links"
|
|
116
|
-
(for [{:keys [outer-dev remote]} tunnels]
|
|
117
|
-
[(str " " (dot-id remote)
|
|
118
|
-
" [label=\"remote host '" remote "'\" " TUNNEL-PROPS "];")
|
|
119
|
-
(str " " (dot-id outer-dev) " -> " (dot-id remote)) ])
|
|
120
|
-
|
|
121
|
-
"}\n"]))))
|
|
122
|
-
|
|
123
|
-
(defn enrich-link [{:as link :keys [service container]}]
|
|
124
|
-
(let [name (if service
|
|
125
|
-
(str "S_" service) #_(str "*_" service "_*")
|
|
126
|
-
container)
|
|
127
|
-
clabel (if service
|
|
128
|
-
(str "service '"service "'")
|
|
129
|
-
(str "container '" container "'"))
|
|
130
|
-
container {:id "CID"
|
|
131
|
-
:pid 3
|
|
132
|
-
:index 1
|
|
133
|
-
:name name}]
|
|
134
|
-
(merge
|
|
135
|
-
(conlink/link-instance-enrich link container 2)
|
|
136
|
-
{:container-label clabel})))
|
|
137
|
-
|
|
138
|
-
(defn enrich-tunnel [tunnel]
|
|
139
|
-
(conlink/tunnel-instance-enrich tunnel 2))
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
(defn main
|
|
143
|
-
[& args]
|
|
144
|
-
(P/let
|
|
145
|
-
[{:keys [verbose compose-file network-file]} (parse-opts usage args)
|
|
146
|
-
_ (when (and (empty? network-file) (empty? compose-file))
|
|
147
|
-
(fatal 2 "either --network-file or --compose-file is required"))
|
|
148
|
-
network-config (P/-> (conlink/load-configs compose-file network-file)
|
|
149
|
-
(conlink/enrich-network-config))
|
|
150
|
-
links (map enrich-link (:links network-config))
|
|
151
|
-
tunnels (map enrich-tunnel (:tunnels network-config))
|
|
152
|
-
dot-graph (digraph links tunnels)]
|
|
153
|
-
(when verbose
|
|
154
|
-
(Eprintln "Links:")
|
|
155
|
-
(Epprint links)
|
|
156
|
-
(Eprintln "Tunnels:")
|
|
157
|
-
(Epprint tunnels))
|
|
158
|
-
(println dot-graph)))
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
# type and veth type requires bridge
|
|
2
|
-
|
|
3
|
-
links:
|
|
4
|
-
# should pass
|
|
5
|
-
- {service: node, type: dummy}
|
|
6
|
-
- {service: node, type: veth, bridge: s1}
|
|
7
|
-
- {service: node, bridge: s1}
|
|
8
|
-
- {service: node, type: vlan, vlanid: 100}
|
|
9
|
-
|
|
10
|
-
# Should error
|
|
11
|
-
- {service: node, type: magic}
|
|
12
|
-
- {service: node, type: veth}
|
|
13
|
-
- {service: node}
|
|
14
|
-
- {service: node, type: vlan}
|
|
15
|
-
- {service: node, bridge: s1, vlanid: 100}
|
|
16
|
-
|
|
17
|
-
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
links:
|
|
2
|
-
# should pass
|
|
3
|
-
- {service: node, bridge: s1, ip: 10.0.1.1/16}
|
|
4
|
-
- {service: node, bridge: s1, mac: "00:11:99:00:00:99"}
|
|
5
|
-
- {service: node, bridge: s1, mac: "00:11:99:0a:0b:ff"}
|
|
6
|
-
|
|
7
|
-
# Should error
|
|
8
|
-
- {service: node, bridge: s1, ip: 10.0.1}
|
|
9
|
-
- {service: node, bridge: s1, ip: 10.0.1.1}
|
|
10
|
-
- {service: node, bridge: s1, ip: 1011.0.1.1/16}
|
|
11
|
-
- {service: node, bridge: s1, mac: "00:11:99:0a:0b"}
|
|
12
|
-
- {service: node, bridge: s1, mac: "00:11:99:0a:0b:fg"}
|
|
13
|
-
|
|
14
|
-
|
package/tmp/conlink/.env
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
blah
|