Skip to content

nikiblume/-SoSecAutSys

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Traffic Control Group6 SSAS

This project provides a Traffic Control Management System built using Java, Quarkus, and Kubernetes. It includes APIs for managing traffic lights, retrieving their statuses, and simulating real-world traffic light systems.

Setting Up and Running the IVSSAS Sandbox Environment

This part provides step-by-step instructions for setting up a clean Kind cluster, configuring Keycloak, deploying Quarkus microservices, and testing endpoints.


Prerequisites

Before starting, ensure you have the following installed:

  • Java (version 11 or higher)
  • Maven (version 3.6.3 or higher)
  • Docker (latest stable version)
  • Kind (Kubernetes in Docker)
  • Kubectl (command-line tool for Kubernetes)
  • Helm

1. Clean Kind Cluster Creation

  1. Clone the repository:

    git clone <repository-url>
    cd SoSecAutSys
  2. Delete any existing Kind cluster:

    kind delete cluster -n ivssas-sandbox
  3. Navigate to the Kind setup directory and start the cluster:

    cd kind
    ./start-cluster
  4. Wait for the script to complete successfully. If the script fails, restart it without deleting the cluster to create only the uncreated instances.

  5. Verify the Keycloak pods are in a running state:

    kubectl get pods -A

2. Create Realm in Keycloak

Import Realm Using the Browser

  1. Login to Keycloak under "localhost" in your browser (default credentials: Username: admin, Password: changeme).
  2. Click on the top-left dropdown menu and select "Create Realm."
  3. Browse for the ./keycloak/quarkus.json file and import it to create the realm.

3. Deploy Quarkus Microservices

  1. Build and deploy the Quarkus microservices:

    ./mvnw clean package -Dquarkus.kubernetes.deploy=true
  2. Alternatively, deploy while skipping tests:

    ./mvnw clean package -DskipTests -Dquarkus.kubernetes.deploy=true
  3. Ensure all microservice pods are running:

    kubectl get pods -A

    Output should be looking like this:

NAMESPACE            NAME                                                       READY   STATUS      RESTARTS   AGE
cert-manager         cert-manager-77c5f7bf75-z4pxs                              1/1     Running     0          23m
cert-manager         cert-manager-cainjector-669d85f6cf-fnb6j                   1/1     Running     0          23m
cert-manager         cert-manager-webhook-585b8b6bfc-g48jb                      1/1     Running     0          23m
cert-manager         trust-manager-64945d7598-fqhjv                             1/1     Running     0          22m
ingress-nginx        ingress-nginx-controller-58f597f7dd-79c56                  1/1     Running     0          20m
keycloak             keycloak-0                                                 1/1     Running     0          20m
keycloak             keycloak-postgresql-0                                      1/1     Running     0          20m
kube-system          coredns-7c65d6cfc9-4zgvs                                   1/1     Running     0          23m
kube-system          coredns-7c65d6cfc9-qq587                                   1/1     Running     0          23m
kube-system          etcd-ivssas-sandbox-control-plane                          1/1     Running     0          23m
kube-system          kindnet-l45tz                                              1/1     Running     0          23m
kube-system          kube-apiserver-ivssas-sandbox-control-plane                1/1     Running     0          23m
kube-system          kube-controller-manager-ivssas-sandbox-control-plane       1/1     Running     0          23m
kube-system          kube-proxy-wlzdx                                           1/1     Running     0          23m
kube-system          kube-scheduler-ivssas-sandbox-control-plane                1/1     Running     0          23m
kyverno-system       kyverno-admission-controller-757bb5cfd-xb9tf               1/1     Running     0          22m
kyverno-system       kyverno-background-controller-84dc569d49-5c7z9             1/1     Running     0          22m
kyverno-system       kyverno-cleanup-admission-reports-28958910-q9qcf           0/1     Completed   0          9m51s
kyverno-system       kyverno-cleanup-cluster-admission-reports-28958910-s8znb   0/1     Completed   0          9m51s
kyverno-system       kyverno-cleanup-controller-5f8d965c6b-92h4x                1/1     Running     0          22m
kyverno-system       kyverno-reports-controller-546d4bd5-qlqjf                  1/1     Running     0          22m
local-path-storage   local-path-provisioner-57c5987fd4-7jkrb                    1/1     Running     0          23m
traffic-control      cli-55c8dfbf94-hv5ll                                       1/1     Running     0          6m13s
traffic-control      intersection-65dfd67446-tk755                              1/1     Running     0          6m23s
traffic-control      tmc-69959c9447-lq6bf                                       1/1     Running     0          6m34s

4. Resolve .test Addresses for Microservices

  1. Get your localhost ip address and look for inet ip address:

    ip a
  2. Map the .test domains to your localhost address:

    echo -e "172.28.183.106 tmc.test\n172.28.183.106 intersection.test\n172.28.183.106 cli.test" | sudo tee -a /etc/hosts
  3. Replace 172.28.183.106 with your actual localhost address.


5. Customize the CLI Microservice User

  1. Open the application.properties file:

    ./cli/src/main/resources/application.properties
  2. Modify the user settings starting from line 82 by commenting/uncommenting the desired username. The password remains unchanged.


6. Test Endpoints

  1. TMC microservice

    curl -k https://tmc.test/tmc-api/test
  2. Intersection Microservice

    curl http://intersection.test/intersection-api/message
  3. CLI Microservice

    curl -k https://cli.test/cli-api/test
    curl -k -X POST https://cli.test/cli-api/create/40.652345/-124.280345/0/90/PEDESTRIAN

