Commit Graph

423 Commits

Author SHA1 Message Date
Brian Kanyora
0a6078df65 Merged PR 129: feature/1641:Update config.rst
## Summary
Changed environment config to training config in config.rst as Chris requested.

## Checklist
- [X] This PR is linked to a **work item**
- [X] I have performed **self-review** of the code
- [X] I have written **tests** for any new functionality added with this PR
- [X] I have updated the **documentation** if this PR changes or adds functionality
- [X] I have run **pre-commit** checks for code style

feature/1641:
Changed environment config to training config

Related work items: #1641
2023-07-20 15:50:13 +00:00
Brian Kanyora
69e7b23d2c feature/1641:
Changed environment config to training config
2023-07-20 16:09:57 +01:00
Sunil Samra
ae8afbdcdc Merged PR 128: #1640 - Update Sphinx Docs for 2.0.0 Release
## Summary
Added to docs as per @<Christopher McCarthy> changes - added prefixes to command line primaite session and explained primate session default no arguments command.

## Test process
*NA*

## Checklist
- [X] This PR is linked to a **work item**
- [X] I have performed **self-review** of the code
- [X] I have written **tests** for any new functionality added with this PR
- [X] I have updated the **documentation** if this PR changes or adds functionality
- [X] I have run **pre-commit** checks for code style

#1640 - Added --ldc and --tc prefixes and added small note about primaite session default run command

Related work items: #1640
2023-07-20 14:31:05 +00:00
SunilSamra
6ce816f2e1 #1640 - Added --ldc and --tc prefixes and added small note about primaite session default run command 2023-07-20 14:45:55 +01:00
Brian Kanyora
f840e924e3 Merged PR 125: feature/1637:Updating-UML-Diagram
## Summary
Updated the UML diagram using puml to help render a better output of the diagram.

## Checklist
- [x] This PR is linked to a **work item**
- [x] I have performed **self-review** of the code
- [na] I have written **tests** for any new functionality added with this PR
- [na] I have updated the **documentation** if this PR changes or adds functionality
- [x] I have run **pre-commit** checks for code style

feature/1637:
Updating the UML diagram using puml instead of mmd.

Related work items: #1637
2023-07-20 13:34:26 +00:00
Christopher McCarthy
3bbc7b8615 Merged PR 126: PrimAITE Benchmarking
## Summary
 - Added full benchmarking script that included plots and a LaTeX report. Ran the v2.0.0rc1 benchmark. Tidied a few other things up.

The code is a bit scrappy. But it's not released code. I will endeavour to tidy it up at a later date.

