blob: 659ff7b72d57ae9dae98c8a528fcfcb158bbcec5 [file] [log] [blame]
Jeremy Ronquillo6be909e2020-08-24 09:36:13 -07001SHELL := /bin/bash
2BUILD ?= /tmp/build
3M ?= $(BUILD)/milestones
4MAKEDIR := $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
Jeremy Ronquilloaf084f32020-08-24 13:18:47 -07005SCRIPTDIR := $(MAKEDIR)/scripts
Jeremy Ronquillo6be909e2020-08-24 09:36:13 -07006RESOURCEDIR := $(MAKEDIR)/resources
7WORKSPACE ?= $(HOME)
Jeremy Ronquillod3cab742020-08-24 11:49:00 -07008VENV ?= $(BUILD)/venv/aiab
9AIABVALUES ?= $(MAKEDIR)/aether-in-a-box-values.yaml
Jeremy Ronquillo6be909e2020-08-24 09:36:13 -070010
Hyunsun84f0f172020-09-23 15:40:08 -050011KUBESPRAY_VERSION ?= release-2.14
12DOCKER_VERSION ?= 19.03
13K8S_VERSION ?= v1.18.9
Jeremy Ronquillo6be909e2020-08-24 09:36:13 -070014HELM_VERSION ?= v2.16.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
23HELM_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)
30os_release := $(shell lsb_release -r -s)
31
Jeremy Ronquillod3cab742020-08-24 11:49:00 -070032aiab: $(M)/system-check $(M)/omec
Jeremy Ronquillo6be909e2020-08-24 09:36:13 -070033oaisim: $(M)/oaisim
34
Jeremy Ronquillod3cab742020-08-24 11:49:00 -070035.PHONY: aiab oaisim test reset-test clean
Jeremy Ronquillo6be909e2020-08-24 09:36:13 -070036
37$(M):
38 mkdir -p $(M)
39
40$(M)/system-check: | $(M)
41 @if [[ $(cpu_family) -eq 6 ]]; then \
42 if [[ $(cpu_model) -lt 60 ]]; then \
43 echo "FATAL: haswell CPU or newer is required."; \
44 exit 1; \
45 fi \
46 else \
47 echo "FATAL: unsupported CPU family."; \
48 exit 1; \
49 fi
50 @if [[ $(os_vendor) =~ (Ubuntu) ]]; then \
51 if [[ ! $(os_release) =~ (16.04) ]]; then \
52 echo "WARN: $(os_vendor) $(os_release) has not been tested."; \
53 fi; \
54 if dpkg --compare-versions 4.15 gt $(shell uname -r); then \
55 echo "FATAL: kernel 4.15 or later is required."; \
56 echo "Please upgrade your kernel by running" \
57 "apt install --install-recommends linux-generic-hwe-$(os_release)"; \
58 exit 1; \
59 fi \
60 else \
61 echo "FAIL: unsupported OS."; \
62 exit 1; \
63 fi
64 touch $@
65
66$(M)/setup: | $(M)
67 sudo $(SCRIPTDIR)/cloudlab-disksetup.sh
68 sudo apt update; sudo apt install -y software-properties-common python-pip jq httpie ipvsadm
69 touch $@
70
71$(BUILD)/kubespray: | $(M)/setup
72 mkdir -p $(BUILD)
73 cd $(BUILD); git clone https://github.com/kubernetes-incubator/kubespray.git -b $(KUBESPRAY_VERSION)
74
75$(VENV)/bin/activate: | $(M)/setup
76 sudo pip install virtualenv
77 virtualenv $(VENV)
78
79$(M)/kubespray-requirements: $(BUILD)/kubespray | $(VENV)/bin/activate
80 source "$(VENV)/bin/activate" && \
81 pip install -r $(BUILD)/kubespray/requirements.txt
82 touch $@
83
84$(M)/k8s-ready: | $(M)/setup $(BUILD)/kubespray $(VENV)/bin/activate $(M)/kubespray-requirements
85 source "$(VENV)/bin/activate" && cd $(BUILD)/kubespray; \
86 ansible-playbook -b -i inventory/local/hosts.ini \
87 -e "{'override_system_hostname' : False, 'disable_swap' : True}" \
88 -e "{'docker_version' : $(DOCKER_VERSION)}" \
89 -e "{'docker_iptables_enabled' : True}" \
90 -e "{'kube_version' : $(K8S_VERSION)}" \
Hyunsun84f0f172020-09-23 15:40:08 -050091 -e "{'kube_network_plugin_multus' : True, 'multus_version' : stable, 'multus_cni_version' : 0.3.1}" \
Jeremy Ronquillo6be909e2020-08-24 09:36:13 -070092 -e "{'kube_proxy_metrics_bind_address' : 0.0.0.0:10249}" \
93 -e "{'kube_pods_subnet' : 192.168.0.0/17, 'kube_service_addresses' : 192.168.128.0/17}" \
94 -e "{'kube_apiserver_node_port_range' : 2000-36767}" \
95 -e "{'kubeadm_enabled': True}" \
96 -e "{'kube_feature_gates' : [SCTPSupport=True]}" \
97 -e "{'kubelet_custom_flags' : [--allowed-unsafe-sysctls=net.*]}" \
98 -e "{'dns_min_replicas' : 1}" \
99 -e "{'helm_enabled' : True, 'helm_version' : $(HELM_VERSION)}" \
100 cluster.yml
101 mkdir -p $(HOME)/.kube
102 sudo cp -f /etc/kubernetes/admin.conf $(HOME)/.kube/config
103 sudo chown $(shell id -u):$(shell id -g) $(HOME)/.kube/config
104 kubectl wait pod -n kube-system --for=condition=Ready --all
105 touch $@
106
107$(M)/helm-ready: | $(M)/k8s-ready
108 helm init --wait --client-only
109 helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com/
110 helm repo add cord https://charts.opencord.org
111 touch $@
112
113/opt/cni/bin/simpleovs: | $(M)/k8s-ready
114 sudo cp $(RESOURCEDIR)/simpleovs /opt/cni/bin/
115
116/opt/cni/bin/static: | $(M)/k8s-ready
117 mkdir -p $(BUILD)/cni-plugins; cd $(BUILD)/cni-plugins; \
118 wget https://github.com/containernetworking/plugins/releases/download/v0.8.2/cni-plugins-linux-amd64-v0.8.2.tgz && \
119 tar xvfz cni-plugins-linux-amd64-v0.8.2.tgz
120 sudo cp $(BUILD)/cni-plugins/static /opt/cni/bin/
121
122# TODO: need to connect ONOS
123$(M)/fabric: | $(M)/setup /opt/cni/bin/simpleovs /opt/cni/bin/static
124 sudo apt install -y openvswitch-switch
125 sudo ovs-vsctl --may-exist add-br br-enb-net
126 sudo ovs-vsctl --may-exist add-port br-enb-net enb -- set Interface enb type=internal
127 sudo ip addr add 192.168.251.4/24 dev enb || true
128 sudo ip link set enb up
129 sudo ethtool --offload enb tx off
130 sudo ip route replace 192.168.252.0/24 via 192.168.251.1 dev enb
131 kubectl apply -f $(RESOURCEDIR)/router.yaml
132 kubectl wait pod -n default --for=condition=Ready -l app=router --timeout=300s
Hyunsun84f0f172020-09-23 15:40:08 -0500133 kubectl -n default exec router ip route add 10.250.0.0/16 via 192.168.250.3
Jeremy Ronquilloaf084f32020-08-24 13:18:47 -0700134 kubectl delete net-attach-def core-net
Jeremy Ronquillo6be909e2020-08-24 09:36:13 -0700135 touch $@
136
137$(M)/omec: | $(M)/helm-ready /opt/cni/bin/simpleovs /opt/cni/bin/static $(M)/fabric
138 helm repo update
139 helm upgrade --install $(HELM_GLOBAL_ARGS) \
140 --namespace omec \
Jeremy Ronquillod3cab742020-08-24 11:49:00 -0700141 --values $(AIABVALUES) \
Jeremy Ronquillo6be909e2020-08-24 09:36:13 -0700142 omec-control-plane \
Jeremy Ronquilloaf084f32020-08-24 13:18:47 -0700143 $(WORKSPACE)/cord/aether-helm-charts/omec/omec-control-plane && \
Hyunsun Moon0bd8cec2020-09-28 00:38:26 -0500144 kubectl wait pod -n omec --for=condition=Ready -l release=omec-control-plane --timeout=300s && \
Jeremy Ronquillo6be909e2020-08-24 09:36:13 -0700145 helm upgrade --install $(HELM_GLOBAL_ARGS) \
146 --namespace omec \
Jeremy Ronquillod3cab742020-08-24 11:49:00 -0700147 --values $(AIABVALUES) \
Jeremy Ronquillo6be909e2020-08-24 09:36:13 -0700148 omec-user-plane \
Jeremy Ronquilloaf084f32020-08-24 13:18:47 -0700149 $(WORKSPACE)/cord/aether-helm-charts/omec/omec-user-plane && \
Hyunsun Moon0bd8cec2020-09-28 00:38:26 -0500150 kubectl wait pod -n omec --for=condition=Ready -l release=omec-user-plane --timeout=300s
Jeremy Ronquillo6be909e2020-08-24 09:36:13 -0700151 touch $@
152
153# UE images includes kernel module, ue_ip.ko
154# which should be built in the exactly same kernel version of the host machine
155$(BUILD)/openairinterface: | $(M)/setup
156 mkdir -p $(BUILD)
157 cd $(BUILD); git clone https://github.com/opencord/openairinterface.git
158
159$(M)/ue-image: | $(M)/k8s-ready $(BUILD)/openairinterface
160 cd $(BUILD)/openairinterface; \
161 sudo docker build . --target lte-uesoftmodem \
162 --build-arg build_base=omecproject/oai-base:1.0.0 \
163 --file Dockerfile.ue \
164 --tag omecproject/lte-uesoftmodem:1.0.0
165 touch $@
166
167$(M)/oaisim: | $(M)/ue-image $(M)/omec
168 sudo ip addr add 127.0.0.2/8 dev lo || true
169 $(eval mme_iface=$(shell ip -4 route list default | awk -F 'dev' '{ print $$2; exit }' | awk '{ print $$1 }'))
Jeremy Ronquillod3cab742020-08-24 11:49:00 -0700170 helm upgrade --install $(HELM_GLOBAL_ARGS) --namespace omec oaisim cord/oaisim -f $(AIABVALUES) \
Jeremy Ronquilloaf084f32020-08-24 13:18:47 -0700171 --set config.enb.networks.s1_mme.interface=$(mme_iface) \
172 --set images.pullPolicy=IfNotPresent
Jeremy Ronquillo6be909e2020-08-24 09:36:13 -0700173 kubectl rollout status -n omec statefulset ue
174 @timeout 60s bash -c \
175 "until ip addr show oip1 | grep -q inet; \
176 do \
177 echo 'Waiting for UE 1 gets IP address'; \
178 sleep 3; \
179 done"
180 touch $@
181
182test: | $(M)/fabric $(M)/omec $(M)/oaisim
183 @sleep 5
184 @echo "Test1: ping from UE to SGI network gateway"
Hyunsun Moon0bd8cec2020-09-28 00:38:26 -0500185 ping -I oip1 192.168.250.1 -c 15
Jeremy Ronquillo6be909e2020-08-24 09:36:13 -0700186 @echo "Test2: ping from UE to 8.8.8.8"
187 ping -I oip1 8.8.8.8 -c 3
Hyunsun Moon0bd8cec2020-09-28 00:38:26 -0500188 @echo "Test3: ping from UE to google.com"
Jeremy Ronquillo6be909e2020-08-24 09:36:13 -0700189 ping -I oip1 google.com -c 3
190 @echo "Finished to test"
191
192reset-test:
193 helm delete --purge oaisim || true
194 helm delete --purge omec-control-plane || true
195 helm delete --purge omec-user-plane || true
Jeremy Ronquillo7ba47332020-09-21 16:47:21 -0700196 kubectl delete po router || true
197 cd $(M); rm -f oaisim omec fabric
Jeremy Ronquillo6be909e2020-08-24 09:36:13 -0700198
199clean: reset-test
200 helm delete --purge $(shell helm ls -q) || true
201 kubectl delete po router || true
Jeremy Ronquilloaf084f32020-08-24 13:18:47 -0700202 kubectl delete net-attach-def core-net || true
203 sudo ovs-vsctl del-br br-access-net || true
204 sudo ovs-vsctl del-br br-core-net || true
Jeremy Ronquillo6be909e2020-08-24 09:36:13 -0700205 sudo apt remove --purge openvswitch-switch -y
206 source "$(VENV)/bin/activate" && cd $(BUILD)/kubespray; \
207 ansible-playbook -b -i inventory/local/hosts.ini reset.yml
208 @if [ -d /usr/local/etc/emulab ]; then \
209 mount | grep /mnt/extra/kubelet/pods | cut -d" " -f3 | sudo xargs umount; \
210 sudo rm -rf /mnt/extra/kubelet; \
211 fi
212 rm -rf $(M)