Repository navigation
Switch to use an in memory port interface when creating dummy ports #780
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
b08802a
Update ports.go
gavinz-ship-it fc8c24d
Update common.go
gavinz-ship-it c6558e3
Update genetlink.go
gavinz-ship-it 60924dd
Update tap.go
gavinz-ship-it ef2127b
Update forwarding_port.proto
gavinz-ship-it 4ca69c4
Update forwarding_port.pb.go
gavinz-ship-it e73e4b2
Update ports.go
gavinz-ship-it 88624d7
Update and rename genetlink.go to dummy.go
gavinz-ship-it 651ac98
Update BUILD
gavinz-ship-it 1c5e9bc
Update forwarding_port.proto
gavinz-ship-it ecd4720
Update forwarding_port.pb.go
gavinz-ship-it d8b9f26
Update ports.go
gavinz-ship-it 05036ad
Update BUILD
gavinz-ship-it 240fe27
Update dummy.go
gavinz-ship-it e3849d1
Update dummy.go
gavinz-ship-it File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| // Copyright 2023 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package ports | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/openconfig/lemming/dataplane/forwarding/fwdaction" | ||
| "github.com/openconfig/lemming/dataplane/forwarding/fwdport" | ||
| "github.com/openconfig/lemming/dataplane/forwarding/infra/fwdcontext" | ||
| "github.com/openconfig/lemming/dataplane/forwarding/infra/fwdobject" | ||
| "github.com/openconfig/lemming/dataplane/forwarding/infra/fwdpacket" | ||
| fwdpb "github.com/openconfig/lemming/proto/forwarding" | ||
| ) | ||
|
|
||
| func init() { | ||
| fwdport.Register(fwdpb.PortType_PORT_TYPE_DUMMY, dummyBuilder{}) | ||
| } | ||
|
|
||
| // dummyPort is a ports that drops all packets written to it. It is used to | ||
| // represent a port that is not present in the forwarding plane. | ||
| type dummyPort struct { | ||
| fwdobject.Base | ||
| desc *fwdpb.PortDesc | ||
| devName string | ||
| adminState fwdpb.PortState | ||
| ctx *fwdcontext.Context // Forwarding context containing the port | ||
| } | ||
|
|
||
| // Desc returns the port description proto. | ||
| func (p *dummyPort) Desc() *fwdpb.PortDesc { | ||
| return p.desc | ||
| } | ||
|
|
||
| func (p *dummyPort) String() string { | ||
| desc := fmt.Sprintf("Type=%v;DeviceName=%v;", fwdpb.PortType_PORT_TYPE_DUMMY, p.devName) | ||
| if state, err := p.State(nil); err == nil { | ||
| desc += fmt.Sprintf("<State=%v>;", state) | ||
| } | ||
| return desc | ||
| } | ||
|
|
||
| func (p *dummyPort) Type() fwdpb.PortType { | ||
| return fwdpb.PortType_PORT_TYPE_DUMMY | ||
| } | ||
|
|
||
| func (p *dummyPort) Cleanup() { | ||
| } | ||
|
|
||
| // Update updates the actions of the port. | ||
| func (p *dummyPort) Update(upd *fwdpb.PortUpdateDesc) error { | ||
| defer func() { | ||
| p.Cleanup() | ||
| }() | ||
| return nil | ||
| } | ||
|
|
||
| func (p *dummyPort) Write(fwdpacket.Packet) (fwdaction.State, error) { | ||
| return fwdaction.CONSUME, nil | ||
| } | ||
|
|
||
| // Actions returns the port actions of the specified type | ||
| func (p *dummyPort) Actions(dir fwdpb.PortAction) fwdaction.Actions { | ||
| return nil | ||
|
gavinz-ship-it marked this conversation as resolved.
Resolved
|
||
| } | ||
|
|
||
| // State returns the state of the port. | ||
| func (p *dummyPort) State(pi *fwdpb.PortInfo) (*fwdpb.PortStateReply, error) { | ||
| if pi != nil { | ||
| p.adminState = pi.AdminStatus | ||
| } | ||
| return &fwdpb.PortStateReply{ | ||
| Status: &fwdpb.PortInfo{ | ||
| OperStatus: fwdpb.PortState_PORT_STATE_DISABLED_DOWN, | ||
| AdminStatus: p.adminState, | ||
| }, | ||
| }, nil | ||
| } | ||
|
|
||
| type dummyBuilder struct{} | ||
|
|
||
| // Build creates a new port. | ||
| func (dummyBuilder) Build(portDesc *fwdpb.PortDesc, ctx *fwdcontext.Context) (fwdport.Port, error) { | ||
| kp, ok := portDesc.Port.(*fwdpb.PortDesc_Dummy) | ||
| if !ok { | ||
| return nil, fmt.Errorf("invalid port type in proto") | ||
| } | ||
| var adminState fwdpb.PortState | ||
| if kp.Dummy.GetAdminState() { | ||
| adminState = fwdpb.PortState_PORT_STATE_ENABLED_UP | ||
| } else { | ||
| adminState = fwdpb.PortState_PORT_STATE_DISABLED_DOWN | ||
| } | ||
| p := dummyPort{ | ||
| ctx: ctx, | ||
| desc: portDesc, | ||
| devName: kp.Dummy.GetDeviceName(), | ||
| adminState: adminState, | ||
| } | ||
| list := append(fwdport.CounterList, fwdaction.CounterList...) | ||
| if err := p.InitCounters("", list...); err != nil { | ||
| return nil, err | ||
| } | ||
| return &p, nil | ||
| } | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.