@@ -23,6 +23,7 @@ type nodeVNIDMap struct {
23
23
// Synchronizes add or remove ids/namespaces
24
24
lock sync.Mutex
25
25
ids map [string ]uint32
26
+ mcEnabled map [string ]bool
26
27
namespaces map [uint32 ]sets.String
27
28
}
28
29
@@ -31,6 +32,7 @@ func newNodeVNIDMap(policy osdnPolicy, osClient *osclient.Client) *nodeVNIDMap {
31
32
policy : policy ,
32
33
osClient : osClient ,
33
34
ids : make (map [string ]uint32 ),
35
+ mcEnabled : make (map [string ]bool ),
34
36
namespaces : make (map [uint32 ]sets.String ),
35
37
}
36
38
}
@@ -74,6 +76,22 @@ func (vmap *nodeVNIDMap) GetVNID(name string) (uint32, error) {
74
76
return 0 , fmt .Errorf ("Failed to find netid for namespace: %s in vnid map" , name )
75
77
}
76
78
79
+ func (vmap * nodeVNIDMap ) GetMCEnabled (id uint32 ) bool {
80
+ vmap .lock .Lock ()
81
+ defer vmap .lock .Unlock ()
82
+
83
+ set , exists := vmap .namespaces [id ]
84
+ if ! exists || set .Len () == 0 {
85
+ return false
86
+ }
87
+ for _ , ns := range set .List () {
88
+ if ! vmap .mcEnabled [ns ] {
89
+ return false
90
+ }
91
+ }
92
+ return true
93
+ }
94
+
77
95
// Nodes asynchronously watch for both NetNamespaces and services
78
96
// NetNamespaces populates vnid map and services/pod-setup depend on vnid map
79
97
// If for some reason, vnid map propagation from master to node is slow
@@ -99,17 +117,18 @@ func (vmap *nodeVNIDMap) WaitAndGetVNID(name string) (uint32, error) {
99
117
}
100
118
}
101
119
102
- func (vmap * nodeVNIDMap ) setVNID (name string , id uint32 ) {
120
+ func (vmap * nodeVNIDMap ) setVNID (name string , id uint32 , mcEnabled bool ) {
103
121
vmap .lock .Lock ()
104
122
defer vmap .lock .Unlock ()
105
123
106
124
if oldId , found := vmap .ids [name ]; found {
107
125
vmap .removeNamespaceFromSet (name , oldId )
108
126
}
109
127
vmap .ids [name ] = id
128
+ vmap .mcEnabled [name ] = mcEnabled
110
129
vmap .addNamespaceToSet (name , id )
111
130
112
- log .Infof ("Associate netid %d to namespace %q" , id , name )
131
+ log .Infof ("Associate netid %d to namespace %q with mcEnabled %v " , id , name , mcEnabled )
113
132
}
114
133
115
134
func (vmap * nodeVNIDMap ) unsetVNID (name string ) (id uint32 , err error ) {
@@ -122,18 +141,24 @@ func (vmap *nodeVNIDMap) unsetVNID(name string) (id uint32, err error) {
122
141
}
123
142
vmap .removeNamespaceFromSet (name , id )
124
143
delete (vmap .ids , name )
144
+ delete (vmap .mcEnabled , name )
125
145
log .Infof ("Dissociate netid %d from namespace %q" , id , name )
126
146
return id , nil
127
147
}
128
148
149
+ func netnsIsMulticastEnabled (netns * osapi.NetNamespace ) bool {
150
+ enabled , ok := netns .Annotations [osapi .MulticastEnabledAnnotation ]
151
+ return enabled == "true" && ok
152
+ }
153
+
129
154
func (vmap * nodeVNIDMap ) populateVNIDs () error {
130
155
nets , err := vmap .osClient .NetNamespaces ().List (kapi.ListOptions {})
131
156
if err != nil {
132
157
return err
133
158
}
134
159
135
160
for _ , net := range nets .Items {
136
- vmap .setVNID (net .Name , net .NetID )
161
+ vmap .setVNID (net .Name , net .NetID , netnsIsMulticastEnabled ( & net ) )
137
162
}
138
163
return nil
139
164
}
@@ -156,12 +181,14 @@ func (vmap *nodeVNIDMap) watchNetNamespaces() {
156
181
log .V (5 ).Infof ("Watch %s event for NetNamespace %q" , delta .Type , netns .ObjectMeta .Name )
157
182
switch delta .Type {
158
183
case cache .Sync , cache .Added , cache .Updated :
159
- // Skip this event if the old and new network ids are same
184
+ // Skip this event if nothing has changed
160
185
oldNetID , err := vmap .GetVNID (netns .NetName )
161
- if (err == nil ) && (oldNetID == netns .NetID ) {
186
+ oldMCEnabled := vmap .mcEnabled [netns .NetName ]
187
+ mcEnabled := netnsIsMulticastEnabled (netns )
188
+ if err == nil && oldNetID == netns .NetID && oldMCEnabled == mcEnabled {
162
189
break
163
190
}
164
- vmap .setVNID (netns .NetName , netns .NetID )
191
+ vmap .setVNID (netns .NetName , netns .NetID , mcEnabled )
165
192
166
193
if delta .Type == cache .Added {
167
194
vmap .policy .AddNetNamespace (netns )
0 commit comments