blob: 029a41ba08af4e3b14361a5d0ab2fb4e8d5e8524 [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
Hyunsun Moon07decd42019-08-19 13:59:52 -060011KUBESPRAY_VERSION ?= release-2.11
12DOCKER_VERSION ?= 18.09
13K8S_VERSION ?= v1.15.3
14HELM_VERSION ?= v2.14.2
Hyunsun Moon81c8e232019-05-21 03:40:22 -060015
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
Hyunsun Moon81c8e232019-05-21 03:40:22 -060023HELM_GLOBAL_ARGS ?=
24HELM_NEM_ARGS ?= $(HELM_GLOBAL_ARGS)
25HELM_ONOS_ARGS ?= $(HELM_GLOBAL_ARGS)
26
27cpu_family := $(shell lscpu | grep 'CPU family:' | awk '{print $$3}')
28cpu_model := $(shell lscpu | grep 'Model:' | awk '{print $$2}')
29os_vendor := $(shell lsb_release -i -s)
Hyunsun Moonad70fc12019-08-02 16:52:19 -060030os_release := $(shell lsb_release -r -s)
Hyunsun Moon81c8e232019-05-21 03:40:22 -060031
Hyunsun Moon07decd42019-08-19 13:59:52 -060032ciab: $(M)/system-check $(M)/omec $(M)/oaisim
Hyunsun Moon81c8e232019-05-21 03:40:22 -060033
Hyunsun Moon235d47a2019-09-03 15:47:30 -060034.PHONY: ciab test reset-test clean
Hyunsun Moon81c8e232019-05-21 03:40:22 -060035
36$(M):
37 mkdir -p $(M)
38
Hyunsun Moon07decd42019-08-19 13:59:52 -060039$(M)/system-check: | $(M)
Hyunsun Moon81c8e232019-05-21 03:40:22 -060040 @if [[ $(cpu_family) -eq 6 ]]; then \
41 if [[ $(cpu_model) -lt 60 ]]; then \
42 echo "FATAL: haswell CPU or newer is required."; \
43 exit 1; \
44 fi \
45 else \
46 echo "FATAL: unsupported CPU family."; \
47 exit 1; \
48 fi
49 @if [[ $(os_vendor) =~ (Ubuntu) ]]; then \
Hyunsun Moonad70fc12019-08-02 16:52:19 -060050 if [[ ! $(os_release) =~ (16.04) ]]; then \
51 echo "WARN: $(os_vendor) $(os_release) has not been tested."; \
52 fi; \
53 if dpkg --compare-versions 4.15 gt $(shell uname -r); then \
54 echo "FATAL: kernel 4.15 or later is required."; \
55 echo "Please upgrade your kernel by running" \
56 "apt install --install-recommends linux-generic-hwe-$(os_release)"; \
57 exit 1; \
Hyunsun Moon81c8e232019-05-21 03:40:22 -060058 fi \
59 else \
60 echo "FAIL: unsupported OS."; \
61 exit 1; \
62 fi
63 touch $@
64
65$(M)/setup: | $(M)
66 sudo $(SCRIPTDIR)/cloudlab-disksetup.sh
67 sudo apt update; sudo apt install -y software-properties-common python-pip jq httpie ipvsadm
68 touch $@
69
70$(BUILD)/kubespray: | $(M)/setup
71 mkdir -p $(BUILD)
72 cd $(BUILD); git clone https://github.com/kubernetes-incubator/kubespray.git -b $(KUBESPRAY_VERSION)
73
74$(VENV)/bin/activate: | $(M)/setup
75 sudo pip install virtualenv
76 virtualenv $(VENV) --no-site-packages
77
78$(M)/kubespray-requirements: $(BUILD)/kubespray | $(VENV)/bin/activate
79 source "$(VENV)/bin/activate" && \
80 pip install -r $(BUILD)/kubespray/requirements.txt
81 touch $@
82
83$(M)/k8s-ready: | $(M)/setup $(BUILD)/kubespray $(VENV)/bin/activate $(M)/kubespray-requirements
84 source "$(VENV)/bin/activate" && cd $(BUILD)/kubespray; \
85 ansible-playbook -b -i inventory/local/hosts.ini \
86 -e "{'override_system_hostname' : False, 'disable_swap' : True}" \
87 -e "{'docker_version' : $(DOCKER_VERSION)}" \
88 -e "{'docker_iptables_enabled' : True}" \
89 -e "{'kube_version' : $(K8S_VERSION)}" \
Hyunsun Moon5d179d42019-08-12 14:18:19 -050090 -e "{'kube_network_plugin_multus' : True, 'multus_version' : stable}" \
Hyunsun Moon81c8e232019-05-21 03:40:22 -060091 -e "{'kube_proxy_mode': iptables}" \
92 -e "{'kube_pods_subnet' : 192.168.0.0/17, 'kube_service_addresses' : 192.168.128.0/17}" \
93 -e "{'kube_apiserver_node_port_range' : 2000-36767}" \
94 -e "{'kubeadm_enabled': True}" \
95 -e "{'kube_feature_gates' : [SCTPSupport=True]}" \
96 -e "{'kubelet_custom_flags' : [--allowed-unsafe-sysctls=net.*]}" \
97 -e "{'dns_min_replicas' : 1}" \
98 -e "{'helm_enabled' : True, 'helm_version' : $(HELM_VERSION)}" \
99 cluster.yml
100 mkdir -p $(HOME)/.kube
101 sudo cp -f /etc/kubernetes/admin.conf $(HOME)/.kube/config
102 sudo chown $(shell id -u):$(shell id -g) $(HOME)/.kube/config
103 kubectl wait pod -n kube-system --for=condition=Ready --all
104 touch $@
105
106$(M)/helm-ready: | $(M)/k8s-ready
107 helm init --wait --client-only
108 helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com/
109 helm repo add cord https://charts.opencord.org
110 touch $@
111
112$(WORKSPACE)/cord/helm-charts: | $(M)/setup
113 mkdir -p $(WORKSPACE)/cord
114 cd $(WORKSPACE)/cord; git clone https://gerrit.opencord.org/helm-charts
115
Doyoung Lee9b0973f2019-08-20 14:47:59 -0700116$(WORKSPACE)/cord/cord-platform: | $(M)/setup
117 mkdir -p $(WORKSPACE)/cord
118 cd $(WORKSPACE)/cord; git clone https://gerrit.opencord.org/cord-platform
119
120$(WORKSPACE)/cord/comac-helm-charts: | $(M)/setup
121 mkdir -p $(WORKSPACE)/cord
122 cd $(WORKSPACE)/cord; git clone https://gerrit.opencord.org/comac-helm-charts
123
124$(M)/cord-platform: | $(M)/helm-ready $(WORKSPACE)/cord/cord-platform
125 cd $(WORKSPACE)/cord/cord-platform && \
126 helm dep update cord-platform && \
Doyoung Leec7c4b5d2019-09-05 20:53:19 -0700127 helm upgrade --install $(HELM_GLOBAL_ARGS) cord-platform cord-platform -f $(CIABVALUES)
Doyoung Lee9b0973f2019-08-20 14:47:59 -0700128 touch $@
129
130$(M)/comac-platform: | $(M)/helm-ready $(WORKSPACE)/cord/comac-helm-charts $(M)/cord-platform
131 cd $(WORKSPACE)/cord/comac-helm-charts && \
132 helm dep update comac-platform && \
Doyoung Leec7c4b5d2019-09-05 20:53:19 -0700133 helm upgrade --install $(HELM_GLOBAL_ARGS) comac-platform comac-platform -f $(CIABVALUES)
Doyoung Lee9b0973f2019-08-20 14:47:59 -0700134 touch $@
135
Hyunsun Moon81c8e232019-05-21 03:40:22 -0600136# TODO: need to connect ONOS
137$(M)/ovs-setup: | $(M)/setup
138 sudo apt install -y openvswitch-switch
139 sudo ovs-vsctl --may-exist add-br br-s1u-net
140 sudo ovs-vsctl --may-exist add-port br-s1u-net s1u-enb -- set Interface s1u-enb type=internal
141 sudo ip link set s1u-enb address 0a:00:00:00:00:01
142 sudo ip addr add 119.0.0.253/24 dev s1u-enb || true
143 sudo ip link set s1u-enb up
144 touch $@
145
146/opt/cni/bin/simpleovs: | $(M)/k8s-ready
147 sudo cp $(RESOURCEDIR)/simpleovs /opt/cni/bin/
148
Hyunsun Moon07decd42019-08-19 13:59:52 -0600149/opt/cni/bin/static: | $(M)/k8s-ready
150 mkdir -p $(BUILD)/cni-plugins; cd $(BUILD)/cni-plugins; \
151 wget https://github.com/containernetworking/plugins/releases/download/v0.8.2/cni-plugins-linux-amd64-v0.8.2.tgz && \
152 tar xvfz cni-plugins-linux-amd64-v0.8.2.tgz
153 sudo cp $(BUILD)/cni-plugins/static /opt/cni/bin/
154
155$(M)/omec: | $(M)/ovs-setup $(M)/helm-ready $(WORKSPACE)/cord/helm-charts /opt/cni/bin/simpleovs /opt/cni/bin/static
156 cd $(WORKSPACE)/cord/helm-charts/omec; \
157 helm dep up omec-data-plane && \
158 helm dep up omec-control-plane && \
159 helm upgrade --install $(HELM_GLOBAL_ARGS) omec-data-plane omec-data-plane -f $(CIABVALUES) && \
160 helm upgrade --install $(HELM_GLOBAL_ARGS) omec-control-plane omec-control-plane -f $(CIABVALUES)
Hyunsun Moon81c8e232019-05-21 03:40:22 -0600161 $(WORKSPACE)/cord/helm-charts/scripts/wait_for_pods.sh default
162 touch $@
163
164# UE images includes kernel module, ue_ip.ko
165# which should be built in the exactly same kernel version of the host machine
166$(BUILD)/openairinterface: | $(M)/setup
167 mkdir -p $(BUILD)
168 cd $(BUILD); git clone https://github.com/opencord/openairinterface.git
169
170$(M)/ue-image: | $(M)/k8s-ready $(BUILD)/openairinterface
171 cd $(BUILD)/openairinterface; \
172 sudo docker build . --target lte-uesoftmodem \
173 --build-arg build_base=omecproject/oai-base:1.0.0 \
174 --file Dockerfile.ue \
175 --tag omecproject/lte-uesoftmodem:1.0.0
176 touch $@
177
178$(M)/oaisim: | $(M)/omec $(M)/ue-image
179 sudo ip addr add 127.0.0.2/8 dev lo || true
180 $(eval mme_iface=$(shell ip -4 route list default | awk -F 'dev' '{ print $$2; exit }' | awk '{ print $$1 }'))
181 cd $(WORKSPACE)/cord/helm-charts; \
182 helm upgrade --install $(HELM_GLOBAL_ARGS) oaisim oaisim -f $(CIABVALUES) \
Hyunsun Moon07decd42019-08-19 13:59:52 -0600183 --set config.enb.networks.s1_mme.interface=$(mme_iface)
Hyunsun Moon81c8e232019-05-21 03:40:22 -0600184 $(WORKSPACE)/cord/helm-charts/scripts/wait_for_pods.sh default
185 @timeout 60s bash -c \
186 "until ip addr show oip1 | grep -q inet; \
187 do \
188 echo 'Waiting for UE 1 gets IP address'; \
189 sleep 3; \
190 done"
191 touch $@
192
193$(M)/router: | /opt/cni/bin/simpleovs $(M)/ovs-setup
194 kubectl apply -f $(RESOURCEDIR)/quagga.yaml
Hyunsun Moon07decd42019-08-19 13:59:52 -0600195 kubectl wait pod --for=condition=Ready -l app=quagga --timeout=60s
Hyunsun Moon81c8e232019-05-21 03:40:22 -0600196 $(eval spgwu_ip=$(shell kubectl get pod -ojson spgwu-0 2>/dev/null | \
197 jq -r '.metadata.annotations["k8s.v1.cni.cncf.io/networks-status"]' | \
198 jq -r '.[] | select(.name=="sgi-net") | .ips[0]'))
199 kubectl exec router ip route add 16.0.0.0/8 via $(spgwu_ip)
200 touch $@
201
Hyunsun Moon07decd42019-08-19 13:59:52 -0600202test: | $(M)/omec $(M)/oaisim $(M)/router
203 @timeout 120s bash -c \
Hyunsun Moon9f8b5952019-08-13 19:03:47 -0600204 "until timeout 3 ping -I oip1 13.1.1.254 -c 1 > /dev/null 2>&1; do \
205 echo 'Waiting for DP to be ready'; \
206 done"
207 ping -I oip1 13.1.1.254 -c 3
Hyunsun Moon81c8e232019-05-21 03:40:22 -0600208
209reset-test:
Hyunsun Moonad70fc12019-08-02 16:52:19 -0600210 kubectl delete po router || true
211 helm delete --purge oaisim || true
Hyunsun Moon07decd42019-08-19 13:59:52 -0600212 helm delete --purge omec-control-plane || true
213 helm delete --purge omec-data-plane || true
Hyunsun Moon81c8e232019-05-21 03:40:22 -0600214 cd $(M); rm -f router oaisim omec
215
216clean: reset-test
217 helm delete --purge $(shell helm ls -q) || true
218 sudo ovs-vsctl del-br br-s1u-net || true
219 sudo ovs-vsctl del-br br-sgi-net || true
220 sudo apt remove --purge openvswitch-switch -y
221 source "$(VENV)/bin/activate" && cd $(BUILD)/kubespray; \
222 ansible-playbook -b -i inventory/local/hosts.ini reset.yml
223 @if [ -d /usr/local/etc/emulab ]; then \
224 mount | grep /mnt/extra/kubelet/pods | cut -d" " -f3 | sudo xargs umount; \
225 sudo rm -rf /mnt/extra/kubelet; \
226 fi
227 rm -rf $(M)