Skip to content

Commit

Permalink
Starting implementation of table entries (#26)
Browse files Browse the repository at this point in the history
* Starting implementation of table entries

* Starting on tests for the stores; broken

* Fixed go.mod

* Adding table entries test scenarios

* Adding stores test

* Implemented purge - tables only for now

* Added skeletal implementation of the controller package
  • Loading branch information
tomikazi authored Jan 26, 2023
1 parent 5ad14e2 commit ad69a54
Show file tree
Hide file tree
Showing 12 changed files with 2,139 additions and 97 deletions.
2 changes: 1 addition & 1 deletion .reuse/dep5
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/

Files: VERSION .gitreview go.mod go.sum *.json *.png *.ico *.jpg \\
Files: VERSION .gitreview go.mod go.sum *.json *.png *.ico *.jpg *.txt \\
*/*.pb.go
Copyright: 2021 Open Networking Foundation
License: Apache-2.0
16 changes: 13 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@ require (
github.com/atomix/go-sdk v0.10.0
github.com/onosproject/onos-api/go v0.10.21
github.com/onosproject/onos-lib-go v0.10.6
github.com/p4lang/p4runtime v1.3.0
github.com/onosproject/onos-net-lib v1.1.5
github.com/p4lang/p4runtime v1.4.0-rc.5
github.com/stretchr/testify v1.7.1
)

require (
github.com/Shopify/sarama v1.31.1 // indirect
github.com/atomix/runtime/api v0.7.0 // indirect
github.com/atomix/runtime/primitives v0.7.2 // indirect
github.com/atomix/runtime/proxy v0.12.0 // indirect
github.com/atomix/runtime/sdk v0.7.4 // indirect
github.com/bits-and-blooms/bitset v1.2.0 // indirect
github.com/bits-and-blooms/bloom/v3 v3.2.0 // indirect
github.com/cenkalti/backoff v2.2.1+incompatible // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/eapache/go-resiliency v1.2.0 // indirect
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21 // indirect
Expand All @@ -21,6 +29,7 @@ require (
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/uuid v1.1.2 // indirect
github.com/hashicorp/go-uuid v1.0.2 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/jcmturner/aescts/v2 v2.0.0 // indirect
Expand All @@ -35,6 +44,7 @@ require (
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/pelletier/go-toml/v2 v2.0.0-beta.8 // indirect
github.com/pierrec/lz4 v2.6.1+incompatible // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/spf13/afero v1.8.2 // indirect
github.com/spf13/cast v1.4.1 // indirect
Expand All @@ -49,8 +59,8 @@ require (
golang.org/x/net v0.0.0-20220412020605-290c469a71a5 // indirect
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/genproto v0.0.0-20220407144326-9054f6ed7bac // indirect
google.golang.org/grpc v1.46.0 // indirect
google.golang.org/genproto v0.0.0-20220608133413-ed9918b62aac // indirect
google.golang.org/grpc v1.47.0 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/ini.v1 v1.66.4 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
35 changes: 24 additions & 11 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,22 @@ github.com/Shopify/toxiproxy/v2 v2.3.0/go.mod h1:KvQTtB6RjCJY4zqNJn7C7JDFgsG5uoH
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/atomix/go-sdk v0.10.0 h1:dJ9y/PwkXrMdLCTrGOa3NdM68XymzrgSGT8tJPuOZDU=
github.com/atomix/go-sdk v0.10.0/go.mod h1:WhQi7ckmY6EYwPcsCGL/J4+DCHsvWD9nUZxLKn0nW8c=
github.com/atomix/runtime/api v0.7.0 h1:yCDoORQqk2rzWr9Eg/NrLFgOu4C/lR3D306IVWzr6ZQ=
github.com/atomix/runtime/api v0.7.0/go.mod h1:tjbd3w4yij89ZHCYdQUbmvZMC0HoHQQ/3/gVzQuOCH0=
github.com/atomix/runtime/primitives v0.7.2 h1:1iM389kF8WBJK+JyrwOUCSIP5LPCLLnpwcN0Myt0mxE=
github.com/atomix/runtime/primitives v0.7.2/go.mod h1:X3OUeueowH0Xu9A8L3SW62Fbhy+D08J3tRDCHx+5WC4=
github.com/atomix/runtime/proxy v0.12.0 h1:0IFBy8l50xEVOJezeJmGHVmgqhaELDawJKnKaFCflDk=
github.com/atomix/runtime/proxy v0.12.0/go.mod h1:iaETiosmxB8LUSDXOcZ2fSlTCIdd6rKP7JsHqZ57hnw=
github.com/atomix/runtime/sdk v0.7.4 h1:9jAAY85/pZMwejg3zhGr0/S2svebriEXlsu2QZ4+bQU=
github.com/atomix/runtime/sdk v0.7.4/go.mod h1:CIxhWG1UkcWL82+XJ1wwynz1T5k4nYTZdwNlWp8IMd8=
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/bits-and-blooms/bitset v1.2.0 h1:Kn4yilvwNtMACtf1eYDlG8H77R07mZSPbMjLyS07ChA=
github.com/bits-and-blooms/bitset v1.2.0/go.mod h1:gIdJ4wp64HaoK2YrL1Q5/N7Y16edYb8uY+O0FJTyyDA=
github.com/bits-and-blooms/bloom/v3 v3.2.0 h1:N+g3GTQ0TVbghahYyzwkQbMZR+IwIwFFC8dpIChtN0U=
github.com/bits-and-blooms/bloom/v3 v3.2.0/go.mod h1:MC8muvBzzPOFsrcdND/A7kU7kMhkqb9KI70JlZCP+C8=
github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4=
github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
Expand All @@ -59,7 +71,6 @@ github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGX
github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4/go.mod h1:6pvJx4me5XPnfI9Z40ddWsdw2W/uZgQLFXToKeRcDiI=
github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
Expand All @@ -79,7 +90,6 @@ github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.m
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5ynNVH9qI8YYLbd1fK2po=
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0=
github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1/go.mod h1:KJwIaB5Mv44NWtYuAOFCVOjcI94vtpEz2JU/D2v6IjE=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw=
Expand Down Expand Up @@ -154,6 +164,7 @@ github.com/google/pprof v0.0.0-20201023163331-3e6fc7fc9c4c/go.mod h1:kpwsk12EmLe
github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/pprof v0.0.0-20201218002935-b9804c9f04c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
Expand Down Expand Up @@ -206,8 +217,10 @@ github.com/onosproject/onos-api/go v0.10.21 h1:rMxmH5UxOodgplTQkCO9+Iq3ZkgexBV6/
github.com/onosproject/onos-api/go v0.10.21/go.mod h1:R882+8UcxQBLpCopnnbBnemXtJ77UXnL2I1y5yHbq10=
github.com/onosproject/onos-lib-go v0.10.6 h1:/WCaZddI3SywC0StjOficcnaiQ49eOs+JIRbB/H4A3U=
github.com/onosproject/onos-lib-go v0.10.6/go.mod h1:BW7ofxESngKlsUw6YmO/hbUrbmL3sNxdXkzZkDev/tE=
github.com/p4lang/p4runtime v1.3.0 h1:3fUhHj0JtsGcL2Bh0uxpACdBJBDqpZyLgj93tqKzoJY=
github.com/p4lang/p4runtime v1.3.0/go.mod h1:voPsRsgz/TDEhcaFvBxfMbI++hSKR/QGJusJveEs9Jg=
github.com/onosproject/onos-net-lib v1.1.5 h1:RbG4gshxnWfhysflYnlDvmUXekjRLQgpZcfER3rP4Q0=
github.com/onosproject/onos-net-lib v1.1.5/go.mod h1:Fpe3V3NtcSQGdLO1IeO50JHEcGba55zyuskjPBk8qnM=
github.com/p4lang/p4runtime v1.4.0-rc.5 h1:zztZGEkRM09Hf25SIX0p0ML07dmRCgsy0oC8uafmjtg=
github.com/p4lang/p4runtime v1.4.0-rc.5/go.mod h1:m9laObIMXM9N1ElGXijc66/MSM5eheZJLRLxg/TG+fU=
github.com/pelletier/go-toml v1.9.4 h1:tjENF6MfZAg8e4ZmZTeWaWiT2vXtsoO6+iuOjFhECwM=
github.com/pelletier/go-toml v1.9.4/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/pelletier/go-toml/v2 v2.0.0-beta.8 h1:dy81yyLYJDwMTifq24Oi/IslOslRrDSb3jwDggjz3Z0=
Expand All @@ -230,6 +243,8 @@ github.com/rogpeppe/go-internal v1.8.1 h1:geMPLpDpQOgVyCg5z5GoRwLHepNdb71NXb67XF
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spf13/afero v1.8.2 h1:xehSyVa0YnHWsJ49JFljMpg1HX19V6NDZ1fkm1Xznbo=
github.com/spf13/afero v1.8.2/go.mod h1:CtAatgMJh6bJEIs48Ay/FOnkljP3WeGUG0MC1RfAqwo=
github.com/spf13/cast v1.4.1 h1:s0hze+J0196ZfEMTs80N7UlFt0BDuQ7Q+JDnHiMWKdA=
Expand Down Expand Up @@ -536,7 +551,6 @@ google.golang.org/genproto v0.0.0-20200228133532-8c2c7df3a383/go.mod h1:55QSHmfG
google.golang.org/genproto v0.0.0-20200305110556-506484158171/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
google.golang.org/genproto v0.0.0-20200312145019-da6875a35672/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
google.golang.org/genproto v0.0.0-20200413115906-b5235f65be36/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
google.golang.org/genproto v0.0.0-20200430143042-b979b6f78d84/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
google.golang.org/genproto v0.0.0-20200511104702-f5ebc3bea380/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
Expand All @@ -553,8 +567,8 @@ google.golang.org/genproto v0.0.0-20201210142538-e3217bee35cc/go.mod h1:FWY/as6D
google.golang.org/genproto v0.0.0-20201214200347-8c77b98c765d/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
google.golang.org/genproto v0.0.0-20210108203827-ffc7fda8c3d7/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
google.golang.org/genproto v0.0.0-20210226172003-ab064af71705/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
google.golang.org/genproto v0.0.0-20220407144326-9054f6ed7bac h1:qSNTkEN+L2mvWcLgJOR+8bdHX9rN/IdU3A1Ghpfb1Rg=
google.golang.org/genproto v0.0.0-20220407144326-9054f6ed7bac/go.mod h1:8w6bsBMX6yCPbAVTeqQHvzxW0EIFigd5lZyahWgyfDo=
google.golang.org/genproto v0.0.0-20220608133413-ed9918b62aac h1:ByeiW1F67iV9o8ipGskA+HWzSkMbRJuKLlwCdPxzn7A=
google.golang.org/genproto v0.0.0-20220608133413-ed9918b62aac/go.mod h1:KEWEmljWE5zPzLBa/oHl6DaEt9LmfH6WtH1OHIvleBA=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
Expand All @@ -574,9 +588,8 @@ google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv
google.golang.org/grpc v1.34.0/go.mod h1:WotjhfgOW/POjDeRt8vscBtXq+2VjORFy659qA51WJ8=
google.golang.org/grpc v1.35.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
google.golang.org/grpc v1.45.0/go.mod h1:lN7owxKUQEqMfSyQikvvk5tf/6zMPsrK+ONuO11+0rQ=
google.golang.org/grpc v1.46.0 h1:oCjezcn6g6A75TGoKYBPgKmVBLexhYLM6MebdrPApP8=
google.golang.org/grpc v1.46.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk=
google.golang.org/grpc v1.47.0 h1:9n77onPX5F3qfFCqjy9dhn8PbNQsIKeVU04J9G7umt8=
google.golang.org/grpc v1.47.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
Expand All @@ -594,7 +607,7 @@ google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscL
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/ini.v1 v1.66.4 h1:SsAcf+mM7mRZo2nJNGt8mZCjG8ZRaNGMURJw7BsIST4=
gopkg.in/ini.v1 v1.66.4/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
Expand Down
15 changes: 3 additions & 12 deletions pkg/api/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package api

import (
"context"
"github.com/onosproject/onos-api/go/onos/stratum"
"github.com/onosproject/onos-api/go/onos/topo"
p4info "github.com/p4lang/p4runtime/go/p4/config/v1"
p4api "github.com/p4lang/p4runtime/go/p4/v1"
Expand Down Expand Up @@ -41,11 +40,11 @@ type PacketHandler interface {
Handle(packetIn *p4api.PacketIn) error
}

// Devices is an abstraction of an entity capable ot tracking device control contexts
// Devices is an abstraction of an entity capable of tracking device control contexts
// of multiple devices on behalf of the control application.
type Devices interface {
// Add requests creation of a new device flow control context using its P4Runtime connection endpoint
Add(id topo.ID, p4rtEndpoint string) DeviceControl
Add(ctx context.Context, id topo.ID, p4rtEndpoint string, translator PipelineTranslator) (DeviceControl, error)

// Remove requests removal of device control context
Remove(id topo.ID)
Expand All @@ -54,13 +53,5 @@ type Devices interface {
Get(id topo.ID) DeviceControl

// GetAll returns all device flow control entities presently registered with the manager
GetAll() []*DeviceControl
}

// TODO: Move to the controller package once it exists, obviously. :)

// NewController creates a new controller for device control contexts using the supplied role descriptor
// and pipeline translator
func NewController(role stratum.P4RoleConfig, translator PipelineTranslator) Devices {
return nil
GetAll() []DeviceControl
}
71 changes: 71 additions & 0 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// SPDX-FileCopyrightText: 2023-present Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0

// Package controller implements the core reconciliation controller tying together API, stores, translators and SB
package controller

import (
"context"
"github.com/onosproject/onos-api/go/onos/topo"
"github.com/onosproject/onos-control/pkg/api"
"github.com/onosproject/onos-control/pkg/store"
p4info "github.com/p4lang/p4runtime/go/p4/config/v1"
p4api "github.com/p4lang/p4runtime/go/p4/v1"
)

type deviceController struct {
api.DeviceControl
id topo.ID
endpoint string
translator api.PipelineTranslator
version string
}

func newDeviceController(id topo.ID, endpoint string, store store.EntityStore, translator api.PipelineTranslator) api.DeviceControl {
return &deviceController{
id: id,
endpoint: endpoint,
translator: translator,
}
}

// Read receives a query and returns back all requested control entries on the given channel
func (d *deviceController) Read(ctx context.Context, entities *[]p4api.Entity, ch chan<- []*p4api.Entity) error {
// TODO: Implement me
return nil
}

// Write applies a set of updates to the device
func (d *deviceController) Write(ctx context.Context, request *[]p4api.Update) error {
// TODO: Implement me
// Write to the store; notify reconciler to translate and contact southbound
return nil
}

// EmitPacket requests emission of the specified packet onto the data-plane
func (d *deviceController) EmitPacket(ctx context.Context, packetOut *p4api.PacketOut) error {
// TODO: Implement me
// Go directly to the southbound
return nil
}

// HandlePackets starts handling the packet-in message using the supplied channel and packet handler
func (d *deviceController) HandlePackets(ch chan<- *p4api.PacketIn, handler *api.PacketHandler) {
// Pass the channel and handler directly to the southbound
}

// Pipeline returns the P4 information describing the high-level device pipeline
func (d *deviceController) Pipeline() *p4info.P4Info {
return d.translator.FromPipeline()
}

// Version returns the P4Runtime version of the target
func (d *deviceController) Version() string {
if d.version == "" {
// TODO: Implement me
// Issue capabilities request using southbound and capture version here
d.version = "unknown"
}
return d.version
}
74 changes: 74 additions & 0 deletions pkg/controller/controllers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// SPDX-FileCopyrightText: 2023-present Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0

// Package controller implements the core reconciliation controller tying together API, stores, translators and SB
package controller

import (
"context"
"github.com/onosproject/onos-api/go/onos/stratum"
"github.com/onosproject/onos-api/go/onos/topo"
"github.com/onosproject/onos-control/pkg/api"
"github.com/onosproject/onos-control/pkg/store"
"sync"
)

type devicesController struct {
api.Devices
role stratum.P4RoleConfig
stores store.Stores

mu sync.RWMutex
devices map[topo.ID]*deviceController
}

// NewController creates a new controller for device control contexts using the supplied role descriptor
// and pipeline translator
func NewController(role stratum.P4RoleConfig, stores store.Stores) api.Devices {
return &devicesController{
role: role,
stores: stores,
}
}

// Add requests creation of a new device flow control context using its P4Runtime connection endpoint
func (c *devicesController) Add(ctx context.Context, id topo.ID, p4rtEndpoint string, translator api.PipelineTranslator) (api.DeviceControl, error) {
c.mu.Lock()
defer c.mu.Unlock()

if d, ok := c.devices[id]; ok {
return d, nil
}

store, err := c.stores.Get(ctx, id, translator.FromPipeline())
if err != nil {
return nil, err
}
return newDeviceController(id, p4rtEndpoint, store, translator), nil
}

// Remove requests removal of device control context
func (c *devicesController) Remove(id topo.ID) {
c.mu.Lock()
defer c.mu.Unlock()
delete(c.devices, id)
}

// Get the device flow control entity by its ID
func (c *devicesController) Get(id topo.ID) api.DeviceControl {
c.mu.RLock()
defer c.mu.RUnlock()
return c.devices[id]
}

// GetAll returns all device flow control entities presently registered with the manager
func (c *devicesController) GetAll() []api.DeviceControl {
c.mu.RLock()
defer c.mu.RUnlock()
devices := make([]api.DeviceControl, 0, len(c.devices))
for _, d := range c.devices {
devices = append(devices, d)
}
return devices
}
Loading

0 comments on commit ad69a54

Please sign in to comment.