本文整理匯總了Golang中github.com/hkwi/gopenflow/ofp4.MakeErrorMsg函數的典型用法代碼示例。如果您正苦於以下問題:Golang MakeErrorMsg函數的具體用法?Golang MakeErrorMsg怎麽用?Golang MakeErrorMsg使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了MakeErrorMsg函數的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: UnmarshalBinary
func (self match) UnmarshalBinary(msg []byte) error {
exps := make(map[uint32]bool)
for _, oxm := range ofp4.Oxm(msg).Iter() {
hdr := oxm.Header()
switch hdr.Class() {
case ofp4.OFPXMC_OPENFLOW_BASIC:
self[OxmKeyBasic(hdr.Type())] = OxmValueMask{
Value: oxm.Value(),
Mask: oxm.Mask(),
}
case ofp4.OFPXMC_EXPERIMENTER:
exps[ofp4.OxmExperimenterHeader(oxm).Experimenter()] = true
default:
return ofp4.MakeErrorMsg(
ofp4.OFPET_BAD_MATCH,
ofp4.OFPBMC_BAD_TYPE,
)
}
}
for exp, _ := range exps {
if handle, ok := oxmHandlers[exp]; ok {
for k, v := range handle.Parse(msg) {
oxmKeys[k] = exp
self[k] = v
}
} else {
return ofp4.MakeErrorMsg(
ofp4.OFPET_BAD_MATCH,
ofp4.OFPBRC_BAD_LEN,
)
}
}
return nil
}
示例2: importInstructions
func (entry *flowEntry) importInstructions(instructions ofp4.Instruction) error {
for _, inst := range instructions.Iter() {
switch inst.Type() {
default:
return ofp4.MakeErrorMsg(
ofp4.OFPET_BAD_INSTRUCTION,
ofp4.OFPBIC_UNKNOWN_INST,
)
case ofp4.OFPIT_GOTO_TABLE:
entry.instGoto = ofp4.InstructionGotoTable(inst).TableId()
case ofp4.OFPIT_WRITE_METADATA:
i := ofp4.InstructionWriteMetadata(inst)
if i.Metadata()&^i.MetadataMask() != 0 {
return errors.New("invalid value/mask pair")
}
entry.instMetadata = &metadataInstruction{
i.Metadata(),
i.MetadataMask(),
}
case ofp4.OFPIT_WRITE_ACTIONS, ofp4.OFPIT_APPLY_ACTIONS, ofp4.OFPIT_CLEAR_ACTIONS:
i := ofp4.InstructionActions(inst)
switch inst.Type() {
case ofp4.OFPIT_WRITE_ACTIONS:
var aset actionSet
if err := aset.UnmarshalBinary(i.Actions()); err != nil {
return err
}
entry.instWrite = aset
case ofp4.OFPIT_APPLY_ACTIONS:
var alist actionList
if err := alist.UnmarshalBinary(i.Actions()); err != nil {
return err
}
entry.instApply = alist
case ofp4.OFPIT_CLEAR_ACTIONS:
entry.instClear = true
}
case ofp4.OFPIT_METER:
entry.instMeter = ofp4.InstructionMeter(inst).MeterId()
case ofp4.OFPIT_EXPERIMENTER:
experimenter := ofp4.InstructionExperimenter(inst).Experimenter()
data := inst[8:]
if handler, ok := instructionHandlers[experimenter]; ok {
pos := handler.Order(data)
entry.instExp[pos] = append(entry.instExp[pos], instExperimenter{
Experimenter: experimenter,
Data: data,
Handler: handler,
})
} else {
return ofp4.MakeErrorMsg(ofp4.OFPET_BAD_INSTRUCTION, ofp4.OFPBIC_UNSUP_INST)
}
}
}
return nil
}
示例3: Map
func (self *ofmMpPortStats) Map() Reducable {
mpreq := ofp4.MultipartRequest(self.req)
proc := func(portNo uint32, port gopenflow.Port) {
var pstats gopenflow.PortStats
var ethinfo gopenflow.PortStatsEthernet
if p, err := port.Stats(); err != nil {
log.Print(err)
} else {
pstats = p
if p.Ethernet != nil {
ethinfo = *p.Ethernet
}
}
duration := self.pipe.portAlive[portNo].Total()
chunk := ofp4.MakePortStats(
portNo,
pstats.RxPackets,
pstats.TxPackets,
pstats.RxBytes,
pstats.TxBytes,
pstats.RxDropped,
pstats.TxDropped,
pstats.RxErrors,
pstats.TxErrors,
ethinfo.RxFrameErr,
ethinfo.RxOverErr,
ethinfo.RxCrcErr,
ethinfo.Collisions,
uint32(duration.Seconds()),
uint32(duration.Nanoseconds()%int64(time.Second)),
)
self.chunks = append(self.chunks, chunk)
}
portNo := ofp4.PortStatsRequest(mpreq.Body()).PortNo()
switch portNo {
default:
if portNo > 0 && portNo <= ofp4.OFPP_MAX {
if port := self.pipe.getPort(portNo); port != nil {
proc(portNo, port)
} else {
self.putError(ofp4.MakeErrorMsg(ofp4.OFPET_PORT_MOD_FAILED, ofp4.OFPPMFC_BAD_PORT))
}
} else {
self.putError(ofp4.MakeErrorMsg(ofp4.OFPET_PORT_MOD_FAILED, ofp4.OFPPMFC_BAD_PORT))
}
case ofp4.OFPP_ALL, ofp4.OFPP_ANY:
for portNo, port := range self.pipe.getAllPorts() {
proc(portNo, port)
}
}
return self
}
示例4: Process
func (self actionSetField) Process(data *Frame) (*outputToPort, *outputToGroup, error) {
ms := match{}
if err := ms.UnmarshalBinary(self.Field); err != nil {
return nil, nil, err
} else {
for oxmKey, oxmPayload := range ms {
var handler OxmHandler
switch oxmKey.(type) {
case OxmKeyBasic:
handler = oxmBasicHandler
default:
handler = oxmHandlers[oxmKeys[oxmKey]]
}
if handler == nil {
return nil, nil, ofp4.MakeErrorMsg(
ofp4.OFPBAC_BAD_EXPERIMENTER,
ofp4.OFPBAC_BAD_TYPE,
)
} else if err := handler.SetField(data, oxmKey, oxmPayload); err != nil {
return nil, nil, err
}
}
}
return nil, nil, nil
}
示例5: deleteGroupInside
func (pipe *Pipeline) deleteGroupInside(groupId uint32) error {
if _, exists := pipe.groups[groupId]; exists {
for _, chainId := range pipe.groupChains(groupId, nil) {
if _, exists := pipe.groups[chainId]; exists {
delete(pipe.groups, chainId)
}
pipe.filterFlowsInside(flowFilter{
opUnregister: true,
outPort: ofp4.OFPP_ANY,
outGroup: chainId,
})
}
} else {
return ofp4.MakeErrorMsg(ofp4.OFPET_GROUP_MOD_FAILED, ofp4.OFPGMFC_GROUP_EXISTS)
}
return nil
}
示例6: Conflict
/*
You should pass expanded match.
*/
func (self match) Conflict(target match) (bool, error) {
uni := make(map[OxmKey]bool)
for k, _ := range self {
uni[k] = true
}
for k, _ := range target {
uni[k] = true
}
for oxmKey, _ := range uni {
if sPayload, ok := self[oxmKey]; !ok {
continue
} else if tPayload, ok := target[oxmKey]; !ok {
continue
} else {
var handle OxmHandler
switch k := oxmKey.(type) {
case OxmKeyBasic:
if oxm.Header(k).Class() == ofp4.OFPXMC_OPENFLOW_BASIC {
handle = oxmBasicHandler
}
default:
handle = oxmHandlers[oxmKeys[oxmKey]]
}
if handle == nil {
return false, ofp4.MakeErrorMsg(
ofp4.OFPET_BAD_MATCH,
ofp4.OFPBMC_BAD_TYPE,
)
}
if result, err := handle.Conflict(oxmKey, sPayload, tPayload); err != nil {
return false, err
} else if result {
return true, nil
}
}
}
return false, nil
}
示例7: Expand
func (self match) Expand() (match, error) {
var exps []uint32
ret := make(map[OxmKey]OxmPayload)
for k, v := range self {
oxm := ofp4.Oxm(k.Bytes(v))
if oxm.Header().Class() == ofp4.OFPXMC_EXPERIMENTER {
exps = append(exps, ofp4.OxmExperimenterHeader(oxm).Experimenter())
}
ret[k] = v
}
oxmBasicHandler.Expand(ret)
for _, exp := range exps {
if handle, ok := oxmHandlers[exp]; !ok {
return nil, ofp4.MakeErrorMsg(
ofp4.OFPET_BAD_MATCH,
ofp4.OFPBMC_BAD_TYPE,
)
} else if err := handle.Expand(ret); err != nil {
return nil, err
}
}
return ret, nil
}
示例8: addFlowEntry
func (pipe Pipeline) addFlowEntry(req ofp4.FlowMod) error {
tableId := req.TableId()
if tableId > ofp4.OFPTT_MAX {
return ofp4.MakeErrorMsg(
ofp4.OFPET_FLOW_MOD_FAILED,
ofp4.OFPFMFC_BAD_TABLE_ID,
)
}
pipe.lock.Lock()
defer pipe.lock.Unlock()
var table *flowTable
if trial, ok := pipe.flows[tableId]; ok {
table = trial
} else {
table = &flowTable{
lock: &sync.RWMutex{},
feature: makeFlowTableFeature(),
}
pipe.flows[tableId] = table
}
return table.addFlowEntry(req, pipe)
}
示例9: addGroup
func (pipe *Pipeline) addGroup(req ofp4.GroupMod) error {
var buckets []bucket
for _, msg := range req.Buckets().Iter() {
var b bucket
if err := b.UnmarshalBinary(msg); err != nil {
return err
}
buckets = append(buckets, b)
}
pipe.lock.Lock()
defer pipe.lock.Unlock()
if _, exists := pipe.groups[req.GroupId()]; exists {
return ofp4.MakeErrorMsg(ofp4.OFPET_GROUP_MOD_FAILED, ofp4.OFPGMFC_GROUP_EXISTS)
} else {
pipe.groups[req.GroupId()] = &group{
lock: &sync.RWMutex{},
groupType: req.Type(),
buckets: buckets,
}
}
return nil
}
示例10: createError
func (self *ofmReply) createError(ofpet uint16, code uint16) {
self.resps = append(self.resps,
ofp4.Header(ofp4.MakeErrorMsg(ofpet, code)).AppendData(self.req).SetXid(self.req.Xid()))
}
示例11: importProps
func (self *flowTableFeature) importProps(props ofp4.TableFeaturePropHeader) error {
for _, prop := range props.Iter() {
switch prop.Type() {
case ofp4.OFPTFPT_INSTRUCTIONS, ofp4.OFPTFPT_INSTRUCTIONS_MISS:
var ids []instructionKey
for _, inst := range ofp4.TableFeaturePropInstructions(prop).InstructionIds().Iter() {
if inst.Type() == ofp4.OFPIT_EXPERIMENTER {
ids = append(ids, ofp4.InstructionExperimenter(inst).Experimenter())
} else {
ids = append(ids, inst.Type())
}
}
switch prop.Type() {
case ofp4.OFPTFPT_INSTRUCTIONS:
self.hit.inst = ids
case ofp4.OFPTFPT_INSTRUCTIONS_MISS:
self.miss.inst = ids
}
case ofp4.OFPTFPT_NEXT_TABLES:
self.hit.next = ofp4.TableFeaturePropNextTables(prop).NextTableIds()
case ofp4.OFPTFPT_NEXT_TABLES_MISS:
self.miss.next = ofp4.TableFeaturePropNextTables(prop).NextTableIds()
case ofp4.OFPTFPT_WRITE_ACTIONS, ofp4.OFPTFPT_WRITE_ACTIONS_MISS,
ofp4.OFPTFPT_APPLY_ACTIONS, ofp4.OFPTFPT_APPLY_ACTIONS_MISS:
var ids []actionKey
for _, act := range ofp4.TableFeaturePropActions(prop).ActionIds().Iter() {
if act.Type() == ofp4.OFPAT_EXPERIMENTER {
ids = append(ids, ofp4.ActionExperimenterHeader(act).Experimenter())
} else {
ids = append(ids, act.Type())
}
}
switch prop.Type() {
case ofp4.OFPTFPT_WRITE_ACTIONS:
self.hit.writeActions = ids
case ofp4.OFPTFPT_WRITE_ACTIONS_MISS:
self.miss.writeActions = ids
case ofp4.OFPTFPT_APPLY_ACTIONS:
self.hit.applyActions = ids
case ofp4.OFPTFPT_APPLY_ACTIONS_MISS:
self.miss.applyActions = ids
}
case ofp4.OFPTFPT_MATCH, ofp4.OFPTFPT_WILDCARDS,
ofp4.OFPTFPT_WRITE_SETFIELD, ofp4.OFPTFPT_WRITE_SETFIELD_MISS,
ofp4.OFPTFPT_APPLY_SETFIELD, ofp4.OFPTFPT_APPLY_SETFIELD_MISS:
var ids []oxmId
for _, oxm := range ofp4.TableFeaturePropOxm(prop).OxmIds().Iter() {
hdr := oxm.Header()
if hdr.Class() == ofp4.OFPXMC_EXPERIMENTER {
exp := ofp4.OxmExperimenterHeader(oxm).Experimenter()
ids = append(ids, [...]uint32{oxmHandlers[exp].OxmId(uint32(oxm.Header())), exp})
} else {
ids = append(ids, hdr.Type())
}
}
switch prop.Type() {
case ofp4.OFPTFPT_MATCH:
self.match = ids
case ofp4.OFPTFPT_WILDCARDS:
self.wildcards = ids
case ofp4.OFPTFPT_WRITE_SETFIELD:
self.hit.writeSetfield = ids
case ofp4.OFPTFPT_WRITE_SETFIELD_MISS:
self.miss.writeSetfield = ids
case ofp4.OFPTFPT_APPLY_SETFIELD:
self.hit.applySetfield = ids
case ofp4.OFPTFPT_APPLY_SETFIELD_MISS:
self.miss.applySetfield = ids
}
case ofp4.OFPTFPT_EXPERIMENTER, ofp4.OFPTFPT_EXPERIMENTER_MISS:
msg := ofp4.TableFeaturePropExperimenter(prop)
eKey := experimenterKey{
Experimenter: msg.Experimenter(),
ExpType: msg.ExpType(),
}
if _, ok := tableHandlers[eKey]; !ok {
return ofp4.MakeErrorMsg(
ofp4.OFPET_TABLE_FEATURES_FAILED,
ofp4.OFPTFFC_BAD_ARGUMENT,
)
}
exp := experimenterProp{
experimenterKey: eKey,
Data: msg.ExperimenterData(),
}
switch prop.Type() {
case ofp4.OFPTFPT_EXPERIMENTER:
self.hit.experimenter = append(self.hit.experimenter, exp)
case ofp4.OFPTFPT_EXPERIMENTER_MISS:
self.miss.experimenter = append(self.hit.experimenter, exp)
}
}
}
return nil
}
示例12: accepts
// See openflow switch 1.3.4 spec "Flow Table Modification Messages" page 40
func (self flowTableFeature) accepts(entry *flowEntry, priority uint16) error {
isTableMiss := false
if len(entry.fields) == 0 && priority == 0 {
isTableMiss = true
}
var instKeys instructionKeyList
if isTableMiss && self.miss.inst != nil {
instKeys = instructionKeyList(self.miss.inst)
} else if self.hit.inst != nil {
instKeys = instructionKeyList(self.hit.inst)
}
if entry.instGoto != 0 {
if instKeys != nil && !instKeys.Have(uint16(ofp4.OFPIT_GOTO_TABLE)) {
return ofp4.MakeErrorMsg(
ofp4.OFPET_BAD_INSTRUCTION,
ofp4.OFPBIC_UNSUP_INST,
)
}
var next []uint8
if isTableMiss && self.miss.next != nil {
next = self.miss.next
} else if self.hit.next != nil {
next = self.hit.next
}
if next != nil {
supported := false
for _, tableId := range next {
if entry.instGoto == tableId {
supported = true
}
}
if !supported {
return ofp4.MakeErrorMsg(
ofp4.OFPET_BAD_INSTRUCTION,
ofp4.OFPBIC_BAD_TABLE_ID,
)
}
}
}
if entry.instMetadata != nil {
if instKeys != nil && !instKeys.Have(uint16(ofp4.OFPIT_WRITE_METADATA)) {
return ofp4.MakeErrorMsg(
ofp4.OFPET_BAD_INSTRUCTION,
ofp4.OFPBIC_UNSUP_INST,
)
}
if entry.instMetadata.metadata&^self.metadataWrite != 0 {
return ofp4.MakeErrorMsg(
ofp4.OFPET_BAD_INSTRUCTION,
ofp4.OFPBIC_UNSUP_METADATA,
)
}
if entry.instMetadata.mask&^self.metadataWrite != 0 {
return ofp4.MakeErrorMsg(
ofp4.OFPET_BAD_INSTRUCTION,
ofp4.OFPBIC_UNSUP_METADATA_MASK,
)
}
}
if !isTableMiss && self.match != nil {
unavailable := func(id oxmId) bool {
for _, k := range self.match {
if k == id {
return false
}
}
return true
}
for k, p := range entry.fields {
for _, oxm := range ofp4.Oxm(k.Bytes(p)).Iter() {
var id oxmId
hdr := oxm.Header()
switch hdr.Type() {
case ofp4.OFPXMC_OPENFLOW_BASIC:
id = oxmBasicHandler.OxmId(uint32(hdr))
case ofp4.OFPXMC_EXPERIMENTER:
exp := ofp4.OxmExperimenterHeader(oxm).Experimenter()
id = [...]uint32{
oxmHandlers[exp].OxmId(uint32(hdr)),
exp,
}
default:
return ofp4.MakeErrorMsg(
ofp4.OFPET_BAD_MATCH,
ofp4.OFPBMC_BAD_TYPE,
)
}
if unavailable(id) {
return ofp4.MakeErrorMsg(
ofp4.OFPET_BAD_MATCH,
ofp4.OFPBMC_BAD_FIELD,
)
}
//.........這裏部分代碼省略.........
示例13: AddChannel
func (self *Pipeline) AddChannel(conn io.ReadWriteCloser) error {
self.lock.Lock()
defer self.lock.Unlock()
ch := &channel{
Conn: conn,
}
// process hello
ch.Notify(ofp4.MakeHello(ofp4.MakeHelloElemVersionbitmap([]uint32{uint32(1 << 4)})))
head := make([]byte, 4)
if msg, err := readOfpMessage(conn, head); err != nil {
return err
} else if ofp4.Header(msg).Type() != ofp4.OFPT_HELLO {
return fmt.Errorf("The first message must be HELLO")
} else {
satisfied := false
for _, element := range ofp4.Hello(msg).Elements().Iter() {
switch element.Type() {
case ofp4.OFPHET_VERSIONBITMAP:
bitmaps := ofp4.HelloElemVersionbitmap(element).Bitmaps()
if len(bitmaps) > 0 && (bitmaps[0]&(1<<4) != 0) {
satisfied = true
}
// ensure there be no bits higher than ofp4
for i, b := range bitmaps {
if i == 0 && (b&0xFFFFFFE0) != 0 {
satisfied = false
}
if i > 0 && b != 0 {
satisfied = false
}
}
}
}
if !satisfied && ofp4.Header(msg).Version() == 4 {
satisfied = true
}
if !satisfied {
err := ofp4.MakeErrorMsg(
ofp4.OFPET_HELLO_FAILED,
ofp4.OFPHFC_INCOMPATIBLE,
)
ch.Response(ofp4.Header(err).SetXid(ofp4.Header(msg).Xid()))
return err
}
}
self.channels = append(self.channels, ch)
worker := make(chan MapReducable)
go MapReduce(worker, 4)
go func() {
defer close(worker)
defer conn.Close()
multipartCollect := make(map[uint32][][]byte)
for {
msg, err := readOfpMessage(conn, head)
if err != nil {
log.Print(err)
break
}
reply := ofmReply{pipe: self, channel: ch, req: msg}
switch ofp4.Header(msg).Type() {
case ofp4.OFPT_ERROR:
log.Print("got unexpected OFPT_ERROR")
case ofp4.OFPT_ECHO_REQUEST:
worker <- &ofmEcho{reply}
case ofp4.OFPT_ECHO_REPLY:
log.Print("got unexpected OFPT_ECHO_REPLY")
case ofp4.OFPT_EXPERIMENTER:
worker <- &ofmExperimenter{reply}
case ofp4.OFPT_FEATURES_REQUEST:
worker <- &ofmFeaturesRequest{reply}
case ofp4.OFPT_GET_CONFIG_REQUEST:
worker <- &ofmGetConfigRequest{reply}
case ofp4.OFPT_SET_CONFIG:
worker <- &ofmSetConfig{reply}
case ofp4.OFPT_PACKET_OUT:
worker <- &ofmPacketOut{ofmOutput{reply, nil}}
case ofp4.OFPT_FLOW_MOD:
worker <- &ofmFlowMod{ofmOutput{reply, nil}}
case ofp4.OFPT_GROUP_MOD:
worker <- &ofmGroupMod{reply}
case ofp4.OFPT_PORT_MOD:
worker <- &ofmPortMod{reply}
case ofp4.OFPT_TABLE_MOD:
worker <- &ofmTableMod{reply}
case ofp4.OFPT_MULTIPART_REQUEST:
xid := ofp4.Header(msg).Xid()
req := ofp4.MultipartRequest(msg)
multipartCollect[xid] = append(multipartCollect[xid], req.Body())
if req.Flags()&ofp4.OFPMPF_REQ_MORE == 0 {
reqs := multipartCollect[xid]
delete(multipartCollect, xid)
mreply := ofmMulti{
ofmReply: reply,
//.........這裏部分代碼省略.........
示例14: UnmarshalBinary
func (self *actionList) UnmarshalBinary(data []byte) error {
var actions []action
for _, msg := range ofp4.ActionHeader(data).Iter() {
var act action
switch msg.Type() {
default:
return errors.New("unknown ofp4.Action type")
case ofp4.OFPAT_COPY_TTL_OUT,
ofp4.OFPAT_COPY_TTL_IN,
ofp4.OFPAT_DEC_MPLS_TTL,
ofp4.OFPAT_POP_VLAN,
ofp4.OFPAT_DEC_NW_TTL,
ofp4.OFPAT_POP_PBB:
act = actionGeneric{
Type: msg.Type(),
}
case ofp4.OFPAT_OUTPUT:
a := ofp4.ActionOutput(msg)
act = actionOutput{
Port: a.Port(),
MaxLen: a.MaxLen(),
}
case ofp4.OFPAT_SET_MPLS_TTL:
act = actionMplsTtl{
MplsTtl: ofp4.ActionMplsTtl(msg).MplsTtl(),
}
case ofp4.OFPAT_PUSH_VLAN,
ofp4.OFPAT_PUSH_MPLS,
ofp4.OFPAT_PUSH_PBB:
act = actionPush{
Type: msg.Type(),
Ethertype: ofp4.ActionPush(msg).Ethertype(),
}
case ofp4.OFPAT_POP_MPLS:
act = actionPopMpls{
Ethertype: ofp4.ActionPopMpls(msg).Ethertype(),
}
case ofp4.OFPAT_SET_QUEUE:
act = actionSetQueue{
QueueId: ofp4.ActionSetQueue(msg).QueueId(),
}
case ofp4.OFPAT_GROUP:
act = actionGroup{
GroupId: ofp4.ActionGroup(msg).GroupId(),
}
case ofp4.OFPAT_SET_NW_TTL:
act = actionNwTtl{
NwTtl: ofp4.ActionNwTtl(msg).NwTtl(),
}
case ofp4.OFPAT_SET_FIELD:
f := ofp4.ActionSetField(msg).Field()
act = actionSetField{
Field: f[:f.Header().Length()+4],
}
case ofp4.OFPAT_EXPERIMENTER:
a := ofp4.ActionExperimenterHeader(msg)
if handler, ok := actionHandlers[a.Experimenter()]; ok {
act = actionExperimenter{
Experimenter: a.Experimenter(),
Data: msg[8:],
Handler: handler,
}
} else {
return ofp4.MakeErrorMsg(
ofp4.OFPET_BAD_ACTION,
ofp4.OFPBAC_BAD_EXPERIMENTER,
)
}
}
actions = append(actions, act)
}
*self = actions
return nil
}