blob: 7eca5ee034e76a5d518dfc6281ea2725df263b9d [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)
32os_distro := $(shell lsb_release -c -s)
33
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 \
53 if [[ ! $(os_distro) =~ (xenial) ]]; then \
54 echo "WARN: $(os_vendor) $(os_distro) has not been tested."; \
55 fi \
56 else \
57 echo "FAIL: unsupported OS."; \
58 exit 1; \
59 fi
60 touch $@
61
62$(M)/setup: | $(M)
63 sudo $(SCRIPTDIR)/cloudlab-disksetup.sh
64 sudo apt update; sudo apt install -y software-properties-common python-pip jq httpie ipvsadm
65 touch $@
66
67$(BUILD)/kubespray: | $(M)/setup
68 mkdir -p $(BUILD)
69 cd $(BUILD); git clone https://github.com/kubernetes-incubator/kubespray.git -b $(KUBESPRAY_VERSION)
70
71$(VENV)/bin/activate: | $(M)/setup
72 sudo pip install virtualenv
73 virtualenv $(VENV) --no-site-packages
74
75$(M)/kubespray-requirements: $(BUILD)/kubespray | $(VENV)/bin/activate
76 source "$(VENV)/bin/activate" && \
77 pip install -r $(BUILD)/kubespray/requirements.txt
78 touch $@
79
80$(M)/k8s-ready: | $(M)/setup $(BUILD)/kubespray $(VENV)/bin/activate $(M)/kubespray-requirements
81 source "$(VENV)/bin/activate" && cd $(BUILD)/kubespray; \
82 ansible-playbook -b -i inventory/local/hosts.ini \
83 -e "{'override_system_hostname' : False, 'disable_swap' : True}" \
84 -e "{'docker_version' : $(DOCKER_VERSION)}" \
85 -e "{'docker_iptables_enabled' : True}" \
86 -e "{'kube_version' : $(K8S_VERSION)}" \
87 -e "{'kube_network_plugin_multus' : True}" \
88 -e "{'kube_proxy_mode': iptables}" \
89 -e "{'kube_pods_subnet' : 192.168.0.0/17, 'kube_service_addresses' : 192.168.128.0/17}" \
90 -e "{'kube_apiserver_node_port_range' : 2000-36767}" \
91 -e "{'kubeadm_enabled': True}" \
92 -e "{'kube_feature_gates' : [SCTPSupport=True]}" \
93 -e "{'kubelet_custom_flags' : [--allowed-unsafe-sysctls=net.*]}" \
94 -e "{'dns_min_replicas' : 1}" \
95 -e "{'helm_enabled' : True, 'helm_version' : $(HELM_VERSION)}" \
96 cluster.yml
97 mkdir -p $(HOME)/.kube
98 sudo cp -f /etc/kubernetes/admin.conf $(HOME)/.kube/config
99 sudo chown $(shell id -u):$(shell id -g) $(HOME)/.kube/config
100 kubectl wait pod -n kube-system --for=condition=Ready --all
101 touch $@
102
103$(M)/helm-ready: | $(M)/k8s-ready
104 helm init --wait --client-only
105 helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com/
106 helm repo add cord https://charts.opencord.org
107 touch $@
108
109$(WORKSPACE)/cord/helm-charts: | $(M)/setup
110 mkdir -p $(WORKSPACE)/cord
111 cd $(WORKSPACE)/cord; git clone https://gerrit.opencord.org/helm-charts
112
113# TODO: need to connect ONOS
114$(M)/ovs-setup: | $(M)/setup
115 sudo apt install -y openvswitch-switch
116 sudo ovs-vsctl --may-exist add-br br-s1u-net
117 sudo ovs-vsctl --may-exist add-port br-s1u-net s1u-enb -- set Interface s1u-enb type=internal
118 sudo ip link set s1u-enb address 0a:00:00:00:00:01
119 sudo ip addr add 119.0.0.253/24 dev s1u-enb || true
120 sudo ip link set s1u-enb up
121 touch $@
122
123/opt/cni/bin/simpleovs: | $(M)/k8s-ready
124 sudo cp $(RESOURCEDIR)/simpleovs /opt/cni/bin/
125
126$(M)/omec: | $(M)/ovs-setup $(M)/helm-ready $(WORKSPACE)/cord/helm-charts /opt/cni/bin/simpleovs
127 cd $(WORKSPACE)/cord/helm-charts/mcord-release; \
128 helm upgrade --install $(HELM_GLOBAL_ARGS) mcord-services mcord-services -f $(CIABVALUES)
129 $(WORKSPACE)/cord/helm-charts/scripts/wait_for_pods.sh default
130 touch $@
131
132# UE images includes kernel module, ue_ip.ko
133# which should be built in the exactly same kernel version of the host machine
134$(BUILD)/openairinterface: | $(M)/setup
135 mkdir -p $(BUILD)
136 cd $(BUILD); git clone https://github.com/opencord/openairinterface.git
137
138$(M)/ue-image: | $(M)/k8s-ready $(BUILD)/openairinterface
139 cd $(BUILD)/openairinterface; \
140 sudo docker build . --target lte-uesoftmodem \
141 --build-arg build_base=omecproject/oai-base:1.0.0 \
142 --file Dockerfile.ue \
143 --tag omecproject/lte-uesoftmodem:1.0.0
144 touch $@
145
146$(M)/oaisim: | $(M)/omec $(M)/ue-image
147 sudo ip addr add 127.0.0.2/8 dev lo || true
148 $(eval mme_iface=$(shell ip -4 route list default | awk -F 'dev' '{ print $$2; exit }' | awk '{ print $$1 }'))
149 cd $(WORKSPACE)/cord/helm-charts; \
150 helm upgrade --install $(HELM_GLOBAL_ARGS) oaisim oaisim -f $(CIABVALUES) \
151 --set conf.enb.networks.s1_mme.interface=$(mme_iface)
152 $(WORKSPACE)/cord/helm-charts/scripts/wait_for_pods.sh default
153 @timeout 60s bash -c \
154 "until ip addr show oip1 | grep -q inet; \
155 do \
156 echo 'Waiting for UE 1 gets IP address'; \
157 sleep 3; \
158 done"
159 touch $@
160
161$(M)/router: | /opt/cni/bin/simpleovs $(M)/ovs-setup
162 kubectl apply -f $(RESOURCEDIR)/quagga.yaml
163 kubectl wait pod --for=condition=Ready -l app=quagga
164 $(eval spgwu_ip=$(shell kubectl get pod -ojson spgwu-0 2>/dev/null | \
165 jq -r '.metadata.annotations["k8s.v1.cni.cncf.io/networks-status"]' | \
166 jq -r '.[] | select(.name=="sgi-net") | .ips[0]'))
167 kubectl exec router ip route add 16.0.0.0/8 via $(spgwu_ip)
168 touch $@
169
170run-test: | $(M)/router
171 ping -I oip1 13.1.1.254 -c 5
172
173reset-test:
174 -kubectl delete po router
175 -helm delete --purge oaisim mcord-services
176 cd $(M); rm -f router oaisim omec
177
178clean: reset-test
179 helm delete --purge $(shell helm ls -q) || true
180 sudo ovs-vsctl del-br br-s1u-net || true
181 sudo ovs-vsctl del-br br-sgi-net || true
182 sudo apt remove --purge openvswitch-switch -y
183 source "$(VENV)/bin/activate" && cd $(BUILD)/kubespray; \
184 ansible-playbook -b -i inventory/local/hosts.ini reset.yml
185 @if [ -d /usr/local/etc/emulab ]; then \
186 mount | grep /mnt/extra/kubelet/pods | cut -d" " -f3 | sudo xargs umount; \
187 sudo rm -rf /mnt/extra/kubelet; \
188 fi
189 rm -rf $(M)