Skip to content
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

Instructions' Actions not Available after Reading #133

Merged
merged 2 commits into from
May 5, 2018

Conversation

kent-h
Copy link
Contributor

@kent-h kent-h commented Apr 30, 2018

Fixes a bug where actions for instructions were not properly read due to using pass-by-value instead of pass-by-pointer for the action list.

Also fixed a related bug where action lists' padding wasn't read, leading to an off-by-4 read error.

… using pass-by-value instead of pass-by-pointer for the action list. Also fixed a related bug where action lists' padding wasn't read, leading to an off-by-4 read error.
@ybubnov
Copy link
Member

ybubnov commented May 1, 2018

@kent-h, nice, could you, please also fix the unit test TestInstructionApplyActions, I believe it should specify a 8-byte padding as in the fix, like this:

tests := []encodingtest.MU{
		{&InstructionApplyActions{
			Actions: Actions{
				&ActionGroup{Group: GroupAll},
				&ActionCopyTTLOut{},
			},
		}, []byte{
			0x00, 0x04, // Instruction type.
			0x00, 0x18, // Instruction length.
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 8-byte padding.

			// Actions.
			0x00, 0x16, // Action group.
			0x00, 0x08, // Action lenght.
			0xff, 0xff, 0xff, 0xfc,
			0x00, 0xb, // Action type.
			0x00, 0x08, // Action lenght.
			0x00, 0x00, 0x00, 0x00, // 4-byte padding.
		}},
	}

Could you, also check that writing of this message puts padding of the appropriate length? Thanks!

@kent-h
Copy link
Contributor Author

kent-h commented May 1, 2018

@ybubnov
4 bytes of padding should already be correct. The header.Len-8 is for the 4 byte header + 4 bytes padding.

@ybubnov
Copy link
Member

ybubnov commented May 2, 2018

You're right. Ah, I see the reason of test failures, as long as test use the same slice of Actions, on decoding, it appends the same elements twice. The ReadFrom of Actions type should be fixed like this:

diff --git a/ofp/action.go b/ofp/action.go                                                                                                                                                                                                                     
index 191871e..899276e 100644                                                                                                                                                                                                                                  
--- a/ofp/action.go                                                                                                                                                                                                                                            
+++ b/ofp/action.go                                                                                                                                                                                                                                            
@@ -196,6 +196,7 @@ func (a *Actions) WriteTo(w io.Writer) (int64, error) {                                                                                                                                                                                    
 // the list of types that implement Action interface.                                                                                                                                                                                                         
 func (a *Actions) ReadFrom(r io.Reader) (int64, error) {                                                                                                                                                                                                      
        var actionType ActionType                                                                                                                                                                                                                              
+       *a = nil                                                                                                                                                                                                                                               
                                                                                                                                                                                                                                                               
        rm := func() (io.ReaderFrom, error) {                                                                                                                                                                                                                  
                if rm, ok := actionMap[actionType]; ok {

Could you, please, incorporate these changes in your PR?

@kent-h
Copy link
Contributor Author

kent-h commented May 4, 2018

Added requested changes.

@ybubnov ybubnov merged commit e388199 into netrack:master May 5, 2018
@kent-h kent-h deleted the bug/instruction-actions-unreadable branch May 8, 2018 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants