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
|
#!/bin/bash
# -----------------------------------------------------------------------------
# Downloads and sets-up Apache Karaf as a basis for running ONOS locally
# as a single-instance.
#
# Note that this in no way impacts the method for running ONOS remotely.
# For that, one should use onos-package and onos-install tools.
# -----------------------------------------------------------------------------
[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
. $ONOS_ROOT/tools/build/envDefaults
# TODO: consider putting this under ~/Applications/onos/apache-karaf-...
export KARAF_ROOT=${KARAF_ROOT:-~/Applications/apache-karaf-$KARAF_VERSION}
export STAGE=$(dirname $KARAF_ROOT)
# Validates the specified IP regular expression against existing adapters.
# Excludes local-loopback.
function validateIp {
ifconfig | awk '{ print $2}' | grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}" | grep $1
}
# Clean the previous Karaf directory if requested and if it exists.
if [ "$1" = "clean" ]; then
shift
CLEAN="true"
[ -d $KARAF_ROOT ] && rm -fr $KARAF_ROOT $STAGE/apps $STAGE/config
fi
ONOS_IP=${ONOS_IP:-127.0.0.1}
IP="${1:-$ONOS_IP}"
# If IP was not given, nor configured attempt to use ONOS_NIC env. variable
if [ -z "$IP" -a -n "$ONOS_NIC" ]; then
IP=$(validateIp $ONOS_NIC)
[ -z "$IP" ] && echo "No adapter with IP matching $ONOS_NIC found!"
else
# Otherwise, verify that the IP address given exists among the adapters.
saveIp=$IP
IP=$(validateIp $IP)
[ -z "$IP" ] && echo "No adapter with IP $saveIp found!"
fi
# If IP is still not surmised or if usage was requested, show usage and IPs.
if [ -z "$IP" -o "$1" = "-?" -o "$1" = "-h" -o "$1" = "--help" ]; then
echo "usage: $(basename $0) [clean] <ip-address>"
echo "Available IP addresses are:"
validateIp .
exit 1
fi
SUBNET="$(echo $IP | cut -d. -f1-3)"
# Bail on any errors
set -e
# Check if Apache Karaf is already installed.
if [ ! -d $KARAF_ROOT ]; then
# Check if Apache Karaf bits are available and if not, fetch them.
if [ ! -f $KARAF_TAR ]; then
echo "Downloading $KARAF_TAR..."
curl -sL http://downloads.onosproject.org/third-party/apache-karaf-$KARAF_VERSION.tar.gz > $KARAF_TAR
fi
[ ! -f $KARAF_ZIP -a ! -f $KARAF_TAR ] && \
echo "Apache Karaf bits $KARAF_ZIP or $KARAF_TAR not found" && exit 1
echo "Unpacking $KARAF_TAR to $STAGE..."
mkdir -p $STAGE
cd $STAGE
tar zxf $KARAF_TAR
rm -rf $KARAF_ROOT/demos
fi
if ! grep -q "/onos-features/" $KARAF_ROOT/etc/org.apache.karaf.features.cfg; then
# Patch the Apache Karaf distribution file to add ONOS features repository
echo "Adding ONOS feature repository..."
perl -pi.old -e "s|^(featuresRepositories=.*)|\1,mvn:org.onosproject/onos-features/$ONOS_POM_VERSION/xml/features|" \
$KARAF_ROOT/etc/org.apache.karaf.features.cfg
fi
if ! grep -q ",onos-api," $KARAF_ROOT/etc/org.apache.karaf.features.cfg; then
# Patch the Apache Karaf distribution file to load default ONOS boot features
export BOOT_FEATURES="webconsole,onos-api,onos-core,onos-incubator,onos-cli,onos-rest,onos-gui"
echo "Adding ONOS boot features $BOOT_FEATURES..."
perl -pi.old -e "s|^(featuresBoot=.*)|\1,$BOOT_FEATURES|" \
$KARAF_ROOT/etc/org.apache.karaf.features.cfg
fi
if [ ! -f $KARAF_ROOT/lib/onos-branding-$ONOS_POM_VERSION.jar ]; then
# Patch the Apache Karaf distribution with ONOS branding bundle
echo "Branding as ONOS..."
rm -f $KARAF_ROOT/lib/onos-branding-*.jar
cp $M2_REPO/org/onosproject/onos-branding/$ONOS_POM_VERSION/onos-branding-$ONOS_POM_VERSION.jar \
$KARAF_ROOT/lib
fi
echo "Creating local cluster configs for IP $IP..."
[ -d $STAGE/config ] || mkdir -p $STAGE/config
cat > $STAGE/config/cluster.json <<EOF
{
"name": "default",
"nodes": [ {"id": "$IP", "ip": "$IP", "port": 9876 } ],
"partitions": [ { "name": "p1", "members": [ "$IP" ] } ]
}
EOF
if [ "$CLEAN" = "true" ]; then
echo "Copying package configs..."
cp -r $ONOS_ROOT/tools/package/etc/* $KARAF_ROOT/etc/
cp -r $ONOS_ROOT/tools/package/config/* $STAGE/config/
fi
echo "Staging builtin apps..."
rm -fr $STAGE/apps
onos-stage-apps $STAGE/apps $KARAF_ROOT/system
ACTIVE_APPS=${ONOS_APPS:-drivers,openflow}
echo "Customizing apps to be auto-activated: $ACTIVE_APPS..."
for app in ${ACTIVE_APPS//,/ }; do
touch $STAGE/apps/org.onosproject.$app/active
done
|