forked from contiv/libOpenflow
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allocate 6 bytes to copy MAC addresses when unmarshalling ethernet ma…
…tch fields (#62) Signed-off-by: Ivan Tsvetkov <[email protected]>
- Loading branch information
1 parent
84e10ca
commit 6ea2df2
Showing
3 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 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,55 @@ | ||
package openflow15_test | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"net" | ||
"testing" | ||
|
||
"antrea.io/libOpenflow/openflow15" | ||
) | ||
|
||
func TestMatchEthAddresses(t *testing.T) { | ||
ethSrcAddress, _ := net.ParseMAC("aa:aa:aa:aa:aa:aa") | ||
ethDstAddress, _ := net.ParseMAC("ff:ff:ff:ff:ff:ff") | ||
|
||
ofMatch := openflow15.NewMatch() | ||
{ | ||
macSrcField := openflow15.NewEthSrcField(ethSrcAddress, nil) | ||
ofMatch.AddField(*macSrcField) | ||
|
||
macDstField := openflow15.NewEthDstField(ethDstAddress, nil) | ||
ofMatch.AddField(*macDstField) | ||
} | ||
|
||
if err := checkMatchSerializationConsistency(ofMatch); err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
func checkMatchSerializationConsistency(ofMatch *openflow15.Match) error { | ||
// Serialize the original match | ||
ofMatchRaw, err := ofMatch.MarshalBinary() | ||
if err != nil { | ||
return fmt.Errorf("failed to marshal match: %w", err) | ||
} | ||
|
||
// Deserialize into a new match object | ||
ofMatchRecovered := openflow15.NewMatch() | ||
if err := ofMatchRecovered.UnmarshalBinary(ofMatchRaw); err != nil { | ||
return fmt.Errorf("failed to unmarshal match: %w", err) | ||
} | ||
|
||
// Serialize the recovered match for comparison | ||
ofMatchRecoveredRaw, err := ofMatchRecovered.MarshalBinary() | ||
if err != nil { | ||
return fmt.Errorf("failed to marshal recovered match: %w", err) | ||
} | ||
|
||
// Check for serialization consistency | ||
if !bytes.Equal(ofMatchRaw, ofMatchRecoveredRaw) { | ||
return fmt.Errorf("initial and recovered match structures do not match") | ||
} | ||
|
||
return nil | ||
} |