Skip to content

Commit

Permalink
Update ueransim
Browse files Browse the repository at this point in the history
  • Loading branch information
niloysh committed Oct 14, 2023
1 parent ad6f3b8 commit e510f7d
Show file tree
Hide file tree
Showing 19 changed files with 179 additions and 332 deletions.
42 changes: 42 additions & 0 deletions bin/k8s-log.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

if [[ $# -eq 0 ]]; then
echo "Usage: k8s-logs <keyword> [namespace]"
exit 1
fi

keyword=$1
namespace=$2

if [[ -z $namespace ]]; then
echo "Select namespace:"
namespaces=($(kubectl get namespaces -o name | cut -d/ -f2))
PS3="Namespace: "
select namespace in "${namespaces[@]}"; do
if [[ -n $namespace ]]; then
break
fi
done
fi

pod=$(kubectl get pods -n "$namespace" | grep "$keyword" | head -1 | awk '{print $1}')
if [[ -z $pod ]]; then
echo "No pods found for keyword: $keyword"
exit 1
fi

containers=($(kubectl get pods "$pod" -n "$namespace" -o jsonpath='{.spec.containers[*].name}'))
if [[ ${#containers[@]} -eq 1 ]]; then
container=${containers[0]}
else
echo "Select container:"
PS3="Container: "
select container in "${containers[@]}"; do
if [[ -n $container ]]; then
break
fi
done
fi

kubectl logs -f "$pod" -n "$namespace" -c "$container"

82 changes: 82 additions & 0 deletions bin/k8s-shell.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/bin/bash

# function to print usage message
function usage {
echo "Usage: $0 keyword [namespace]"
echo " keyword: a string that identifies the pod you want to access, e.g. amf, smf, upf"
echo " namespace (optional): the Kubernetes namespace where the pod is running"
echo "If no namespace is specified, a namespace picker will be displayed."
}

# Function to prompt the user to select a namespace from a list
select_namespace() {
echo "Select a namespace:"
select NAMESPACE in $(kubectl get namespaces -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}')
do
if [ -n "$NAMESPACE" ]
then
break
fi
done
}

# Function to prompt the user to select a container from a list
select_container() {
echo "Select a container:"
select CONTAINER in $(kubectl get pod $POD -n $NAMESPACE -o jsonpath='{range .spec.containers[*]}{.name}{"\n"}{end}')
do
if [ -n "$CONTAINER" ]
then
break
fi
done
}

# Display help message if no arguments provided
if [ "$#" -eq 0 ]
then
usage
exit 1
fi

POD_KEYWORD=$1

# Prompt for namespace if not specified
if [ "$#" -eq 1 ]
then
select_namespace
else
NAMESPACE=$2
fi

POD=$(kubectl get pods -n $NAMESPACE | grep "$POD_KEYWORD" | awk '{print $1}')

if [ -z "$POD" ]
then
echo "No pod found with keyword: $POD_KEYWORD in namespace: $NAMESPACE"
exit 1
fi

CONTAINER_COUNT=$(kubectl get pod $POD -n $NAMESPACE -o jsonpath='{range .spec.containers[*]}{.name}{"\n"}{end}' | wc -l)

if [ "$CONTAINER_COUNT" -eq 1 ]
then
CONTAINER=$(kubectl get pod $POD -n $NAMESPACE -o jsonpath='{.spec.containers[0].name}')
else
select_container
fi

# Try bash shell, fallback to sh
SHELLS=("bash" "sh")
for SHELL in "${SHELLS[@]}"
do
if kubectl exec $POD -n $NAMESPACE -c $CONTAINER -- $SHELL -c 'exit 0' > /dev/null 2>&1
then
kubectl exec -it $POD -n $NAMESPACE -c $CONTAINER -- $SHELL
exit 0
fi
done

echo "No supported shell found in pod: $POD"
exit 1

2 changes: 1 addition & 1 deletion ueransim/ueransim-gnb/config/free5gc-gnb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ nci: '0x000000010' # NR Cell Identity (36-bit)
idLength: 32 # NR gNB ID length in bits [22...32]
tac: 1 # Tracking Area Code

linkIp: 129.97.168.65 # gNB's local IP address for Radio Link Simulation (Usually same with local IP)
linkIp: 0.0.0.0 # gNB's local IP address for Radio Link Simulation (Usually same with local IP)
ngapIp: 10.10.2.22 # gNB's local IP address for N2 Interface (Usually same with local IP)
gtpIp: 10.10.3.22 # gNB's local IP address for N3 Interface (Usually same with local IP)

Expand Down
2 changes: 2 additions & 0 deletions ueransim/ueransim-gnb/config/wrapper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
/ueransim/nr-gnb --config /ueransim/config/free5gc-gnb.yaml
40 changes: 0 additions & 40 deletions ueransim/ueransim-gnb/gnb-configmap.yaml

This file was deleted.

16 changes: 8 additions & 8 deletions ueransim/ueransim-gnb/gnb-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ spec:
component: gnb
annotations:
k8s.v1.cni.cncf.io/networks: '[
{ "name": "n2network", "interface": "n2", "ips": [ "10.10.2.31/24" ] },
{ "name": "n3network", "interface": "n3", "ips": [ "10.10.3.31/24" ] }
{ "name": "n2network", "interface": "n2", "ips": [ "10.10.2.22/24" ] },
{ "name": "n3network", "interface": "n3", "ips": [ "10.10.3.22/24" ] }
]'
spec:
containers:
Expand All @@ -39,20 +39,20 @@ spec:
name: gnb-volume
resources:
requests:
memory: "1024Mi"
cpu: "1000m"
memory: "256Mi"
cpu: "200m"
limits:
memory: "2048Mi"
cpu: "2000m"
memory: "512Mi"
cpu: "500m"
dnsPolicy: ClusterFirst
restartPolicy: Always
volumes:
- name: gnb-volume
configMap:
name: gnb-configmap
items:
- key: gnb-config.yaml
path: gnb-config.yaml
- key: free5gc-gnb.yaml
path: free5gc-gnb.yaml
- key: wrapper.sh
path: wrapper.sh
mode: 0777
9 changes: 7 additions & 2 deletions ueransim/ueransim-gnb/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- gnb-configmap.yaml
- gnb-deployment.yaml
- gnb-service.yaml
- gnb-service.yaml

configMapGenerator:
- name: gnb-configmap
files:
- config/free5gc-gnb.yaml
- config/wrapper.sh
72 changes: 0 additions & 72 deletions ueransim/ueransim-ue/config/ue3.yaml

This file was deleted.

File renamed without changes.
9 changes: 7 additions & 2 deletions ueransim/ueransim-ue/ue1/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
resources:
- ue-configmap.yaml
- ue-deployment.yaml
- ue-deployment.yaml

configMapGenerator:
- name: ue1-configmap
files:
- ue1.yaml
- wrapper.sh
Loading

0 comments on commit e510f7d

Please sign in to comment.