Skip to content

Commit

Permalink
Merge pull request #10 from PSU-Capstone-Team24/IPCP_Tracking
Browse files Browse the repository at this point in the history
SWENG480-161
  • Loading branch information
masonticehurst authored Jan 27, 2024
2 parents e86234e + 9e08817 commit 5ff69ee
Show file tree
Hide file tree
Showing 12 changed files with 207 additions and 48 deletions.
19 changes: 17 additions & 2 deletions .github/workflows/ada.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:

- uses: alire-project/setup-alire@v2

- name: Set up GNAT toolchain
- name: Install Dependencies
run: >
sudo apt-get update &&
sudo apt-get install gcc g++ libprotobuf-dev protobuf-compiler cmake linux-headers-$(uname -r) python-is-python3 swig wpasupplicant hostapd &&
Expand All @@ -29,8 +29,23 @@ jobs:
sudo make install depmod
- name: Build
run: cd eRINA_Linux && alr build
run: >
cd eRINA_Linux &&
alr build &&
cd ..
- name: Run UIPCPS
run: >
sudo modprobe rlite &&
sudo modprobe rlite-normal &&
sudo rlite-uipcps &
- name: Execute Tests
run: >
cd eRINA_Tests &&
alr build &&
sudo ./bin/erina_tests
- name: Slack Notification Success
if: success()
uses: rtCamp/action-slack-notify@v2
Expand Down
22 changes: 22 additions & 0 deletions eRINA_Linux/src/ada_src/bindings-rlite-api.adb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ pragma Style_Checks (Off);

-- Bindings
with Bindings.Rlite.Ctrl;

-- Exceptions
with Exceptions;

package body Bindings.Rlite.API is
Expand Down Expand Up @@ -37,6 +39,26 @@ package body Bindings.Rlite.API is
return Ctrl.RINA_Create_IPCP (Fd, To_Bounded_String (Name), DIF_Type, To_Bounded_String (DIF_Name));
end RINA_Create_IPCP;

-- Removes/destroys an existing IPCP by name
procedure RINA_Destroy_IPCP (
Fd : OS.File_Descriptor;
Name : String) is
Bounded_Name : constant Bounded_String := To_Bounded_String (Name);
begin
if Ctrl.IPCP_Map.Contains (Bounded_Name) then
RINA_Destroy_IPCP(Fd, Ctrl.IPCP_Map (Bounded_Name));
end if;
end RINA_Destroy_IPCP;

-- Removes/destroys an existing IPCP by its IPCP_Id
-- (This can be looked up via the IPCP hashmap in Ctrl logic)
procedure RINA_Destroy_IPCP (
Fd : OS.File_Descriptor;
Id : Rl_Ipcp_Id_T) is
begin
Ctrl.RINA_Destroy_IPCP (Fd, Id);
end RINA_Destroy_IPCP;

function RINA_Register (Fd : OS.File_Descriptor;
DIF_Name : String;
Local_Appl : String;
Expand Down
13 changes: 13 additions & 0 deletions eRINA_Linux/src/ada_src/bindings-rlite-api.ads
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@ package Bindings.Rlite.API is
DIF_Name : String
) return Rl_IPCP_Id_T;

-- Removes/destroys an existing IPCP by name
procedure RINA_Destroy_IPCP (
Fd : OS.File_Descriptor;
Name : String
);

-- Removes/destroys an existing IPCP by its IPCP_Id
-- (This can be looked up via the IPCP hashmap in Ctrl logic)
procedure RINA_Destroy_IPCP (
Fd : OS.File_Descriptor;
Id : Rl_Ipcp_Id_T
);

-- Register the application name local_appl to a DIF in the system.
-- After a successful registration, flow allocation requests can be received
-- on fd.
Expand Down
54 changes: 50 additions & 4 deletions eRINA_Linux/src/ada_src/bindings-rlite-ctrl.adb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,26 @@ with Names;
with Exceptions;

with Bindings.Rlite.Msg.Register;
with Bindings.Rlite.Msg.IPCP;

package body Bindings.Rlite.Ctrl is

-- I don't like this being here
-- we should separate the IPCP map and relevant funcs to a separate package
function Search_Map_By_Value
(Map_Var : in out Map; Value : Rl_Ipcp_Id_T) return Cursor is
Index : Cursor := No_Element;
begin
while Index /= No_Element loop
if Map_Var (Index) = Value then
return Index;
end if;

Index := Next (Index);
end loop;

return No_Element;
end Search_Map_By_Value;

