-
Notifications
You must be signed in to change notification settings - Fork 19
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
support nsh encap and decap #25
Conversation
@zhenglinan thanks for the PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two general comments except for the code change:
- Please update file VERSION whenever you propose a new change, change the min part (the version string uses this format: max.min.patch) if it is a new feature, e.g. this change is a new feature support. And change the patch part if it is bug fix.
- Please format your code before updating your patch on github.
openflow15/nx_action.go
Outdated
var b []byte | ||
n := 0 | ||
|
||
b, err = a.NXActionHeader.MarshalBinary() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add error check here, becore consuming b
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added error check here in new commit
openflow15/nx_action.go
Outdated
} | ||
|
||
func (a *NXActionDecapsulate) Len() (n uint16) { | ||
return a.Length |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is better to return a constant or calcuate the length according to the properties instead of consuming some property in function Len()
, to avoid unnecessary issue if the property is not set in advance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done , I have replaced it to constant 16
openflow15/nx_action.go
Outdated
binary.BigEndian.PutUint32(data[n:], a.HeaderType) | ||
n += 4 | ||
return | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function UnmarshalBinary
in type NXActionDecapsulate
is missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are right ! Thanks
openflow15/nx_action.go
Outdated
type NXActionEncapsulate struct { | ||
*NXActionHeader | ||
HeaderSize uint16 | ||
HeaderType uint32 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you use an enum to list the valid values of HeaderType in NXActionEncapsulate
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
openflow15/nx_action.go
Outdated
n := 0 | ||
|
||
b, err = a.NXActionHeader.MarshalBinary() | ||
copy(data[n:], b) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check err before consuming b
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
openflow15/nx_action.go
Outdated
a.HeaderType = binary.BigEndian.Uint32(data[n:]) | ||
n += 4 | ||
var prop PropTLV | ||
for n < int(a.Length) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a.Len() to be consistent with line 2012?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
I have another question: are the new actions only for nsh packets, or also for ethernet? If they are only suitable for nsh packets, it is better to change names more concrete, otherwise, it is confusing when calling "encap(ethernet)" |
openflow15/nx_action.go
Outdated
a.NXActionHeader = new(NXActionHeader) | ||
err := a.NXActionHeader.UnmarshalBinary(data[n:]) | ||
if err != nil { | ||
return errors.New("failed to unmarshal header") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return errors.New("failed to unmarshal header") | |
return fmt.Errorf("failed to unmarshal NXAction header: %v", err) |
openflow15/nx_action.go
Outdated
*NXActionHeader | ||
HeaderSize uint16 | ||
HeaderType EncapType | ||
Property []PropTLV |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Property []PropTLV | |
Property []PropTLV |
Property []PropTLV | |
Properties []PropTLV |
openflow15/nx_action.go
Outdated
func NewNXActionEncapsulate(headerSize uint16, headerType EncapType, property []PropTLV) *NXActionEncapsulate { | ||
a := new(NXActionEncapsulate) | ||
a.NXActionHeader = NewNxActionHeader(NXAST_RAW_ENCAP) | ||
a.Length = 16 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If property is not empty, a.Length should be a value larger than 16?
openflow15/nx_action.go
Outdated
a := new(NXActionDecapsulate) | ||
a.NXActionHeader = NewNxActionHeader(NXAST_RAW_DECAP) | ||
a.Length = 16 | ||
a.pad = make([]byte, 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to explicitly make a byte slice for pad
, since its value is never accessible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refer to NewNXActionCTNAT
openflow15/nx_action.go
Outdated
n += int(a.NXActionHeader.Len()) | ||
|
||
if len(data) < int(a.Len()) { | ||
return errors.New("the []byte is too short to unmarshal a full NXActionConjunction message") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return errors.New("the []byte is too short to unmarshal a full NXActionConjunction message") | |
return errors.New("the []byte is too short to unmarshal a full NXActionDecapsulate message") |
openflow15/nx_action.go
Outdated
} | ||
n += int(a.NXActionHeader.Len()) | ||
if len(data) < int(a.Len()) { | ||
return errors.New("the []byte is too short to unmarshal a full NXActionConjunction message") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return errors.New("the []byte is too short to unmarshal a full NXActionConjunction message") | |
return errors.New("the []byte is too short to unmarshal a full NXActionEncapsulate message") |
Please pay attention on the DCO and test/golint errors. Update: Please add unit test on your new code, e.g., you can test the message Marshal and Unmarshal in the case, so that we could avoid runtime issues. |
support nsh encap and decap
@tnqn
Signed-off-by: zhenglinan [email protected]