7. Run the CLI

  1. Execute the main method in the TMCCLI class:
    ./cli/src/main/java/de/tub/aot/TMCCLI.java
    
    See below for an overview of the API and keycloak-roles.

Congrats, your done!

Keycloak-Roles

Default Role: tmc-operator (has all rights)

TMC and Intersection Microservice Roles

  • tmc (tmc microservice)
  • intersection (intersection microservice)

CLI Microservice Roles (can act as different users. For changing see 5. in setup above)

  • tmc-admin
  • tmc-operator
  • emergency-vehicle
  • mayor-vehicle
  • autonomous-vehicle
  • regular-vehicle

Traffic Control Management CLI - API Endpoints

Base URL: https://tmc.test/tmc-api/

1. Create Traffic Light

Create a new traffic light at a specified location and heading.

  • URL: /tmc-api/create/{lat_deg}/{lon_deg}/{altitudeAboveNN_m}/{heading}/{type}
  • Method: POST
  • Roles Allowed: tmc-operator
  • Parameters:
    • lat_deg (PathParam): Latitude in degrees.
    • lon_deg (PathParam): Longitude in degrees.
    • altitudeAboveNN_m (PathParam): Altitude above sea level in meters.
    • heading (PathParam): Direction the traffic light is facing, in degrees.
    • type (PathParam): Type of the traffic light (VEHICLE or PEDESTRIAN).

2. Get Traffic Light Status

Retrieve the status of a specific traffic light.

  • URL: /tmc-api/{trafficLightId}/status
  • Method: GET
  • Roles Allowed: tmc-operator, tmc-admin, emergency-vehicle, mayor-vehicle, autonomous-vehicle
  • Parameters:
    • trafficLightId (PathParam): Unique identifier of the traffic light.

3. Get All Traffic Lights Status

Retrieve the status of all traffic lights.

  • URL: /tmc-api/trafficLights/status
  • Method: GET
  • Roles Allowed: tmc-operator, tmc-admin, emergency-vehicle, mayor-vehicle, autonomous-vehicle

4. Request green light

Request green for a traffic light.

  • URL: /tmc-api/requestGreen/{trafficLightId}
  • Method: PUT
  • Roles Allowed: tmc-operator, emergency-vehicle, mayor-vehicle

5. Remove Traffic Light

Remove a traffic light by its unique ID.

  • URL: /tmc-api/remove/{trafficLightId}
  • Method: DELETE
  • Roles Allowed: tmc-operator
  • Parameters:
    • trafficLightId (PathParam): Unique identifier of the traffic light.

6. Set Traffic Light Color

Set the color of a specific traffic light.

  • URL: /tmc-api/set/{id}/{color}
  • Method: PUT
  • Roles Allowed: tmc-operator
  • Parameters:
    • id (PathParam): Unique identifier of the traffic light.
    • color (PathParam):
      • For vehicle lights: green, yellow, red, yellow_flashing, red_yellow
      • For pedestrian lights: green, red.

7. Disable Traffic Light

Disable (turn off) a specific traffic light.

  • URL: /tmc-api/disable/{id}
  • Method: PUT
  • Roles Allowed: tmc-operator
  • Parameters:
    • id (PathParam): Unique identifier of the traffic light.

8. Enable Traffic Light

Enable (turn on) a specific traffic light with an initial color.

  • URL: /tmc-api/enable/{id}/{color}
  • Method: PUT
  • Roles Allowed: tmc-operator
  • Parameters:
    • id (PathParam): Unique identifier of the traffic light.
    • color (PathParam): Initial color after enabling.
      • For vehicle lights: green, yellow, yellow_flashing, red_yellow
      • For pedestrian lights: green, red.

9. Link Two Traffic Lights

Link two traffic lights to coordinate their behavior.

  • URL: /tmc-api/link/{id1}/{id2}
  • Method: PUT
  • Roles Allowed: tmc-operator
  • Parameters:
    • id1 (PathParam): Unique identifier of the first traffic light.
    • id2 (PathParam): Unique identifier of the second traffic light.

Curl commands

Creating a Traffic Light

curl -k -X POST http://cli.test/cli-api/create/40.652345/-124.280345/0/90/pedestrian

Getting the Status of a Traffic Light

# needs to be valid UUID
curl -k http://cli.test/cli-api/c8a0b04d-f94d-491e-ab0d-e2457188f153/status

Getting the Status of All Traffic Lights

curl -k http://cli.test/cli-api/trafficLights/status

Requesting green for a Traffic Light

curl -k -X PUT http://cli.test/cli-api/requestGreen/4957d6e1-deb0-3265-ae9d-63687a96b941

Removing a Traffic Light

curl -k -X DELETE http://cli.test/cli-api/remove/4957d6e1-deb0-3265-ae9d-63687a96b941

Set Traffic Light Color

curl -k -X PUT https://cli.test/cli-api/set/c8a0b04d-f94d-491e-ab0d-e2457188f153/green

Disable Traffic Light

curl -k -X PUT https://cli.test/cli-api/disable/c8a0b04d-f94d-491e-ab0d-e2457188f153

Enable Traffic Light

curl -k -X PUT https://cli.test/cli-api/enable/c8a0b04d-f94d-491e-ab0d-e2457188f153/green

Link Two Traffic Lights

curl -k -X PUT https://cli.test/cli-api/link/c8a0b04d-f94d-491e-ab0d-e2457188f153/4957d6e1-deb0-3265-ae9d-63687a96b941

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •