blob: 696b40fccfc9d2ed84910273dd0835e5f518d8ba [file] [log] [blame]
Hyunsun Moon81c8e232019-05-21 03:40:22 -06001SHELL := /bin/bash
2BUILD ?= /tmp/build
3M ?= $(BUILD)/milestones
4MAKEDIR := $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
5SCRIPTDIR := $(MAKEDIR)../scripts
6RESOURCEDIR := $(MAKEDIR)/resources
7WORKSPACE ?= $(HOME)
8VENV ?= $(BUILD)/venv/ciab
9CIABVALUES ?= $(MAKEDIR)/comac-in-a-box-values.yaml
10
11KUBESPRAY_VERSION ?= release-2.10
12DOCKER_VERSION ?= 18.06
13K8S_VERSION ?= v1.14.3
14HELM_VERSION ?= v2.13.1
15
16# used to start logging/monitoring and other infrastructure charts
17INFRA_CHARTS ?=
18INFRA_PREREQS = $(foreach chart,$(INFRA_CHARTS),$(M)/$(chart))
19
20KAFKA_CHART_VERSION ?= 0.13.3
21KAFKA_POD := "pod/cord-kafka-0"
22
23ETCD_OPERATOR_VERSION ?= 0.8.3
24
25HELM_GLOBAL_ARGS ?=
26HELM_NEM_ARGS ?= $(HELM_GLOBAL_ARGS)
27HELM_ONOS_ARGS ?= $(HELM_GLOBAL_ARGS)
28
29cpu_family := $(shell lscpu | grep 'CPU family:' | awk '{print $$3}')
30cpu_model := $(shell lscpu | grep 'Model:' | awk '{print $$2}')
31os_vendor := $(shell lsb_release -i -s)
Hyunsun Moonad70fc12019-08-02 16:52:19 -060032os_release := $(shell lsb_release -r -s)
Hyunsun Moon81c8e232019-05-21 03:40:22 -060033
34# TODO: include CORD platform
35ciab: $(M)/system_check $(M)/omec $(M)/oaisim
36
37.PHONY: ciab run-test reset-test clean
38
39$(M):
40 mkdir -p $(M)
41
42$(M)/system_check: | $(M)
43 @if [[ $(cpu_family) -eq 6 ]]; then \
44 if [[ $(cpu_model) -lt 60 ]]; then \
45 echo "FATAL: haswell CPU or newer is required."; \
46 exit 1; \
47 fi \
48 else \
49 echo "FATAL: unsupported CPU family."; \
50 exit 1; \
51 fi
52 @if [[ $(os_vendor) =~ (Ubuntu) ]]; then \
Hyunsun Moonad70fc12019-08-02 16:52:19 -060053 if [[ ! $(os_release) =~ (16.04) ]]; then \
54 echo "WARN: $(os_vendor) $(os_release) has not been tested."; \
55 fi; \
56 if dpkg --compare-versions 4.15 gt $(shell uname -r); then \
57 echo "FATAL: kernel 4.15 or later is required."; \
58 echo "Please upgrade your kernel by running" \
59 "apt install --install-recommends linux-generic-hwe-$(os_release)"; \
60 exit 1; \
Hyunsun Moon81c8e232019-05-21 03:40:22 -060061 fi \
62 else \
63 echo "FAIL: unsupported OS."; \
64 exit 1; \
65 fi
66 touch $@
67
68$(M)/setup: | $(M)
69 sudo $(SCRIPTDIR)/cloudlab-disksetup.sh
70 sudo apt update; sudo apt install -y software-properties-common python-pip jq httpie ipvsadm
71 touch $@
72
73$(BUILD)/kubespray: | $(M)/setup
74 mkdir -p $(BUILD)
75 cd $(BUILD); git clone https://github.com/kubernetes-incubator/kubespray.git -b $(KUBESPRAY_VERSION)
76
77$(VENV)/bin/activate: | $(M)/setup
78 sudo pip install virtualenv
79 virtualenv $(VENV) --no-site-packages
80
81$(M)/kubespray-requirements: $(BUILD)/kubespray | $(VENV)/bin/activate
82 source "$(VENV)/bin/activate" && \
83 pip install -r $(BUILD)/kubespray/requirements.txt
84 touch $@
85
86$(M)/k8s-ready: | $(M)/setup $(BUILD)/kubespray $(VENV)/bin/activate $(M)/kubespray-requirements
87 source "$(VENV)/bin/activate" && cd $(BUILD)/kubespray; \
88 ansible-playbook -b -i inventory/local/hosts.ini \
89 -e "{'override_system_hostname' : False, 'disable_swap' : True}" \
90 -e "{'docker_version' : $(DOCKER_VERSION)}" \
91 -e "{'docker_iptables_enabled' : True}" \
92 -e "{'kube_version' : $(K8S_VERSION)}" \
Hyunsun Moon5d179d42019-08-12 14:18:19 -050093 -e "{'kube_network_plugin_multus' : True, 'multus_version' : stable}" \
Hyunsun Moon81c8e232019-05-21 03:40:22 -060094 -e "{'kube_proxy_mode': iptables}" \
95 -e "{'kube_pods_subnet' : 192.168.0.0/17, 'kube_service_addresses' : 192.168.128.0/17}" \
96 -e "{'kube_apiserver_node_port_range' : 2000-36767}" \
97 -e "{'kubeadm_enabled': True}" \
98 -e "{'kube_feature_gates' : [SCTPSupport=True]}" \
99 -e "{'kubelet_custom_flags' : [--allowed-unsafe-sysctls=net.*]}" \
100 -e "{'dns_min_replicas' : 1}" \
101 -e "{'helm_enabled' : True, 'helm_version' : $(HELM_VERSION)}" \
102 cluster.yml
103 mkdir -p $(HOME)/.kube
104 sudo cp -f /etc/kubernetes/admin.conf $(HOME)/.kube/config
105 sudo chown $(shell id -u):$(shell id -g) $(HOME)/.kube/config
106 kubectl wait pod -n kube-system --for=condition=Ready --all
107 touch $@
108
109$(M)/helm-ready: | $(M)/k8s-ready
110 helm init --wait --client-only
111 helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com/
112 helm repo add cord https://charts.opencord.org
113 touch $@
114
115$(WORKSPACE)/cord/helm-charts: | $(M)/setup
116 mkdir -p $(WORKSPACE)/cord
117 cd $(WORKSPACE)/cord; git clone https://gerrit.opencord.org/helm-charts
118
119# TODO: need to connect ONOS
120$(M)/ovs-setup: | $(M)/setup
121 sudo apt install -y openvswitch-switch
122 sudo ovs-vsctl --may-exist add-br br-s1u-net
123 sudo ovs-vsctl --may-exist add-port br-s1u-net s1u-enb -- set Interface s1u-enb type=internal
124 sudo ip link set s1u-enb address 0a:00:00:00:00:01
125 sudo ip addr add 119.0.0.253/24 dev s1u-enb || true
126 sudo ip link set s1u-enb up
127 touch $@
128
129/opt/cni/bin/simpleovs: | $(M)/k8s-ready
130 sudo cp $(RESOURCEDIR)/simpleovs /opt/cni/bin/
131
132$(M)/omec: | $(M)/ovs-setup $(M)/helm-ready $(WORKSPACE)/cord/helm-charts /opt/cni/bin/simpleovs
133 cd $(WORKSPACE)/cord/helm-charts/mcord-release; \
134 helm upgrade --install $(HELM_GLOBAL_ARGS) mcord-services mcord-services -f $(CIABVALUES)
135 $(WORKSPACE)/cord/helm-charts/scripts/wait_for_pods.sh default
136 touch $@
137
138# UE images includes kernel module, ue_ip.ko
139# which should be built in the exactly same kernel version of the host machine
140$(BUILD)/openairinterface: | $(M)/setup
141 mkdir -p $(BUILD)
142 cd $(BUILD); git clone https://github.com/opencord/openairinterface.git
143
144$(M)/ue-image: | $(M)/k8s-ready $(BUILD)/openairinterface
145 cd $(BUILD)/openairinterface; \
146 sudo docker build . --target lte-uesoftmodem \
147 --build-arg build_base=omecproject/oai-base:1.0.0 \
148 --file Dockerfile.ue \
149 --tag omecproject/lte-uesoftmodem:1.0.0
150 touch $@
151
152$(M)/oaisim: | $(M)/omec $(M)/ue-image
153 sudo ip addr add 127.0.0.2/8 dev lo || true
154 $(eval mme_iface=$(shell ip -4 route list default | awk -F 'dev' '{ print $$2; exit }' | awk '{ print $$1 }'))
155 cd $(WORKSPACE)/cord/helm-charts; \
156 helm upgrade --install $(HELM_GLOBAL_ARGS) oaisim oaisim -f $(CIABVALUES) \
157 --set conf.enb.networks.s1_mme.interface=$(mme_iface)
158 $(WORKSPACE)/cord/helm-charts/scripts/wait_for_pods.sh default
159 @timeout 60s bash -c \
160 "until ip addr show oip1 | grep -q inet; \
161 do \
162 echo 'Waiting for UE 1 gets IP address'; \
163 sleep 3; \
164 done"
165 touch $@
166
167$(M)/router: | /opt/cni/bin/simpleovs $(M)/ovs-setup
168 kubectl apply -f $(RESOURCEDIR)/quagga.yaml
169 kubectl wait pod --for=condition=Ready -l app=quagga
170 $(eval spgwu_ip=$(shell kubectl get pod -ojson spgwu-0 2>/dev/null | \
171 jq -r '.metadata.annotations["k8s.v1.cni.cncf.io/networks-status"]' | \
172 jq -r '.[] | select(.name=="sgi-net") | .ips[0]'))
173 kubectl exec router ip route add 16.0.0.0/8 via $(spgwu_ip)
174 touch $@
175
Hyunsun Moone8d0c0d2019-08-12 14:11:18 -0500176test: | $(M)/router
Hyunsun Moon9f8b5952019-08-13 19:03:47 -0600177 @timeout 60s bash -c \
178 "until timeout 3 ping -I oip1 13.1.1.254 -c 1 > /dev/null 2>&1; do \
179 echo 'Waiting for DP to be ready'; \
180 done"
181 ping -I oip1 13.1.1.254 -c 3
Hyunsun Moon81c8e232019-05-21 03:40:22 -0600182
183reset-test:
Hyunsun Moonad70fc12019-08-02 16:52:19 -0600184 kubectl delete po router || true
185 helm delete --purge oaisim || true
186 helm delete --purge mcord-services || true
Hyunsun Moon81c8e232019-05-21 03:40:22 -0600187 cd $(M); rm -f router oaisim omec
188
189clean: reset-test
190 helm delete --purge $(shell helm ls -q) || true
191 sudo ovs-vsctl del-br br-s1u-net || true
192 sudo ovs-vsctl del-br br-sgi-net || true
193 sudo apt remove --purge openvswitch-switch -y
194 source "$(VENV)/bin/activate" && cd $(BUILD)/kubespray; \
195 ansible-playbook -b -i inventory/local/hosts.ini reset.yml
196 @if [ -d /usr/local/etc/emulab ]; then \
197 mount | grep /mnt/extra/kubelet/pods | cut -d" " -f3 | sudo xargs umount; \
198 sudo rm -rf /mnt/extra/kubelet; \
199 fi
200 rm -rf $(M)