forked from contiv/ofnet
-
Notifications
You must be signed in to change notification settings - Fork 16
/
fgraphTable.go
executable file
·97 lines (75 loc) · 2.37 KB
/
fgraphTable.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/***
Copyright 2014 Cisco Systems Inc. All rights reserved.
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 ofctrl
// This file implements the forwarding graph API for the table
import (
"fmt"
"sync"
"antrea.io/libOpenflow/openflow13"
log "github.com/sirupsen/logrus"
)
// Fgraph table element
type Table struct {
Switch *OFSwitch
TableId uint8
flowDb map[string]*Flow // database of flow entries
lock sync.Mutex // lock flodb modification
}
// Fgraph element type for table
func (self *Table) Type() string {
return "table"
}
// instruction set for table element
func (self *Table) GetFlowInstr() openflow13.Instruction {
return openflow13.NewInstrGotoTable(self.TableId)
}
// FIXME: global unique flow cookie
var globalFlowID uint64 = 1
// Create a new flow on the table
func (self *Table) NewFlow(match FlowMatch) (*Flow, error) {
// modifications to flowdb requires a lock
self.lock.Lock()
defer self.lock.Unlock()
flow := new(Flow)
flow.Table = self
flow.Match = match
flow.isInstalled = false
flow.flowActions = make([]*FlowAction, 0)
log.Debugf("Creating new flow for match: %+v", match)
// See if the flow already exists
flowKey := flow.flowKey()
if self.flowDb[flowKey] != nil {
log.Errorf("Flow %s already exists", flowKey)
return nil, fmt.Errorf("Flow %s already exists", flowKey)
}
log.Debugf("Added flow: %s", flowKey)
// Save it in DB. We dont install the flow till its next graph elem is set
self.flowDb[flowKey] = flow
return flow, nil
}
// Delete a flow from the table
func (self *Table) DeleteFlow(flowKey string) error {
// modifications to flowdb requires a lock
self.lock.Lock()
defer self.lock.Unlock()
// first empty it and then delete it.
self.flowDb[flowKey] = nil
delete(self.flowDb, flowKey)
log.Debugf("Deleted flow: %s", flowKey)
return nil
}
// Delete the table
func (self *Table) Delete() error {
// FIXME: Delete the table
return nil
}