procedure Rl_Write_Msg
(Rfd : OS.File_Descriptor;
Msg : Byte_Buffer;
Expand Down Expand Up @@ -59,9 +75,6 @@ package body Bindings.Rlite.Ctrl is
return Buffer;
end Rl_Read_Msg;

-- TODO: Check special case where IPCP already exists
-- i.e. Probe for IPCP first, if exists, return that IPCP_ID
-- otherwise, create it. This way no exceptions thrown on deserialize later...
function RINA_Create_IPCP (
Fd : OS.File_Descriptor;
Name : Bounded_String;
Expand All @@ -71,6 +84,12 @@ package body Bindings.Rlite.Ctrl is
Request : IPCP.Create;
Response : IPCP.Create_Response;
begin

-- If we're trying to create an IPCP that already exists, return the known IPCP_Id
if IPCP_Map.Contains (Name) then
return IPCP_Map (Name);
end if;

Request.Hdr.Msg_Type := RLITE_KER_IPCP_CREATE;
Request.Hdr.Event_Id := 1;
Request.Ipcp_Name := Name;
Expand Down Expand Up @@ -98,10 +117,37 @@ package body Bindings.Rlite.Ctrl is
Debug.Print("RINA_Create_IPCP", "Deserialized wrong event_id?", Debug.Error);
raise Exceptions.IPCP_Creation_Exception;
end if;

-- Insert into IPCP name => IPCP ID map
-- The hashmap will simply update if this name already exists
IPCP_Map.Include(Name, Response.Ipcp_Id);

return Response.Ipcp_Id;
end RINA_Create_IPCP;

procedure RINA_Destroy_IPCP (
Fd : OS.File_Descriptor;
Id : Rl_Ipcp_Id_T) is
Request : IPCP.Destroy;
Index : Cursor;
begin
Request.Hdr.Msg_Type := RLITE_KER_IPCP_DESTROY;
Request.Hdr.Event_Id := 1;
Request.Ipcp_Id := Id;

declare
Buffer : constant Byte_Buffer := IPCP.Serialize (Request);
begin
Rl_Write_Msg (Fd, Buffer, 0);
end;

Index := Search_Map_By_Value (IPCP_Map, Id);

if Index /= No_Element then
IPCP_Map.Delete (Index);
end if;
end RINA_Destroy_IPCP;

function RINA_Register_Wait (Fd : OS.File_Descriptor;
Wfd : OS.File_Descriptor) return OS.File_Descriptor is
Buffer : Byte_Buffer(1 .. 4096) := (others => 0);
Expand Down
19 changes: 19 additions & 0 deletions eRINA_Linux/src/ada_src/bindings-rlite-ctrl.ads
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ pragma Style_Checks (Off);

with Interfaces;
use Interfaces;

with Ada.Containers.Doubly_Linked_Lists;
with Ada.Containers.Hashed_Maps;
use Ada.Containers;

with Bindings.Rlite.API;
with Bindings.Rlite.Common;
Expand Down Expand Up @@ -49,6 +52,18 @@ package Bindings.Rlite.Ctrl is
package Sig_Action_List is new Ada.Containers.Doubly_Linked_Lists
(Element_Type => Sa_Pending_Item);

package IPCP_Id_Map is new Ada.Containers.Hashed_Maps (
Key_Type => Bounded_String,
Element_Type => Rl_Ipcp_Id_T,
Hash => Names.Hash,
Equivalent_Keys => "="
);

use IPCP_Id_Map;

IPCP_Map : Map;
function Search_Map_By_Value (Map_Var : in out Map; Value : Rl_Ipcp_Id_T) return Cursor;

function RINA_Register_Common (Fd : OS.File_Descriptor;
Dif_Name : Bounded_String;
Local_Appl : Bounded_String;
Expand All @@ -63,6 +78,10 @@ package Bindings.Rlite.Ctrl is
DIF_Name : Bounded_String
) return Rl_IPCP_Id_T;

procedure RINA_Destroy_IPCP (
Fd : OS.File_Descriptor;
Id : Rl_Ipcp_Id_T);

-- struct rl_msg_base *rl_read_next_msg(int rfd, int quiet)
function Rl_Read_Msg (
Rfd : OS.File_Descriptor;
Expand Down
3 changes: 0 additions & 3 deletions eRINA_Linux/src/ada_src/messages/bindings-rlite-msg-flow.ads
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ pragma Style_Checks (Off);
with Bindings.Rlite.Msg;
use Bindings.Rlite.Msg;

with Bindings.Rlite.List;
use Bindings.Rlite;

package Bindings.Rlite.Msg.Flow is

RINA_FLOW_SPEC_VERSION : constant Unsigned_32 := 2;
Expand Down
25 changes: 18 additions & 7 deletions eRINA_Linux/src/ada_src/messages/bindings-rlite-msg-ipcp.adb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package body Bindings.Rlite.Msg.IPCP is

IPCP_Name_Ptr : constant Byte_Buffer := To_Packed_Buffer (Self.Ipcp_Name);

DIF_Type : String := Ada.Characters.Handling.To_Lower (DIF_Types'Image (Self.DIF_Type));
DIF_Type : constant String := Ada.Characters.Handling.To_Lower (DIF_Types'Image (Self.DIF_Type));

DIF_Type_Size : constant Unsigned_16 := Unsigned_16 (DIF_Type'Size / 8);

Expand All @@ -39,11 +39,6 @@ package body Bindings.Rlite.Msg.IPCP is
begin
return Serialized_Msg;
end Serialize;

procedure Deserialize (Self : in out Create; fd : OS.File_Descriptor) is
begin
raise Exceptions.Not_Implemented_Exception;
end Deserialize;

function Serialize (Self : in Create_Response) return Byte_Buffer is
t : constant Byte_Buffer(1 .. 128) := (others => 0);
Expand All @@ -52,10 +47,11 @@ package body Bindings.Rlite.Msg.IPCP is
return t;
end Serialize;

overriding
procedure Deserialize (Self : in out Create_Response; Fd : OS.File_Descriptor) is
Buffer : constant Byte_Buffer := Read_Next_Msg (Fd);
Msg_Data : constant Byte_Buffer := Buffer(Rl_Msg_Hdr'Size / 8 + 1 .. Buffer'Size / 8);
Offset : Integer := Msg_Data'First;
Offset : constant Integer := Msg_Data'First;
begin
-- Byte buffer must not include any tagged record parts. This assumes
-- byte_buffer is coming from C struct read from FD and not Ada!
Expand All @@ -69,4 +65,19 @@ package body Bindings.Rlite.Msg.IPCP is
Self.Ipcp_Id := Rl_Ipcp_Id_T (Buffer_To_Unsigned_16(Msg_Data(Offset .. Offset + 1)));
end Deserialize;

overriding
function Serialize (Self : Destroy) return Byte_Buffer is
Hdr_Ptr : constant Byte_Buffer(1 .. Self.Hdr'Size / 8)
with Address => Self.Hdr'Address, Import, Volatile;

IPCP_Id : constant Byte_Buffer(1 .. Self.Ipcp_Id'Size / 8)
with Address => Self.Ipcp_Id'Address, Import, Volatile;

Pad1 : constant Byte_Buffer(1 .. 6) := (others => 0);

Serialized_Msg : constant Byte_Buffer := Hdr_Ptr & IPCP_Id & Pad1;
begin
return Serialized_Msg;
end Serialize;

end Bindings.Rlite.Msg.IPCP;
15 changes: 10 additions & 5 deletions eRINA_Linux/src/ada_src/messages/bindings-rlite-msg-ipcp.ads
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ package Bindings.Rlite.Msg.IPCP is
end record;
pragma Pack(Create);

overriding
procedure Deserialize (Self : in out Create; fd : OS.File_Descriptor);

overriding
function Serialize (Self : in Create) return Byte_Buffer;

Expand All @@ -25,9 +22,17 @@ package Bindings.Rlite.Msg.IPCP is
pragma Pack(Create_Response);

overriding
procedure Deserialize (Self : in out Create_Response; fd : OS.File_Descriptor);
function Serialize (Self : in Create_Response) return Byte_Buffer;

overriding
function Serialize (Self : in Create_Response) return Byte_Buffer;
procedure Deserialize (Self : in out Create_Response; Fd : OS.File_Descriptor);

type Destroy is new Rl_Msg_Base with record
Ipcp_Id : Rl_Ipcp_Id_T;
end record;
pragma Pack(Destroy);

overriding
function Serialize (Self : in Destroy) return Byte_Buffer;

end Bindings.Rlite.Msg.IPCP;
2 changes: 1 addition & 1 deletion eRINA_Linux/src/ada_src/messages/bindings-rlite-msg.ads
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ package Bindings.Rlite.Msg is

-- Abstract base serialization function, must be overridden by child messages
function Serialize (Self : in Rl_Msg_Base) return Byte_Buffer is abstract;
procedure Deserialize (Self : in out Rl_Msg_Base; fd : OS.File_Descriptor) is abstract;
procedure Deserialize (Self : in out Rl_Msg_Base; fd : OS.File_Descriptor) is null;

function Read_Next_Msg(fd : OS.File_Descriptor) return Byte_Buffer;

Expand Down
4 changes: 4 additions & 0 deletions eRINA_Linux/src/ada_src/names.adb
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ package body Names is

return Buffer;
end To_Packed_Buffer;

function Hash(Name : in Bounded_String) return Ada.Containers.Hash_Type is begin
return Ada.Strings.Hash(To_String (Name));
end Hash;
end Names;
11 changes: 8 additions & 3 deletions eRINA_Linux/src/ada_src/names.ads
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
-- Temp disabling
pragma Style_Checks (Off);

with Ada.Strings;
with Ada.Strings.Hash;
with Ada.Strings.Bounded;

with Ada.Containers;

with Buffers;
use Buffers;

with Interfaces;
use Interfaces;

-- Max name length to be used for DIF_Name, Appl_Name, etc
package Names is
package Name_String is new Ada.Strings.Bounded.Generic_Bounded_Length
Expand All @@ -19,4 +21,7 @@ package Names is

-- Takes a Bounded String and returns the packed buffer of all characters up to null terminator
function To_Packed_Buffer(Input : Bounded_String) return Byte_Buffer;

-- Takes in a bounded_string and returns a unique hash code
function Hash(Name : in Bounded_String) return Ada.Containers.Hash_Type;
end Names;
Loading

0 comments on commit 5ff69ee

Please sign in to comment.