blob: 6e1fb1a3f9747b071df02863727637882409b793 [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
Doyoung Lee9b0973f2019-08-20 14:47:59 -070023CORD_PLATFORM_VERSION ?= 7.0.0
24COMAC_PLATFORM_VERSION ?= 0.0.2
Hyunsun Moon81c8e232019-05-21 03:40:22 -060025
26HELM_GLOBAL_ARGS ?=
27HELM_NEM_ARGS ?= $(HELM_GLOBAL_ARGS)
28HELM_ONOS_ARGS ?= $(HELM_GLOBAL_ARGS)
29
30cpu_family := $(shell lscpu | grep 'CPU family:' | awk '{print $$3}')
31cpu_model := $(shell lscpu | grep 'Model:' | awk '{print $$2}')
32os_vendor := $(shell lsb_release -i -s)
Hyunsun Moonad70fc12019-08-02 16:52:19 -060033os_release := $(shell lsb_release -r -s)
Hyunsun Moon81c8e232019-05-21 03:40:22 -060034
Hyunsun Moon07decd42019-08-19 13:59:52 -060035ciab: $(M)/system-check $(M)/omec $(M)/oaisim
Hyunsun Moon81c8e232019-05-21 03:40:22 -060036
37.PHONY: ciab run-test reset-test clean
38
39$(M):
40 mkdir -p $(M)
41
Hyunsun Moon07decd42019-08-19 13:59:52 -060042$(M)/system-check: | $(M)
Hyunsun Moon81c8e232019-05-21 03:40:22 -060043 @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
Doyoung Lee9b0973f2019-08-20 14:47:59 -0700119$(WORKSPACE)/cord/cord-platform: | $(M)/setup
120 mkdir -p $(WORKSPACE)/cord
121 cd $(WORKSPACE)/cord; git clone https://gerrit.opencord.org/cord-platform
122
123$(WORKSPACE)/cord/comac-helm-charts: | $(M)/setup
124 mkdir -p $(WORKSPACE)/cord
125 cd $(WORKSPACE)/cord; git clone https://gerrit.opencord.org/comac-helm-charts
126
127$(M)/cord-platform: | $(M)/helm-ready $(WORKSPACE)/cord/cord-platform
128 cd $(WORKSPACE)/cord/cord-platform && \
129 helm dep update cord-platform && \
130 helm upgrade --install $(HELM_GLOBAL_ARGS) cord-platform --version $(CORD_PLATFORM_VERSION) cord-platform -f $(CIABVALUES)
131 touch $@
132
133$(M)/comac-platform: | $(M)/helm-ready $(WORKSPACE)/cord/comac-helm-charts $(M)/cord-platform
134 cd $(WORKSPACE)/cord/comac-helm-charts && \
135 helm dep update comac-platform && \
136 helm upgrade --install $(HELM_GLOBAL_ARGS) comac-platform --version $(COMAC_PLATFORM_VERSION) comac-platform -f $(CIABVALUES)
137 touch $@
138
Hyunsun Moon81c8e232019-05-21 03:40:22 -0600139# TODO: need to connect ONOS
140$(M)/ovs-setup: | $(M)/setup
141 sudo apt install -y openvswitch-switch
142 sudo ovs-vsctl --may-exist add-br br-s1u-net
143 sudo ovs-vsctl --may-exist add-port br-s1u-net s1u-enb -- set Interface s1u-enb type=internal
144 sudo ip link set s1u-enb address 0a:00:00:00:00:01
145 sudo ip addr add 119.0.0.253/24 dev s1u-enb || true
146 sudo ip link set s1u-enb up
147 touch $@
148
149/opt/cni/bin/simpleovs: | $(M)/k8s-ready
150 sudo cp $(RESOURCEDIR)/simpleovs /opt/cni/bin/
151
Hyunsun Moon07decd42019-08-19 13:59:52 -0600152/opt/cni/bin/static: | $(M)/k8s-ready
153 mkdir -p $(BUILD)/cni-plugins; cd $(BUILD)/cni-plugins; \
154 wget https://github.com/containernetworking/plugins/releases/download/v0.8.2/cni-plugins-linux-amd64-v0.8.2.tgz && \
155 tar xvfz cni-plugins-linux-amd64-v0.8.2.tgz
156 sudo cp $(BUILD)/cni-plugins/static /opt/cni/bin/
157
158$(M)/omec: | $(M)/ovs-setup $(M)/helm-ready $(WORKSPACE)/cord/helm-charts /opt/cni/bin/simpleovs /opt/cni/bin/static
159 cd $(WORKSPACE)/cord/helm-charts/omec; \
160 helm dep up omec-data-plane && \
161 helm dep up omec-control-plane && \
162 helm upgrade --install $(HELM_GLOBAL_ARGS) omec-data-plane omec-data-plane -f $(CIABVALUES) && \
163 helm upgrade --install $(HELM_GLOBAL_ARGS) omec-control-plane omec-control-plane -f $(CIABVALUES)
Hyunsun Moon81c8e232019-05-21 03:40:22 -0600164 $(WORKSPACE)/cord/helm-charts/scripts/wait_for_pods.sh default
165 touch $@
166
167# UE images includes kernel module, ue_ip.ko
168# which should be built in the exactly same kernel version of the host machine
169$(BUILD)/openairinterface: | $(M)/setup
170 mkdir -p $(BUILD)
171 cd $(BUILD); git clone https://github.com/opencord/openairinterface.git
172
173$(M)/ue-image: | $(M)/k8s-ready $(BUILD)/openairinterface
174 cd $(BUILD)/openairinterface; \
175 sudo docker build . --target lte-uesoftmodem \
176 --build-arg build_base=omecproject/oai-base:1.0.0 \
177 --file Dockerfile.ue \
178 --tag omecproject/lte-uesoftmodem:1.0.0
179 touch $@
180
181$(M)/oaisim: | $(M)/omec $(M)/ue-image
182 sudo ip addr add 127.0.0.2/8 dev lo || true
183 $(eval mme_iface=$(shell ip -4 route list default | awk -F 'dev' '{ print $$2; exit }' | awk '{ print $$1 }'))
184 cd $(WORKSPACE)/cord/helm-charts; \
185 helm upgrade --install $(HELM_GLOBAL_ARGS) oaisim oaisim -f $(CIABVALUES) \
Hyunsun Moon07decd42019-08-19 13:59:52 -0600186 --set config.enb.networks.s1_mme.interface=$(mme_iface)
Hyunsun Moon81c8e232019-05-21 03:40:22 -0600187 $(WORKSPACE)/cord/helm-charts/scripts/wait_for_pods.sh default
188 @timeout 60s bash -c \
189 "until ip addr show oip1 | grep -q inet; \
190 do \
191 echo 'Waiting for UE 1 gets IP address'; \
192 sleep 3; \
193 done"
194 touch $@
195
196$(M)/router: | /opt/cni/bin/simpleovs $(M)/ovs-setup
197 kubectl apply -f $(RESOURCEDIR)/quagga.yaml
Hyunsun Moon07decd42019-08-19 13:59:52 -0600198 kubectl wait pod --for=condition=Ready -l app=quagga --timeout=60s
Hyunsun Moon81c8e232019-05-21 03:40:22 -0600199 $(eval spgwu_ip=$(shell kubectl get pod -ojson spgwu-0 2>/dev/null | \
200 jq -r '.metadata.annotations["k8s.v1.cni.cncf.io/networks-status"]' | \
201 jq -r '.[] | select(.name=="sgi-net") | .ips[0]'))
202 kubectl exec router ip route add 16.0.0.0/8 via $(spgwu_ip)
203 touch $@
204
Hyunsun Moon07decd42019-08-19 13:59:52 -0600205test: | $(M)/omec $(M)/oaisim $(M)/router
206 @timeout 120s bash -c \
Hyunsun Moon9f8b5952019-08-13 19:03:47 -0600207 "until timeout 3 ping -I oip1 13.1.1.254 -c 1 > /dev/null 2>&1; do \
208 echo 'Waiting for DP to be ready'; \
209 done"
210 ping -I oip1 13.1.1.254 -c 3
Hyunsun Moon81c8e232019-05-21 03:40:22 -0600211
212reset-test:
Hyunsun Moonad70fc12019-08-02 16:52:19 -0600213 kubectl delete po router || true
214 helm delete --purge oaisim || true
Hyunsun Moon07decd42019-08-19 13:59:52 -0600215 helm delete --purge omec-control-plane || true
216 helm delete --purge omec-data-plane || true
Hyunsun Moon81c8e232019-05-21 03:40:22 -0600217 cd $(M); rm -f router oaisim omec
218
219clean: reset-test
220 helm delete --purge $(shell helm ls -q) || true
221 sudo ovs-vsctl del-br br-s1u-net || true
222 sudo ovs-vsctl del-br br-sgi-net || true
223 sudo apt remove --purge openvswitch-switch -y
224 source "$(VENV)/bin/activate" && cd $(BUILD)/kubespray; \
225 ansible-playbook -b -i inventory/local/hosts.ini reset.yml
226 @if [ -d /usr/local/etc/emulab ]; then \
227 mount | grep /mnt/extra/kubelet/pods | cut -d" " -f3 | sudo xargs umount; \
228 sudo rm -rf /mnt/extra/kubelet; \
229 fi
230 rm -rf $(M)