# How to build Magma AGW using Vagrant

### `Prerequisites`

[`VirtualBox`](https://www.virtualbox.org/) [`Vagrant`](https://vagrantup.com/)

### `Setting up AGW`

---

## `Download magma repo`:

[Magma repo](https://github.com/magma/magma.git)

```go
git clone https://github.com/magma/magma.git
```

### `Move to gateway folder:`

```go
cd magma/lte/gateway
```

### `download vagrant box:`

```go
vagrant box add magmacore/magma_dev \
  --box-version=1.1.20210618 \
  --provider=virtualbox
```

### `install ansible:`

```go
Ubuntu
sudo apt install ansible

Fedora/Centos
sudo dnf install ansible

Mac
brew install ansible
```

### `start vagrant box:`

```go
vagrant up magma
```

`ssh inside vagrant box:`

```go
vagrant ssh magma
username: vagrant 
password: vagrant
```

## `Build AGW`

### `build AGW`

```go
cd magma/lte/gateway
make run
```

### `Install scp plugin for Vagrant and copy the rootCA.pem file to AGW`

```go
vagrant plugin install vagrant-scp
vagrant scp /tmp/rootCA.pem magma:~

vagrant ssh magma
```

## `Configure AGW`

### `First, copy the root CA for your Orchestrator deployment into your AGW:`

```go
sudo mkdir -p /var/opt/magma/tmp/certs/
sudo mv rootCA.pem /var/opt/magma/tmp/certs/rootCA.pem
```

### `Then, point your AGW to your Orchestrator:`

```go
sudo mkdir -p /var/opt/magma/configs
cd /var/opt/magma/configs
sudo vim control_proxy.yml
```

### `Put the following contents into the file:`

```go
cloud_address: controller.magma.redemption.com 
cloud_port: 443
bootstrap_address: bootstrapper-controller.magma.redemption.com
bootstrap_port: 443
fluentd_address: fluentd.magma.redemption.com
fluentd_port: 24224

You can use your custom dns configs for the above 

rootca_cert: /var/opt/magma/tmp/certs/rootCA.pem
```

### `Then restart your services to pick up the config changes:`

```go
sudo service magma@* stop
sudo service magma@magmad restart
sudo service magma@magmad status

# check status of magma services
sudo systemctl status magma@*
```

### `check logs:`

```go
sudo tail -f /var/log/syslog
sudo journalctl -fu magma@magmad
```

### `Grab the hardware secrets off your AGW:`

```go
show_gateway_info.py

# if above command doesn't work
sudo pip3 install snowflake
export AGW_SCRIPTS=/home/vagrant/magma/orc8r/gateway/python
ln -s ${AGW_SCRIPTS}/magma ${AGW_SCRIPTS}/scripts/
${AGW_SCRIPTS}/scripts/show_gateway_info.py
```

test network:

```go
checkin_cli.py
```

## `Extras`

### `Generate new Challenge key:`

```go
cd /var/opt/magma/certs

# Generate Private key
sudo openssl ecparam -name secp384r1 -genkey -noout -out gw_challenge.key
sudo chmod 644 gw_challenge.key

# Generate Public key
openssl ec -in gw_challenge.key -pubout -out gw_challenge.pem
GW_CHALLENGE=$(cat gw_challenge.pem | sed '5d' | sed '1d' | tr -d '\n')
echo ${GW_CHALLENGE}
```

### `Generate new Hardware ID:`

```go
sudo uuidgen > /etc/snowflake
sudo snowflake --force-new-key
```

### `Remove gateway keys and network config:`

```go
sudo rm /var/opt/magma/certs/gateway.crt
sudo rm /var/opt/magma/certs/gateway.key
sudo rm /var/opt/magma/configs/gateway.mconfig
```

### `Check certificate details:`

```go
openssl x509 -text -noout -in rootCA.pem

openssl x509 -text -noout -in /var/opt/magma/tmp/certs/rootCA.pem
```

%[https://www.youtube.com/channel/UCf-tTLM6XzMZK7WPXpUKVMg]
