Newer
Older
<!doctype html>
<html lang="en" class="no-js">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="description" content="ETSI SDG TFS Documentation page">
<meta name="author" content="TeraflowSDN by ETSI">
<link rel="canonical" href="https://tfs.etsi.org/develop/development_guide/development_guide/">
<link rel="prev" href="../../deployment_guide/deployment_guide/">
<link rel="icon" href="../../images/favicon.png">
<meta name="generator" content="mkdocs-1.6.1, mkdocs-material-9.5.42">
<title>2. Development Guide - ETSI SDG TFS Documentation</title>
<link rel="stylesheet" href="../../assets/stylesheets/main.0253249f.min.css">
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<link rel="stylesheet" href="../../assets/stylesheets/palette.06af60db.min.css">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,700,700i%7CRoboto+Mono:400,400i,700,700i&display=fallback">
<style>:root{--md-text-font:"Roboto";--md-code-font:"Roboto Mono"}</style>
<link rel="stylesheet" href="../../stylesheets/extra.css">
<script>__md_scope=new URL("../..",location),__md_hash=e=>[...e].reduce(((e,_)=>(e<<5)-e+_.charCodeAt(0)),0),__md_get=(e,_=localStorage,t=__md_scope)=>JSON.parse(_.getItem(t.pathname+"."+e)),__md_set=(e,_,t=localStorage,a=__md_scope)=>{try{t.setItem(a.pathname+"."+e,JSON.stringify(_))}catch(e){}}</script>
</head>
<body dir="ltr" data-md-color-scheme="default" data-md-color-primary="0D47A1" data-md-color-accent="1565C0">
<input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
<label class="md-overlay" for="__drawer"></label>
<div data-md-component="skip">
<a href="#21-configure-environment" class="md-skip">
Skip to content
</a>
</div>
<div data-md-component="announce">
</div>
<div data-md-color-scheme="default" data-md-component="outdated" hidden>
</div>
<header class="md-header md-header--shadow" data-md-component="header">
<nav class="md-header__inner md-grid" aria-label="Header">
<a href="../.." title="ETSI SDG TFS Documentation" class="md-header__button md-logo" aria-label="ETSI SDG TFS Documentation" data-md-component="logo">
<img src="../../images/logos/TeraFlow SDN Logo Screen_B_W NEG.png" alt="logo">
</a>
<label class="md-header__button md-icon" for="__drawer">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3zm0 5h18v2H3zm0 5h18v2H3z"/></svg>
</label>
<div class="md-header__title" data-md-component="header-title">
<div class="md-header__ellipsis">
<div class="md-header__topic">
<span class="md-ellipsis">
ETSI SDG TFS Documentation
</span>
</div>
<div class="md-header__topic" data-md-component="header-topic">
<span class="md-ellipsis">
2. Development Guide
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
</span>
</div>
</div>
</div>
<label class="md-header__button md-icon" for="__search">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.52 6.52 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5"/></svg>
</label>
<div class="md-search" data-md-component="search" role="dialog">
<label class="md-search__overlay" for="__search"></label>
<div class="md-search__inner" role="search">
<form class="md-search__form" name="search">
<input type="text" class="md-search__input" name="query" aria-label="Search" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="search-query" required>
<label class="md-search__icon md-icon" for="__search">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.52 6.52 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5"/></svg>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11z"/></svg>
</label>
<nav class="md-search__options" aria-label="Search">
<button type="reset" class="md-search__icon md-icon" title="Clear" aria-label="Clear" tabindex="-1">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"/></svg>
</button>
</nav>
</form>
<div class="md-search__output">
<div class="md-search__scrollwrap" tabindex="0" data-md-scrollfix>
<div class="md-search-result" data-md-component="search-result">
<div class="md-search-result__meta">
Initializing search
</div>
<ol class="md-search-result__list" role="presentation"></ol>
</div>
</div>
</div>
</div>
</div>
<div class="md-header__source">
<a href="https://labs.etsi.org/rep/tfs" title="Go to repository" class="md-source" data-md-component="source">
<div class="md-source__icon md-icon">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.6.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2024 Fonticons, Inc.--><path d="m503.5 204.6-.7-1.8-69.7-181.78c-1.4-3.57-3.9-6.59-7.2-8.64-2.4-1.55-5.1-2.515-8-2.81s-5.7.083-8.4 1.11c-2.7 1.02-5.1 2.66-7.1 4.78-1.9 2.12-3.3 4.67-4.1 7.44l-47 144H160.8l-47.1-144c-.8-2.77-2.2-5.31-4.1-7.43-2-2.12-4.4-3.75-7.1-4.77a18.1 18.1 0 0 0-8.38-1.113 18.4 18.4 0 0 0-8.04 2.793 18.1 18.1 0 0 0-7.16 8.64L9.267 202.8l-.724 1.8a129.57 129.57 0 0 0-3.52 82c7.747 26.9 24.047 50.7 46.447 67.6l.27.2.59.4 105.97 79.5 52.6 39.7 32 24.2c3.7 1.9 8.3 4.3 13 4.3s9.3-2.4 13-4.3l32-24.2 52.6-39.7 106.7-79.9.3-.3c22.4-16.9 38.7-40.6 45.6-67.5 8.6-27 7.4-55.8-2.6-82"/></svg>
</div>
<div class="md-source__repository">
TFS GitLab
</div>
</a>
</div>
</nav>
</header>
<div class="md-container" data-md-component="container">
<main class="md-main" data-md-component="main">
<div class="md-main__inner md-grid">
<div class="md-sidebar md-sidebar--primary" data-md-component="sidebar" data-md-type="navigation" >
<div class="md-sidebar__scrollwrap">
<div class="md-sidebar__inner">
<nav class="md-nav md-nav--primary md-nav--integrated" aria-label="Navigation" data-md-level="0">
<label class="md-nav__title" for="__drawer">
<a href="../.." title="ETSI SDG TFS Documentation" class="md-nav__button md-logo" aria-label="ETSI SDG TFS Documentation" data-md-component="logo">
<img src="../../images/logos/TeraFlow SDN Logo Screen_B_W NEG.png" alt="logo">
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
</a>
ETSI SDG TFS Documentation
</label>
<div class="md-nav__source">
<a href="https://labs.etsi.org/rep/tfs" title="Go to repository" class="md-source" data-md-component="source">
<div class="md-source__icon md-icon">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.6.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2024 Fonticons, Inc.--><path d="m503.5 204.6-.7-1.8-69.7-181.78c-1.4-3.57-3.9-6.59-7.2-8.64-2.4-1.55-5.1-2.515-8-2.81s-5.7.083-8.4 1.11c-2.7 1.02-5.1 2.66-7.1 4.78-1.9 2.12-3.3 4.67-4.1 7.44l-47 144H160.8l-47.1-144c-.8-2.77-2.2-5.31-4.1-7.43-2-2.12-4.4-3.75-7.1-4.77a18.1 18.1 0 0 0-8.38-1.113 18.4 18.4 0 0 0-8.04 2.793 18.1 18.1 0 0 0-7.16 8.64L9.267 202.8l-.724 1.8a129.57 129.57 0 0 0-3.52 82c7.747 26.9 24.047 50.7 46.447 67.6l.27.2.59.4 105.97 79.5 52.6 39.7 32 24.2c3.7 1.9 8.3 4.3 13 4.3s9.3-2.4 13-4.3l32-24.2 52.6-39.7 106.7-79.9.3-.3c22.4-16.9 38.7-40.6 45.6-67.5 8.6-27 7.4-55.8-2.6-82"/></svg>
</div>
<div class="md-source__repository">
TFS GitLab
</div>
</a>
</div>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../deployment_guide/deployment_guide/" class="md-nav__link">
<span class="md-ellipsis">
1. Deployment Guide
</span>
</a>
</li>
<li class="md-nav__item md-nav__item--active">
<input class="md-nav__toggle md-toggle" type="checkbox" id="__toc">
<label class="md-nav__link md-nav__link--active" for="__toc">
<span class="md-ellipsis">
2. Development Guide
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<a href="./" class="md-nav__link md-nav__link--active">
<span class="md-ellipsis">
2. Development Guide
</span>
</a>
<nav class="md-nav md-nav--secondary" aria-label="Table of contents">
<label class="md-nav__title" for="__toc">
<span class="md-nav__icon md-icon"></span>
Table of contents
</label>
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
<li class="md-nav__item">
<a href="#21-configure-environment" class="md-nav__link">
<span class="md-ellipsis">
2.1. Configure Environment
</span>
</a>
<nav class="md-nav" aria-label="2.1. Configure Environment">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#211-python" class="md-nav__link">
<span class="md-ellipsis">
2.1.1. Python
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#212-java-quarkus" class="md-nav__link">
<span class="md-ellipsis">
2.1.2. Java (Quarkus)
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#213-java-maven" class="md-nav__link">
<span class="md-ellipsis">
2.1.3. Java (Maven)
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#214-rust" class="md-nav__link">
<span class="md-ellipsis">
2.1.4. Rust
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#215-erlang" class="md-nav__link">
<span class="md-ellipsis">
2.1.5. Erlang
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#216-kotlin" class="md-nav__link">
<span class="md-ellipsis">
2.1.6. Kotlin
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#22-configure-vscode" class="md-nav__link">
<span class="md-ellipsis">
2.2. Configure VScode
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#23-develop-a-component-wip" class="md-nav__link">
<span class="md-ellipsis">
2.3. Develop A Component (WIP)
</span>
</a>
</li>
</ul>
</nav>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div class="md-content" data-md-component="content">
<article class="md-content__inner md-typeset">
<h1>2. Development Guide</h1>
<h2 id="21-configure-environment"><strong>2.1. Configure Environment</strong></h2>
<h3 id="211-python"><strong>2.1.1. Python</strong></h3>
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
<p>This section describes how to configure the Python environment to run experiments and
develop code for the ETSI TeraFlowSDN controller.
In particular, we use <a href="https://github.com/pyenv/pyenv">PyEnv</a> to install the appropriate
version of Python and manage the virtual environments.</p>
<h3><u>Upgrade the Ubuntu distribution</h3>
<p></u></p>
<p>Skip this step if you already did it during the installation of your machine.</p>
<pre><code class="language-bash">sudo apt-get update -y
sudo apt-get dist-upgrade -y
</code></pre>
<h3><u>Install PyEnv dependencies</h3>
<p></u></p>
<pre><code class="language-bash">sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget \
curl llvm git libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
</code></pre>
<h3><u>Install PyEnv</h3>
<p></u></p>
<p>We recommend installing PyEnv through<br />
<a href="https://github.com/pyenv/pyenv-installer">PyEnv Installer</a>.
Below you can find the instructions, but we refer you to the link for updated
instructions.</p>
<pre><code class="language-bash">curl https://pyenv.run | bash
# When finished, edit ~/.bash_profile // ~/.profile // ~/.bashrc as the installer proposes.
# In general, it means to append the following lines to ~/.bashrc:
export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
</code></pre>
<p>In case .bashrc is not linked properly to your profile, you may need to append the
following line into your local .profile file:</p>
<pre><code class="language-bash"># Open ~/.profile and append this line:
+source "$HOME"/.bashrc
</code></pre>
<h3><u>Restart the machine</h3>
<p></u>
Restart the machine for all the changes to take effect.</p>
<pre><code class="language-bash">sudo reboot
</code></pre>
<h3><u>Install Python 3.9 over PyEnv</h3>
<p></u></p>
<p>ETSI TeraFlowSDN uses Python 3.9 by default.
You should install the latest stable update of Python 3.9, i.e., avoid "-dev" versions.
To find the latest version available in PyEnv, you can run the following command:</p>
<pre><code class="language-bash">pyenv install --list | grep " 3.9"
</code></pre>
<p>At the time of writing, this command will output the following list:</p>
<pre><code> 3.9.0
3.9-dev
3.9.1
3.9.2
3.9.4
3.9.5
3.9.6
3.9.7
3.9.8
3.9.9
3.9.10
3.9.11
3.9.12
3.9.13
3.9.14
3.9.15
3.9.16 ** always select the latest version **
</code></pre>
<p>Therefore, the latest stable version is Python 3.9.16.
To install this version, you should run:</p>
<pre><code class="language-bash">pyenv install 3.9.16
# This command might take some minutes depending on your Internet connection speed
# and the performance of your machine.
</code></pre>
<h3><u>Create the Virtual Environment for TeraFlowSDN</h3>
<p></u>
The following commands create a virtual environment named as <code>tfs</code> using Python 3.9 and
associate that environment with the current folder, i.e., <code>~/tfs-ctrl</code>.
That way, when you are in that folder, the associated virtual environment will be used,
thus inheriting the Python interpreter, i.e., Python 3.9, and the Python packages
installed on it.</p>
<pre><code class="language-bash">cd ~/tfs-ctrl
pyenv virtualenv 3.9.16 tfs
pyenv local 3.9.16/envs/tfs
</code></pre>
<p>After completing these commands, you should see in your prompt that now you're within
the virtual environment <code>3.9.16/envs/tfs</code> on folder <code>~/tfs-ctrl</code>:</p>
<pre><code>(3.9.16/envs/tfs) tfs@tfs-vm:~/tfs-ctrl$
</code></pre>
<p>In case that the correct pyenv does not get automatically activated when you change to
the tfs-ctrl/ folder, then execute the following command:</p>
<pre><code class="language-bash">cd ~/tfs-ctrl
pyenv activate 3.9.16/envs/tfs
</code></pre>
<h3><u>Install the basic Python packages within the virtual environment</h3>
<p></u>
From within the <code>3.9.16/envs/tfs</code> environment on folder <code>~/tfs-ctrl</code>, run the following
commands to install the basic Python packages required to work with TeraFlowSDN.</p>
<pre><code class="language-bash">cd ~/tfs-ctrl
./install_requirements.sh
</code></pre>
<p>Some dependencies require to re-load the session, so log-out and log-in again.</p>
<h3><u>Generate the Python code from the gRPC Proto messages and services</h3>
<p></u></p>
<p>The components, e.g., microservices, of the TeraFlowSDN controller, in general, use a gRPC-based open API to interoperate.
All the protocol definitions can be found in sub-folder <code>proto</code> within the root project folder.
For additional details on gRPC, visit the official web-page <a href="https://grpc.io/">gRPC</a>.</p>
<p>In order to interact with the components, (re-)generate the Python code from gRPC definitions running the following command:</p>
<pre><code class="language-bash">cd ~/tfs-ctrl
proto/generate_code_python.sh
</code></pre>
<h3 id="212-java-quarkus"><strong>2.1.2. Java (Quarkus)</strong></h3>
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
<p>This section describe the steps needed to create a development environment for TFS components implemented in Java. Currently, ZTP and Policy components have been developed in Java (version 11) and use the <a href="https://quarkus.io/">Quarkus</a> framework, which enables kubernetes-native development.</p>
<h3><u>Install JDK</h3>
<p></u>
To begin, make sure that you have java installed and in the correct version</p>
<pre><code>java --version
</code></pre>
<p>If you don't have java installed you will get an error like the following:</p>
<pre><code>Command 'java' not found, but can be installed with:
sudo apt install default-jre # version 2:1.11-72build1, or
sudo apt install openjdk-11-jre-headless # version 11.0.14+9-0ubuntu2
sudo apt install openjdk-17-jre-headless # version 17.0.2+8-1
sudo apt install openjdk-18-jre-headless # version 18~36ea-1
sudo apt install openjdk-8-jre-headless # version 8u312-b07-0ubuntu1
</code></pre>
<p>In which case you should use the following command to install the correct version:</p>
<pre><code>sudo apt install openjdk-11-jre-headless
</code></pre>
<p>Else you should get something like the following:</p>
<pre><code>openjdk 11.0.18 2023-01-17
OpenJDK Runtime Environment (build 11.0.18+10-post-Ubuntu-0ubuntu120.04.1)
OpenJDK 64-Bit Server VM (build 11.0.18+10-post-Ubuntu-0ubuntu120.04.1, mixed mode, sharing)
</code></pre>
<h3><u>Compiling and testing existing components</h3>
<p></u>
In the root directory of the existing Java components you will find an executable maven wrapper named <code>mvnw</code>. You could use this executable, which is already configured in pair with the components, instead of your local maven installation. So for example if you want to compile the project you would run the following:</p>
<pre><code>./mvnw compile
</code></pre>
<h3><u>VS Code Quarkus plugin</h3>
<p></u>
In case you are using <a href="https://code.visualstudio.com/">VS Code</a> for development, we suggest to install the <a href="https://marketplace.visualstudio.com/items?itemName=redhat.vscode-quarkus">official Quarkus extension</a>.
The extension should be able to automatically find the current open project and integrate with the above <code>mvnw</code> maven wrapper, making it easier to control the <a href="https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html">maven lifecycle</a>.
Make sure that you open the specific component directory (i.e., <code>src/ztp</code> or <code>src/policy</code>) and not the general controller one (i.e., <code>src</code>.</p>
<h3><u>New Java TFS component</h3>
<p></u></p>
<p><strong>Sample Project</strong></p>
<p>If you want to create a new TFS component written in Java you could generate a new Quarkus project based on the following project:</p>
<p><a href="https://code.quarkus.io/?e=grpc&e=kubernetes&e=container-image-jib&e=kubernetes-service-binding&e=smallrye-health&e=resteasy-reactive">TFS Sample Quarkus Project</a></p>
<p>In that way, you should have most of the libraries you would need to integrate with the rest of the TFS Components. Feel free however to add or remove libraries depending on your needs.</p>
<p><strong>Initial setup</strong></p>
<p>If you used the sample project above, you should have a project with a basic structure. However there are some steps that you should take before starting development.</p>
<p>First make sure that you copy the protobuff files, that are found in the root directory of the TFS SDN controller, to the <code>new-component/src/main/proto</code> directory.</p>
<p>Next you should create the following files:
* <code>new-component/.gitlab-ci.yml</code>
* <code>new-component/Dockerfile</code>
* <code>new-component/src/resources/application.yaml</code></p>
<p>We suggest to copy the respective files from existing components (Automation and Policy) and change them according to your needs.</p>
<h3 id="213-java-maven"><strong>2.1.3. Java (Maven)</strong></h3>
<p><strong>Page under construction</strong></p>
<h3 id="214-rust"><strong>2.1.4. Rust</strong></h3>
<p><strong>Page under construction</strong></p>
<h3 id="215-erlang"><strong>2.1.5. Erlang</strong></h3>
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
<p>This section describes how to configure the Erlang environment to run experiments and
develop code for the ETSI TeraFlowSDN controller.</p>
<p>First we need to install Erlang. There is multiple way, for development we will be
using <a href="https://asdf-vm.com/">ASDF</a>, a tool that allows the installation of multiple
version of Erlang at the same time, and switch from one version to the other at will.</p>
<ul>
<li>First, install any missing dependencies:</li>
</ul>
<pre><code class="language-bash">sudo apt install curl git autoconf libncurses-dev build-essential m4 libssl-dev
</code></pre>
<ul>
<li>Download <em>ASDF</em> tool to the local account:</li>
</ul>
<pre><code class="language-bash">git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.10.2
</code></pre>
<ul>
<li>Make <em>ASDF</em> activate on login by adding these lines at the end of the <code>~/.bashrc</code> file:</li>
</ul>
<pre><code class="language-bash">. $HOME/.asdf/asdf.sh
. $HOME/.asdf/completions/asdf.bash
</code></pre>
<ul>
<li>Logout and log back in to activate <em>ASDF</em>.</li>
</ul>
<p><em>ASDF</em> supports multiple tools by installing there corresponding plugins.</p>
<ul>
<li>Install <em>ASDF</em> plugin for Erlang:</li>
</ul>
<pre><code class="language-bash">asdf plugin add erlang https://github.com/asdf-vm/asdf-erlang.git
</code></pre>
<ul>
<li>Install a version of Erlang:</li>
</ul>
<pre><code class="language-bash">asdf install erlang 24.3.4.2
</code></pre>
<ul>
<li>Activate Erlang locally for TFS controller. This will create a local file
called <code>.tool-versions</code> defining which version of the tools to use when
running under the current directory:</li>
</ul>
<pre><code class="language-bash">cd tfs-ctrl/
asdf local erlang 24.3.4.2
</code></pre>
<p>Erlang projects uses a build tool called
<a href="https://github.com/erlang/rebar3">rebar3</a>.
It is used to manager project dependenecies, compile a project and generate
project releases.</p>
<ul>
<li>Install rebar3 localy from source:</li>
</ul>
<pre><code class="language-bash">cd ~
git clone https://github.com/erlang/rebar3.git
cd rebar3
asdf local erlang 24.3.4.2
./bootstrap
./rebar3 local install
</code></pre>
<ul>
<li>Update <code>~/.bashrc</code> to use rebar3 by adding this line at the end:</li>
</ul>
<pre><code class="language-bash">export PATH=$HOME/.cache/rebar3/bin:$PATH
</code></pre>
<ul>
<li>Logout and log back in.</li>
</ul>
<h3 id="216-kotlin"><strong>2.1.6. Kotlin</strong></h3>
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
<h2><u>Kotlin</h2>
<p></u>
This section describes the steps needed to establish a development environment for TFS (TeraFlowSDN) components implemented in Kotlin. Currently, the <code>Gateway</code> component stands as the sole component developed in Kotlin.</p>
<h3><u>Install Kotlin</h3>
<p></u>
To begin, make sure that you have kotlin installed and its current version:</p>
<pre><code>kotlin -version
</code></pre>
<p>If you don't have kotlin installed you will get an error like the following:</p>
<pre><code>Command 'kotlin' not found, but can be installed with:
sudo snap install --classic kotlin
</code></pre>
<p>In which case you should use the following command to install the correct version:</p>
<pre><code> sudo snap install --classic kotlin
</code></pre>
<p>Currently, the recommended version is 1.6.21, which uses Java Runtime Environment (JRE) version 11.</p>
<h3><u>Compiling and testing existing components</h3>
<p></u>
To compile a Kotlin project using Gradle, similarly to using the Maven wrapper (mvnw) for Java projects, you can use the Gradle wrapper (gradlew) within the root directory of your Kotlin component, specifically the gateway directory.</p>
<p>Navigate to the gateway directory within your Kotlin project. Ensure that it contains the gradlew script along with the gradle directory.
Then, create a directory named <code>proto</code> and move all the files with extension <code>.proto</code> in this way:</p>
<pre><code>mkdir proto
cp ../../../proto/*.proto ./proto
</code></pre>
<p>For building the application, open a terminal or command prompt, navigate to the gateway directory, and run the following command:</p>
<pre><code>./gradlew build
</code></pre>
<p>The following program runs the gateway application:</p>
<pre><code>./gradlew runServer
</code></pre>
<h3><u>New Kotlin TFS component</h3>
<p></u></p>
<p><strong>Sample Project</strong></p>
<p>If you want to create a new TFS component written in Kotlin you could generate a Kotlin project using <code>gradle</code>. The recommended version is 7.1. Follow the following <a href="https://linuxize.com/post/how-to-install-gradle-on-ubuntu-20-04/">Gradle guide</a> for its installation. For building the prokect follow <a href="https://docs.gradle.org/current/samples/sample_building_kotlin_applications.html">this link</a> instead.</p>
<p>From inside the new project directory, run the init task using the following command in a terminal: <code>gradle init</code>. </p>
<p>The output will look like this:</p>
<pre><code>$ gradle init
Select type of project to generate:
1: basic
2: application
3: library
4: Gradle plugin
Enter selection (default: basic) [1..4] 2
Select implementation language:
1: C++
2: Groovy
3: Java
4: Kotlin
5: Scala
6: Swift
Enter selection (default: Java) [1..6] 4
Select build script DSL:
1: Groovy
2: Kotlin
Enter selection (default: Groovy) [1..2] 1
Project name (default: demo):
Source package (default: demo):
BUILD SUCCESSFUL
2 actionable tasks: 2 executed
</code></pre>
<p><strong>Initial setup</strong></p>
<p>The <code>gradle init</code> command generates the new project. </p>
<p>First, ensure the protobuf files are copied from the root directory of the TFS SDN controller. Run the following command in the directory of the new project:</p>
<pre><code>mkdir proto
cp TFS/project/root/path/proto/*.proto ./proto/
</code></pre>
<p>The file <code>build.gradle.ktl</code> is fundamental as it manages dependencies. Adjust it for adding external libraries. </p>
<p>Next you should create the following files:</p>
<ol>
<li><code>new-component/.gitlab-ci.yml</code></li>
<li><code>new-component/Dockerfile</code></li>
</ol>
<p>We recommend leveraging the structures and configurations found in the files of existing components for inspiration.</p>
<p><strong>Docker Container</strong>
This project operates with Docker containers. Ensure the production of the container version for your component. To generate the container version of the project, modify the 'new-component/Dockerfile.' Execute the following command from the project's root directory:</p>
<pre><code>docker build -t new-image -f new-component/Dockerfile ./
</code></pre>
<hr />
<h2 id="22-configure-vscode"><strong>2.2. Configure VScode</strong></h2>
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
<h3><u>Install VSCode and the required extensions</h3>
<p></u></p>
<p>If not already done, install <a href="https://code.visualstudio.com/">VSCode</a> and the "Remote SSH" extension on your local
machine, not in the VM.</p>
<p><strong>Note</strong>: "Python" extension is not required here. It will be installed later on the VSCode server running on the VM.</p>
<h3><u>Configure the "Remote SSH" extension</h3>
<p></u></p>
<ul>
<li>Go to left icon "Remote Explorer"</li>
<li>Click the "gear" icon next to "SSH TARGETS" on top of "Remote Explorer" bar</li>
<li>Choose to edit "<...>/.ssh/config" file (or equivalent)</li>
<li>Add the following entry (assuming previous port forwarding configuration):</li>
</ul>
<pre><code>Host TFS-VM
HostName 127.0.0.1
Port 2200
ForwardX11 no
User tfs
</code></pre>
<ul>
<li>Save the file</li>
<li>An entry "TFS-VM" should appear on "SSH TARGETS".</li>
</ul>
<h3><u>Connect VSCode to the VM through "Remote SSH" extension</h3>
<p></u>
- Right-click on "TFS-VM"
- Select "Connect to Host in Current Window"
- Reply to the questions asked
- Platform of the remote host "TFS-VM": Linux
- "TFS-VM" has fingerprint "<fingerprint>". Do you want to continue?: Continue
- Type tfs user's password: tfs123
- You should be now connected to the TFS-VM.</p>
<p><strong>Note</strong>: if you get a connection error message, the reason might be due to wrong SSH server fingerprint. Edit file
"<...>/.ssh/known_hosts" on your local user account, check if there is a line starting with
"[127.0.0.1]:2200" (assuming previous port forwarding configuration), remove the entire line, save the file,
and retry connection.</p>
<h3><u>Add SSH key to prevent typing the password every time</h3>
<p></u>
This step creates an SSH key in the VM and installs it on the VSCode to prevent having to type the password every time.</p>
<ul>
<li>In VSCode (connected to the VM), click menu "Terminal > New Terminal"</li>
<li>Run the following commands on the VM's terminal through VSCode</li>
</ul>
<pre><code class="language-bash">ssh-keygen -t rsa -b 4096 -f ~/.ssh/tfs-vm.key
# leave password empty
ssh-copy-id -i ~/.ssh/tfs-vm.key.pub tfs@10.0.2.10
# tfs@10.0.2.10's password: <type tfs user's password: tfs123>
rm .ssh/known_hosts
</code></pre>
<ul>
<li>In VSCode, click left "Explorer" panel to expand, if not expanded, and click "Open Folder" button.</li>
<li>Choose "/home/tfs/"</li>
<li>Type tfs user's password when asked</li>
<li>Trust authors of the "/home/tfs [SSH: TFS-VM]" folder when asked</li>
<li>Right click on the file "tfs-vm.key" in the file explorer</li>
<li>Select "Download..." option</li>
<li>Download the file into your user's accout ".ssh" folder</li>
<li>
<p>Delete files "tfs-vm.key" and "tfs-vm.key.pub" on the TFS-VM.</p>
</li>
<li>
<p>In VSCode, click left "Remote Explorer" panel to expand</p>
</li>
<li>Click the "gear" icon next to "SSH TARGETS" on top of "Remote Explorer" bar</li>
<li>Choose to edit "<...>/.ssh/config" file (or equivalent)</li>
<li>Find entry "Host TFS-VM" and update it as follows:</li>
</ul>
<pre><code>Host TFS-VM
HostName 127.0.0.1
Port 2200
ForwardX11 no
User tfs
IdentityFile "<path to the downloaded identity private key file>"
</code></pre>
<ul>
<li>Save the file</li>
<li>From now, VSCode will use the identity file to connect to the TFS-VM instead of the user's password.</li>
</ul>
<h3><u>Install VSCode Python Extension (in VSCode server)</h3>
<p></u>
This step installs Python extensions in VSCode server running in the VM.</p>
<ul>
<li>In VSCode (connected to the VM), click left button "Extensions"</li>
<li>Search "Python" extension in the extension Marketplace.</li>
<li>Install official "Python" extension released by Microsoft.</li>
<li>
<p>By default, since you're connected to the VM, it will be installed in the VSCode server running in the VM.</p>
</li>
<li>
<p>In VSCode (connected to the VM), click left button "Explorer"</p>
</li>
<li>Click "Ctrl+Alt+P" and type "Python: Select Interpreter". Select option "Python: 3.9.13 64-bit ('tfs')"</li>
</ul>
<h3><u>Define environment variables for VSCode</h3>
<p></u>
The source code in the TFS controller project is hosted in folder <code>src/</code>. To help VSCode find the Python modules and
packages, add the following file into your working space root folder:</p>
<pre><code class="language-bash">echo "PYTHONPATH=./src" >> ~/tfs-ctrl/.env
</code></pre>
<h2 id="23-develop-a-component-wip"><strong>2.3. Develop A Component (WIP)</strong></h2>
<p><strong>Page under construction</strong></p>
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
</article>
</div>
<script>var target=document.getElementById(location.hash.slice(1));target&&target.name&&(target.checked=target.name.startsWith("__tabbed_"))</script>
</div>
<button type="button" class="md-top md-icon" data-md-component="top" hidden>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M13 20h-2V8l-5.5 5.5-1.42-1.42L12 4.16l7.92 7.92-1.42 1.42L13 8z"/></svg>
Back to top
</button>
</main>
<footer class="md-footer">
<nav class="md-footer__inner md-grid" aria-label="Footer" >
<a href="../../deployment_guide/deployment_guide/" class="md-footer__link md-footer__link--prev" aria-label="Previous: 1. Deployment Guide">
<div class="md-footer__button md-icon">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11z"/></svg>
</div>
<div class="md-footer__title">
<span class="md-footer__direction">
Previous
</span>
<div class="md-ellipsis">
1. Deployment Guide
</div>
</div>
</a>
</nav>
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
<div class="md-footer-meta md-typeset">
<div class="md-footer-meta__inner md-grid">
<div class="md-copyright">
<div class="md-copyright__highlight">
Copyright © 2019-2024 TeraflowSDN Project
</div>
Made with
<a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
Material for MkDocs
</a>
</div>
<div class="md-social">
<a href="https://tfs.etsi.org/" target="_blank" rel="noopener" title="tfs.etsi.org" class="md-social__link">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.6.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2024 Fonticons, Inc.--><path d="M352 256c0 22.2-1.2 43.6-3.3 64H163.4c-2.2-20.4-3.3-41.8-3.3-64s1.2-43.6 3.3-64h185.3c2.2 20.4 3.3 41.8 3.3 64m28.8-64h123.1c5.3 20.5 8.1 41.9 8.1 64s-2.8 43.5-8.1 64H380.8c2.1-20.6 3.2-42 3.2-64s-1.1-43.4-3.2-64m112.6-32H376.7c-10-63.9-29.8-117.4-55.3-151.6 78.3 20.7 142 77.5 171.9 151.6zm-149.1 0H167.7c6.1-36.4 15.5-68.6 27-94.7 10.5-23.6 22.2-40.7 33.5-51.5C239.4 3.2 248.7 0 256 0s16.6 3.2 27.8 13.8c11.3 10.8 23 27.9 33.5 51.5 11.6 26 20.9 58.2 27 94.7m-209 0H18.6c30-74.1 93.6-130.9 172-151.6-25.5 34.2-45.3 87.7-55.3 151.6M8.1 192h123.1c-2.1 20.6-3.2 42-3.2 64s1.1 43.4 3.2 64H8.1C2.8 299.5 0 278.1 0 256s2.8-43.5 8.1-64m186.6 254.6c-11.6-26-20.9-58.2-27-94.6h176.6c-6.1 36.4-15.5 68.6-27 94.6-10.5 23.6-22.2 40.7-33.5 51.5-11.2 10.7-20.5 13.9-27.8 13.9s-16.6-3.2-27.8-13.8c-11.3-10.8-23-27.9-33.5-51.5zM135.3 352c10 63.9 29.8 117.4 55.3 151.6-78.4-20.7-142-77.5-172-151.6zm358.1 0c-30 74.1-93.6 130.9-171.9 151.6 25.5-34.2 45.2-87.7 55.3-151.6h116.7z"/></svg>
</a>
<a href="https://labs.etsi.org/rep/tfs" target="_blank" rel="noopener" title="labs.etsi.org" class="md-social__link">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.6.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2024 Fonticons, Inc.--><path d="m503.5 204.6-.7-1.8-69.7-181.78c-1.4-3.57-3.9-6.59-7.2-8.64-2.4-1.55-5.1-2.515-8-2.81s-5.7.083-8.4 1.11c-2.7 1.02-5.1 2.66-7.1 4.78-1.9 2.12-3.3 4.67-4.1 7.44l-47 144H160.8l-47.1-144c-.8-2.77-2.2-5.31-4.1-7.43-2-2.12-4.4-3.75-7.1-4.77a18.1 18.1 0 0 0-8.38-1.113 18.4 18.4 0 0 0-8.04 2.793 18.1 18.1 0 0 0-7.16 8.64L9.267 202.8l-.724 1.8a129.57 129.57 0 0 0-3.52 82c7.747 26.9 24.047 50.7 46.447 67.6l.27.2.59.4 105.97 79.5 52.6 39.7 32 24.2c3.7 1.9 8.3 4.3 13 4.3s9.3-2.4 13-4.3l32-24.2 52.6-39.7 106.7-79.9.3-.3c22.4-16.9 38.7-40.6 45.6-67.5 8.6-27 7.4-55.8-2.6-82"/></svg>
</a>
<a href="https://www.linkedin.com/company/teraflowsdn/" target="_blank" rel="noopener" title="www.linkedin.com" class="md-social__link">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--! Font Awesome Free 6.6.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2024 Fonticons, Inc.--><path d="M416 32H31.9C14.3 32 0 46.5 0 64.3v383.4C0 465.5 14.3 480 31.9 480H416c17.6 0 32-14.5 32-32.3V64.3c0-17.8-14.4-32.3-32-32.3M135.4 416H69V202.2h66.5V416zm-33.2-243c-21.3 0-38.5-17.3-38.5-38.5S80.9 96 102.2 96c21.2 0 38.5 17.3 38.5 38.5 0 21.3-17.2 38.5-38.5 38.5m282.1 243h-66.4V312c0-24.8-.5-56.7-34.5-56.7-34.6 0-39.9 27-39.9 54.9V416h-66.4V202.2h63.7v29.2h.9c8.9-16.8 30.6-34.5 62.9-34.5 67.2 0 79.7 44.3 79.7 101.9z"/></svg>
</a>
<a href="https://twitter.com/TeraflowSDN" target="_blank" rel="noopener" title="twitter.com" class="md-social__link">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.6.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2024 Fonticons, Inc.--><path d="M389.2 48h70.6L305.6 224.2 487 464H345L233.7 318.6 106.5 464H35.8l164.9-188.5L26.8 48h145.6l100.5 132.9zm-24.8 373.8h39.1L151.1 88h-42z"/></svg>
</a>
</div>
</div>
</div>
</footer>
</div>
<div class="md-dialog" data-md-component="dialog">
<div class="md-dialog__inner md-typeset"></div>
</div>
<div class="md-progress" data-md-component="progress" role="progressbar"></div>
<script id="__config" type="application/json">{"base": "../..", "features": ["navigation.instant", "navigation.instant.progress", "navigation.top", "navigation.footer", "navigation.path", "search", "search.highlight", "toc.integrate"], "search": "../../assets/javascripts/workers/search.6ce7567c.min.js", "translations": {"clipboard.copied": "Copied to clipboard", "clipboard.copy": "Copy to clipboard", "search.result.more.one": "1 more on this page", "search.result.more.other": "# more on this page", "search.result.none": "No matching documents", "search.result.one": "1 matching document", "search.result.other": "# matching documents", "search.result.placeholder": "Type to start searching", "search.result.term.missing": "Missing", "select.version": "Select version"}, "version": {"provider": "mike"}}</script>
<script src="../../assets/javascripts/bundle.83f73b43.min.js"></script>
</body>
</html>