## Test process
Manually ran the script. This is the final report -> [PrimAITE v2.0.0rc1 Learning Benchmark.pdf](https://dev.azure.com/ma-dev-uk/b50a61ee-86c4-48bc-9a0b-a67645ba12ee/_apis/git/repositories/2825053e-bd3b-45b2-8680-1281809eefa2/pullRequests/126/attachments/PrimAITE%20v2.0.0rc1%20Learning%20Benchmark.pdf)

## Checklist
- [X] This PR is linked to a **work item**
- [X] I have performed **self-review** of the code
- [ ] I have written **tests** for any new functionality added with this PR
- [ ] I have updated the **documentation** if this PR changes or adds functionality
- [X] I have run **pre-commit** checks for code style

Related work items: #1632
2023-07-20 12:58:54 +00:00
Marek Wolan
f6a9063484 Merged PR 127: Add license
## Summary
Add license file and reference it in the pyproject.toml

## Test process
Running `pip-licenses` shows:
```
 pre-commit                     2.20.0       MIT License
 primaite                       2.0.0rc1     MIT
 primaite                       2.0.0rc1     MIT
 prometheus-client              0.17.1       Apache Software License
 prompt-toolkit                 3.0.39       BSD License
```
## Checklist
- [x This PR is linked to a **work item**
- [x] I have performed **self-review** of the code
- [ ] I have written **tests** for any new functionality added with this PR
- [ ] I have updated the **documentation** if this PR changes or adds functionality
- [x] I have run **pre-commit** checks for code style

Related work items: #1638
2023-07-20 11:16:05 +00:00
Brian Kanyora
90620e0c64 feature/1637:
Fixed the relationship between PrimIATE and Transaction.
2023-07-20 10:54:42 +01:00
Chris McCarthy
3731b2ba13 #1632 - Fixed output directory clear bug. Added gputil to dev deps. 2023-07-20 10:28:19 +01:00
Marek Wolan
dd9613853b Apply suggestions from code review 2023-07-20 09:21:35 +00:00
Chris McCarthy
f22681d6b4 #1632 - Added Python version to the System Information section in the report 2023-07-20 10:16:29 +01:00
Chris McCarthy
e9fc9a0d1a #1632 - Increased rolling window from 5 to 25 2023-07-20 10:06:44 +01:00
Marek Wolan
1e24ce7b9a Add license 2023-07-20 10:03:05 +01:00
Chris McCarthy
afbe2e1400 #1632 - Added full benchmarking script that included plots and a LaTeX report. Ran the v2.0.0rc1 benchmark. Tidied a few other things up. 2023-07-20 08:48:18 +01:00
Brian Kanyora
f8959a65e9 feature/1637:
Updating the UML diagram using puml instead of mmd.
2023-07-19 17:03:10 +01:00
Chris McCarthy
ba6f8f054b Merge branch 'dev' into feature/1632_Add_benchmarking_scripts 2023-07-18 13:24:15 +01:00
Christopher McCarthy
52a7185583 Merged PR 124: #1635 - Updated the session outputs details in primaite_session.rst
## Summary
- Updated the session outputs details in primaite_session.rst
- Fixed Logger typehint bugs
- Fixed typing issues in access_control_list.py

## Test process
Build the docs

![image.png](https://dev.azure.com/ma-dev-uk/b50a61ee-86c4-48bc-9a0b-a67645ba12ee/_apis/git/repositories/2825053e-bd3b-45b2-8680-1281809eefa2/pullRequests/124/attachments/image.png)

## Checklist
- [ ] This PR is linked to a **work item**
- [ ] I have performed **self-review** of the code
- [ ] I have written **tests** for any new functionality added with this PR
- [ ] I have updated the **documentation** if this PR changes or adds functionality
- [ ] I have run **pre-commit** checks for code style

#1635 - Updated the session outputs details in primaite_session.rst

Related work items: #1635
2023-07-18 10:44:17 +00:00
Chris McCarthy
d730a206d8 #1635 - Fixed typing issues in access_control_list.py 2023-07-18 11:38:28 +01:00
Chris McCarthy
713aa279ec Merge branch 'dev' into feature/1635_Update_Primaite_Session_page_in_Docs
# Conflicts:
#	src/primaite/setup/old_installation_clean_up.py
#	src/primaite/setup/reset_example_configs.py
2023-07-18 11:36:31 +01:00
Chris McCarthy
e070b247b1 #1635 - Updated the session outputs details in primaite_session.rst
- Fixed Logger typehint bugs
2023-07-18 11:34:41 +01:00
Sunil Samra
a10a1d9267 Merged PR 120: Change Functionality of ACL Rules
## Summary
### ACL List
First change was I changed `access_control_list.py` from a `dict` to a `list` so it is now an ordered structure. This was done so I could implement the positions inside the `ACL` and `ANY` action spaces.

From this, some functions have changed such as `add_rule` and `remove_rule`, `is_blocked` and `get_relevant_rules`.

The ACL list is now a fixed size and on initialisation it is filled with `None` types. When a function calls `self.acl` the `implicit rule` (if there is one) is added after the last `ACLRule` object in the list. The remainder of the list (if there is left over space) is padded out with `None`.

As the agent adds rules, the `None` are replaced by `ACLRule` objects and the agent cannot overwrite an existing `ACLRule` with another, it can only write over `None` types.

### ACL Training Config Changes
Changes have been made to the `training_config_main.yaml`. There are 2 new items:

`implicit_acl_rule:` - Implicit ACL firewall rule at end of list to be default action (ALLOW or DENY)
`max_number_acl_rules:` - Total number of ACL rules allowed in the environment

In the `OBSERVATION_SPACE` area of the config, `ACCESS_CONTROL_LIST` can be selected

They have default values if none are specified so for the older configs - these values are in the `TrainingConfig` dataclass.

### ACL and ANY Action Spaces
I changed the ACL space from length of 6 to 7. I have included the `position` of where the agent wants to position the ACL Rule.

`position` = index in `self.acl` with bounds [0 to ...]

As a result, total possible actions have gone up.

### ACL Observation Space
In the observations.py I have made a new observation component: Access Control List.
It has the following mappings/meanings:

        [0, 1, 2] - Permission (0 = NA, 1 = DENY, 2 = ALLOW)
        [0, num nodes] - Source IP (0 = NA, 1 = any, then 2 -> x resolving to Node IDs)
        [0, num nodes] - Dest IP (0 = NA, 1 = any, then 2 -> x resolving to Node IDs)
        [0, num services] - Protocol (0 = NA, 1 = any, then 2 -> x resolving to protocol)
        [0, num ports] - Port (0 = NA, 1 = any, then 2 -> x resolving to port)
        [0, max acl rules - 1] - Position (0 = NA, 1 = first index, then 2 -> x index resolving to acl rule in acl list)

I created a new 0 meaning, which means NA and represents the None objects in the ACLList.

Also, there is no 'flatten' in the observation space components and this has been done in the observations.py now if there are multiple components.

## Test process
I have written tests in a new `TestAccessControlList` object in `test_observations.py`.

I ran a single test which was 1000 episodes, SB3/PPO, Config 5 and ACL Observation Space. I seemed to get some interesting results which may need investigating on Monday.

![Figure_1.png](https://dev.azure.com/ma-dev-uk/b50a61ee-86c4-48bc-9a0b-a67645ba12ee/_apis/git/repositories/2825053e-bd3b-45b2-8680-1281809eefa2/pullRequests/120/attachments/Figure_1.png)

## Checklist
- ...
2023-07-18 10:31:15 +00:00
Marek Wolan
9e3285350a Get tests working with new ACL changes 2023-07-18 11:16:39 +01:00
Marek Wolan
c5f612889e Merge remote-tracking branch 'origin/dev' into feature/901-change-functionality-acl-rules 2023-07-18 10:55:31 +01:00
Marek Wolan
9c6ee73b9e Merged PR 122: Typehint everything
## Summary
Added typehints to functions/methods, and class attributes.

## Test process
I used flake8-annotations and mypy to verify completeness and correctness. Mypy did throw up a very large number of errors and many of them point to some potential problems in the codebase. To elaborate, there are some places where there has been confusion as to whether objects should be strings, integers, or enums. Resolving this is out of scope of this PR but I will create more tickets with concrete examples.

## Checklist
- [x] This PR is linked to a **work item**
- [x] I have performed **self-review** of the code
- [ ] I have written **tests** for any new functionality added with this PR
- [ ] I have updated the **documentation** if this PR changes or adds functionality
- [x] I have run **pre-commit** checks for code style

Related work items: #1623
2023-07-18 09:43:08 +00:00
Marek Wolan
a2ef4328dd Remove redundant 'if TYPE_CHECKING' statements 2023-07-18 10:21:06 +01:00
Marek Wolan
393505b98b Ensure everything is still typehinted 2023-07-18 10:13:54 +01:00
Chris McCarthy
e198c17ac0 #1632 - Added bench marking script 2023-07-18 10:11:01 +01:00
Marek Wolan
a7a5fb8598 Mark failing tests as Xfail to force build success 2023-07-18 10:08:02 +01:00
Marek Wolan
3d0e50823a Merge branch 'dev' into feature/1623-typehints 2023-07-18 10:03:48 +01:00
Christopher McCarthy
15f37c938f Merged PR 123: #1631 - Added the DEFCON 703 header to all possible files
## Summary
Added the DEFCON 703 header to all possible files

## Test process
Built docs to confirm that the top-of-the-page comment does not break anything

## Checklist
- [X] This PR is linked to a **work item**
- [X] I have performed **self-review** of the code
- [ ] I have written **tests** for any new functionality added with this PR
- [X] I have updated the **documentation** if this PR changes or adds functionality
- [X] I have run **pre-commit** checks for code style

#1631 - Added the DEFCON 703 header to all possible files

Related work items: #1631
2023-07-17 19:51:29 +00:00
SunilSamra
9520cfea24 #901 - Replaced "ALLOW" with RulePermissionType.ALLOW
- Added Explicit ALLOW to test_configs in order for tests to work
- Added typing to access_control_list.py and acl_rule.py
2023-07-17 20:40:00 +01:00
Chris McCarthy
81295a4fc4 #1631 - Updated the copyright statement to comply with DEFCON 703 Edition 08/13 2023-07-17 19:57:34 +01:00
SunilSamra
a2f43b5abc #901 - merged dev into branch 2023-07-17 19:54:07 +01:00
SunilSamra
95b6211781 Merge remote-tracking branch 'origin/feature/901-change-functionality-acl-rules' into feature/901-change-functionality-acl-rules 2023-07-17 19:42:29 +01:00
SunilSamra
3aab6a3738 #901 - ran black pre-commit over observations.py to fix it 2023-07-17 19:42:05 +01:00
Sunil Samra
1721f2eb84 Apply suggestions from code review 2023-07-17 18:36:13 +00:00
Chris McCarthy
2d1a1e6db7 #1631 - Added the DEFCON 703 header to all possible files 2023-07-17 19:28:43 +01:00
Christopher McCarthy
35af1e9d1e Merged PR 121: #1629 - Added rllib test
## Summary
Quick test that uses RLLIB in a session

## Test process
The learning session completes then we check that the number of rows in both the average reward per episode and all transactions csv files.

## Checklist
- [X] This PR is linked to a **work item**
- [X] I have performed **self-review** of the code
- [X] I have written **tests** for any new functionality added with this PR
- [ ] I have updated the **documentation** if this PR changes or adds functionality
- [X] I have run **pre-commit** checks for code style

#1629 - Added rllib test

Related work items: #1629
2023-07-17 17:28:51 +00:00
Czar Echavez
e1ac628793 Merged PR 119: Loading SB3 Agents + Loading agent via PrimaiteSession
## Summary
- Added a feature which allows a user to load a previous SB3 session
- Added a feature which allows a user to load a previous PrimaiteSession
- Added a feature which allows a user to load a previous session via the CLI: `primaite session --load "<SESSION_PATH>"`
- RLlib is TODO in another ticket #1626
- Parallel tests via the [pytest-xdist](https://pypi.org/project/pytest-xdist/) dependency (MIT licensed)
- Moved hardcoded agent into hardcoded_abc.py
- renamed agent.py to agent_abc.py to clarify it is an abstract base class
- Added documentation to clarify how to use the feature via CLI or using the run function via main.py

## Test process
Created [test_session_loading.py](https://dev.azure.com/ma-dev-uk/PrimAITE/_git/PrimAITE/pullrequest/119?_a=files&path=/tests/test_session_loading.py) which loads a previously run session and then performs a learn and evaluation run on the loaded agent/Primate session.

The test copies the saved session into a temporary folder, which is then set as the test session path. Once the test is done, the temporary folder should then be deleted

## Checklist
- [X] This PR is linked to a **work item**
- [X] I have performed **self-review** of the code
- [X] I have written **tests** for any new functionality added with this PR
- [X] I have updated the **documentation** if this PR changes or adds functionality
- [X] I have run **pre-commit** checks for code style

Related work items: #1595
2023-07-17 15:26:42 +00:00
Marek Wolan
bfce2f9a7b Change typehints after mypy analysis 2023-07-17 16:22:07 +01:00
SunilSamra
257be9532f #901 - Changed num_eval_steps back to 1 in ppo_seeded_training_config.yaml 2023-07-17 15:54:15 +01:00
SunilSamra
57157db08c Merge remote-tracking branch 'origin/dev' into feature/901-change-functionality-acl-rules 2023-07-17 15:51:01 +01:00
Czar Echavez
39b30460cd Merge branch 'dev' into feature/1595-finalise-and-test-the-loading-of-trained-agents 2023-07-17 15:23:46 +01:00
Sunil Samra
dd21f9440f Apply suggestions from code review 2023-07-17 14:21:37 +00:00
Brian Kanyora
a432822bcb Merged PR 113: feature/1597-Getting-Started
## Summary
Add a Getting started page to the docs file.

## Checklist
- [x] This PR is linked to a **work item**
- [x] I have performed **self-review** of the code
- [na] I have written **tests** for any new functionality added with this PR
- [x] I have updated the **documentation** if this PR changes or adds functionality
- [x] I have run **pre-commit** checks for code style

Related work items: #1597
2023-07-17 14:19:16 +00:00
SunilSamra
ec938ce761 #901 - Changed num_eval_steps back to 1 in ppo_seeded_training_config.yaml 2023-07-17 14:06:33 +01:00
SunilSamra
007a0c4b98 Merge remote-tracking branch 'origin/feature/901-change-functionality-acl-rules' into feature/901-change-functionality-acl-rules 2023-07-17 14:01:32 +01:00
SunilSamra
2526427f2f #901 - Fixed bug in implicit rule - comparing it to string ALLOW or DENY in access_control_list.py 2023-07-17 13:58:06 +01:00
Sunil Samra
cc09fe9079 Removed apply_implicit_rule comment 2023-07-17 12:45:31 +00:00
SunilSamra
78d7f39342 #901 - Removed flatten from training configs
- Added flatten operation in observations.py when there are multiple obs components
- Updated config.rst docs
2023-07-17 13:44:16 +01:00