bash_profile
8.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
#!/bin/bash
# ONOS developer BASH profile conveniences
# Simply include in your own .bash_aliases or .bash_profile
# Root of the ONOS source tree
export ONOS_ROOT=${ONOS_ROOT:-~/onos}
# Setup some environmental context for developers
if [ -z "${JAVA_HOME}" ]; then
if [ -x /usr/libexec/java_home ]; then
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
elif [ -d /usr/lib/jvm/java-8-oracle ]; then
export JAVA_HOME="/usr/lib/jvm/java-8-oracle"
elif [ -d /usr/lib/jvm/java-8-openjdk-amd64 ]; then
export JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64"
fi
fi
export MAVEN=${MAVEN:-~/Applications/apache-maven-3.3.9}
export KARAF_VERSION=${KARAF_VERSION:-3.0.5}
export KARAF_ROOT=${KARAF_ROOT:-~/Applications/apache-karaf-$KARAF_VERSION}
export KARAF_LOG=$KARAF_ROOT/data/log/karaf.log
# Setup a path
export PATH="$PATH:$ONOS_ROOT/tools/dev/bin"
export PATH="$PATH:$ONOS_ROOT/tools/test/bin:$ONOS_ROOT/tools/test/scenarios/bin"
export PATH="$PATH:$ONOS_ROOT/tools/build"
export PATH="$PATH:$MAVEN/bin:$KARAF_ROOT/bin"
# Setup cell enviroment
export ONOS_CELL=${ONOS_CELL:-local}
# Setup default web user/password
export ONOS_WEB_USER=onos
export ONOS_WEB_PASS=rocks
# Setup default location of test scenarios
export ONOS_SCENARIOS=$ONOS_ROOT/tools/test/scenarios
# Convenience utility to warp to various ONOS source projects
# e.g. 'o api', 'o dev', 'o'
function o {
cd $(find $ONOS_ROOT/ -type d -and \( -name 'buck-out' -o -name '.git' -o -name 'target' -o -name 'gen-src' -o -name 'src' \) -prune -o -type d | \
egrep "${1:-$ONOS_ROOT}" | head -n 1)
}
# Short-hand for 'mvn clean install' for us lazy folk
alias mci='mvn clean install'
alias mcis='mvn clean install -DskipTests -Dcheckstyle.skip'
alias mis='mvn install -DskipTests -Dcheckstyle.skip'
# Short-hand for ONOS build, package and test.
alias ob='onos-build'
alias obf='ob -DskipTests -Dcheckstyle.skip'
alias obi='onos-build -Dmaven.test.failure.ignore=true'
alias obs='onos-build-selective'
alias obd='onos-build-docs'
alias op='onos-package'
alias ok='onos-karaf'
alias ot='onos-test'
alias ol='onos-log'
alias ow='onos-watch'
alias ocl='onos-check-logs'
alias oi='setPrimaryInstance'
alias pub='onos-push-update-bundle'
# Short-hand for tailing and searching the ONOS (karaf) log
alias tl='$ONOS_ROOT/tools/dev/bin/onos-local-log'
alias gl='grep $KARAF_LOG --colour=auto -E -e '
function filterLocalLog {
tl | grep --colour=always -E -e "${1-org.onlab|org.onosproject}"
}
alias tlo='filterLocalLog'
alias tle='tlo "ERROR|WARN|Exception|Error"'
function filterLog {
ol | grep --colour=always -E -e "${1-org.onlab|org.onosproject}"
}
alias olo='filterLog'
alias ole='olo "ERROR|WARN|Exception|Error"'
# Pretty-print JSON output
alias pp='python -m json.tool'
# Short-hand to launch Java API docs, REST API docs and ONOS GUI
alias docs='open $ONOS_ROOT/docs/target/site/apidocs/index.html'
alias rsdocs='onos-rsdocs'
alias gui='onos-gui'
# Test related conveniences
# SSH to a specified ONOS instance
alias sshctl='onos-ssh'
alias sshnet='onos-ssh $OCN'
# Applies the settings in the specified topology recipe file or lists current
# topo recipe definition if no topo recipe file is given.
function topo {
topo=${1:-""}
case "$topo" in
"")
env | egrep "ONOS_TOPO"
env | egrep "(OTD|OTL|OTH)="
;;
*)
[ ! -f $ONOS_ROOT/tools/test/topos/$1.recipe ] && echo "No such topo recipe: $1" >&2 && return 1
unset ONOS_TOPO OTD OTL OTH ONOS_DEVICES ONOS_HOSTS
unset $(env | sed -n 's:\(^OT[DLH][0-9]\{1,\}\)=.*:\1 :g p')
export ONOS_TOPO=$1
. $ONOS_ROOT/tools/test/topos/$1.recipe
let d=1; while [ $d -le $OTD ]; do
dev="$(printf 'of:%016x' $d)"
export OTD$d=$dev; export ONOS_DEVICES="$ONOS_DEVICES $dev"
let d=d+1;
done
let h=1; while [ $h -le $OTH ]; do
host="$(printf '00:00:00:00:00:%02x/-1' $h)"
export OTH$h=$host; export ONOS_HOSTS="$ONOS_HOSTS $host"
let h=h+1
done
topo
esac
}
# Lists available topo recipes
function topos {
for topo in $(ls -1 $ONOS_ROOT/tools/test/topos/*.recipe); do
name=$(basename $topo .recipe)
printf "%-16s %s\n" \
"$([ $name = $ONOS_TOPO ] && echo $name '*' || echo $name)" \
"$(grep '^#' $topo | head -n 1)"
done
}
# Sets the primary instance to the specified instance number.
function setPrimaryInstance {
export ONOS_INSTANCES=$(env | grep 'OC[0-9]*=' | sort | cut -d= -f2)
export OCI=$(env | egrep "OC[0-9]+" | sort | egrep OC${1:-1} | cut -d= -f2)
echo $OCI
}
# ON.Lab shared test cell warden address
export CELL_WARDEN="10.254.1.19"
# Clears cell environment
function clearCell {
unset ONOS_CELL ONOS_NIC ONOS_IP ONOS_APPS ONOS_BOOT_FEATURES
unset OCI OCN OCT ONOS_INSTANCES ONOS_FEATURES
unset $(env | sed -n 's:\(^OC[0-9]\{1,\}\)=.*:\1 :g p')
}
# Applies the settings in the specified cell file or lists current cell definition
# if no cell file is given.
function cell {
cell=${1:-""}
case "$cell" in
"borrow")
clearCell
aux="/tmp/cell-$$"
duration=${2:-0}
spec=${3:-3+1}
spec=${spec/+/%2B}
user=${4:-$(id -un)}
query="duration=$duration&spec=$spec&user=$user"
curl -sS -X POST "http://$CELL_WARDEN:4321/?$query" -d "$(cat ~/.ssh/id_rsa.pub)" > $aux
. $aux
rm -f $aux
setPrimaryInstance 1 >/dev/null
onos-verify-cell
topo default >/dev/null
;;
"return")
curl -sS -X DELETE "http://$CELL_WARDEN:4321/?user=${2:-$(id -un)}"
clearCell
;;
"status")
curl -sS "http://$CELL_WARDEN:4321/" | sort
;;
"")
env | egrep "ONOS_CELL"
env | egrep "OCI"
env | egrep "OC[0-9]+" | sort
env | egrep "OC[NT]"
env | egrep "ONOS_" | egrep -v 'ONOS_ROOT|ONOS_CELL|ONOS_INSTANCES|ONOS_DEVICES|ONOS_HOSTS' | sort
;;
*)
[ ! -f $ONOS_ROOT/tools/test/cells/$1 ] && echo "No such cell: $1" >&2 && return 1
clearCell
export ONOS_USER=${ONOS_USER:-sdn}
export ONOS_GROUP=${ONOS_GROUP:-sdn}
export ONOS_WEB_USER=${ONOS_WEB_USER:-onos}
export ONOS_WEB_PASS=${ONOS_WEB_PASS:-rocks}
export ONOS_CELL=$1
. $ONOS_ROOT/tools/test/cells/$1
setPrimaryInstance 1 >/dev/null
cell
topo default >/dev/null
esac
}
[ -n "$ONOS_CELL" -a "$ONOS_CELL" != "borrow" ] && cell $ONOS_CELL > /dev/null
# Lists available cells
function cells {
for cell in $(ls -1 $ONOS_ROOT/tools/test/cells); do
printf "%-16s %s\n" \
"$([ $cell = $ONOS_CELL ] && echo $cell '*' || echo $cell)" \
"$(grep '^#' $ONOS_ROOT/tools/test/cells/$cell | head -n 1)"
done
}
# Find a process by regex
function spy {
ps -ef | egrep "$@" | grep -v egrep
}
# Kill a process by regex
function nuke {
spy "$@" | cut -c7-11 | xargs kill
}
# Edit a cell file by providing a cell name; opens the cell file in $EDITOR.
function vicell {
local apply=false
local create=false
local ${cdf:=$ONOS_CELL}
local cpath="${ONOS_ROOT}/tools/test/cells/"
if [ "$1" = "-h" ] ; then
printf "usage: vicell [file] [options]\n\noptions:\n"
printf "\t[file]: cell name (default: current cell)\n"
printf "\t-a: apply the cell after editing\n"
printf "\t-e: [editor] set EDITOR to [editor] (default: *vi*)\n"
printf "\t-c: create cell file if none exist\n\n"
return 1
fi
while [ $# -gt 0 ]; do
case "$1" in
-a) apply=true ;;
-e) EDITOR=$2; shift ;;
-c) create=true ;;
*) cdf="$1" ;;
esac
shift
done
if [ ! -e "${cpath}${cdf}" ] && ! ($create) ; then
printf "${cdf} : no such cell\n" && return 1
fi
if [ -z "${EDITOR}" ] || [ -x "$(which ${EDITOR})" ]; then
unset EDITOR && vi ${cpath}${cdf}
else
$EDITOR ${cpath}${cdf}
fi
($apply) && cell ${cdf}
}
# Autocomplete for certain utilities
. ${ONOS_ROOT}/tools/test/bin/ogroup-opts
# Load AT&T MPLS topo GEO data
alias atttopo='onos-netcfg $OCI $ONOS_ROOT/tools/test/topos/attmpls-cfg.json'
# Load UK topo GEO data
alias uktopo='onos-netcfg $OCI $ONOS_ROOT/tools/test/topos/uk-cfg.json'
# Git annotated one-line log
alias gil='git log --oneline --decorate=short'
# Buck (if "buck" is not on the PATH)
[ -z "$(which buck)" ] && alias buck="onos-buck"