Committed by
Gerrit Code Review
Added skeleton for Netconf Flow Rule Provider.
Change-Id: Iee4389f897c438aa6cda50fb48079fdd0baefe8a
Showing
3 changed files
with
189 additions
and
0 deletions
providers/netconf/flow/pom.xml
0 → 100644
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<!-- | ||
3 | + ~ Copyright 2014 Open Networking Laboratory | ||
4 | + ~ | ||
5 | + ~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
6 | + ~ you may not use this file except in compliance with the License. | ||
7 | + ~ You may obtain a copy of the License at | ||
8 | + ~ | ||
9 | + ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
10 | + ~ | ||
11 | + ~ Unless required by applicable law or agreed to in writing, software | ||
12 | + ~ distributed under the License is distributed on an "AS IS" BASIS, | ||
13 | + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
14 | + ~ See the License for the specific language governing permissions and | ||
15 | + ~ limitations under the License. | ||
16 | + --> | ||
17 | +<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
18 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
19 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
20 | + <modelVersion>4.0.0</modelVersion> | ||
21 | + | ||
22 | + <parent> | ||
23 | + <groupId>org.onosproject</groupId> | ||
24 | + <artifactId>onos-netconf-providers</artifactId> | ||
25 | + <version>1.2.0-SNAPSHOT</version> | ||
26 | + <relativePath>../pom.xml</relativePath> | ||
27 | + </parent> | ||
28 | + | ||
29 | + <artifactId>onos-netconf-provider-flow</artifactId> | ||
30 | + <packaging>bundle</packaging> | ||
31 | + | ||
32 | + <description>ONOS Netconf protocol flow provider</description> | ||
33 | + | ||
34 | +</project> |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.provider.netconf.flow.impl; | ||
17 | + | ||
18 | +import static org.slf4j.LoggerFactory.getLogger; | ||
19 | + | ||
20 | +import java.util.Collections; | ||
21 | +import java.util.Set; | ||
22 | +import java.util.concurrent.ConcurrentHashMap; | ||
23 | +import java.util.concurrent.ConcurrentMap; | ||
24 | +import java.util.concurrent.TimeUnit; | ||
25 | + | ||
26 | +import org.apache.felix.scr.annotations.Activate; | ||
27 | +import org.apache.felix.scr.annotations.Component; | ||
28 | +import org.apache.felix.scr.annotations.Deactivate; | ||
29 | +import org.apache.felix.scr.annotations.Modified; | ||
30 | +import org.apache.felix.scr.annotations.Reference; | ||
31 | +import org.apache.felix.scr.annotations.ReferenceCardinality; | ||
32 | +import org.jboss.netty.util.HashedWheelTimer; | ||
33 | +import org.jboss.netty.util.Timeout; | ||
34 | +import org.jboss.netty.util.TimerTask; | ||
35 | +import org.onlab.util.Timer; | ||
36 | +import org.onosproject.core.ApplicationId; | ||
37 | +import org.onosproject.net.DeviceId; | ||
38 | +import org.onosproject.net.flow.FlowEntry; | ||
39 | +import org.onosproject.net.flow.FlowRule; | ||
40 | +import org.onosproject.net.flow.FlowRuleBatchOperation; | ||
41 | +import org.onosproject.net.flow.FlowRuleProvider; | ||
42 | +import org.onosproject.net.flow.FlowRuleProviderRegistry; | ||
43 | +import org.onosproject.net.flow.FlowRuleProviderService; | ||
44 | +import org.onosproject.net.provider.AbstractProvider; | ||
45 | +import org.onosproject.net.provider.ProviderId; | ||
46 | +import org.slf4j.Logger; | ||
47 | +/** | ||
48 | + * Netconf provider to accept any flow and report them. | ||
49 | + */ | ||
50 | +@Component(immediate = true) | ||
51 | +public class NetconfFlowRuleProvider extends AbstractProvider | ||
52 | + implements FlowRuleProvider { | ||
53 | + | ||
54 | + private final Logger log = getLogger(getClass()); | ||
55 | + | ||
56 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
57 | + protected FlowRuleProviderRegistry providerRegistry; | ||
58 | + | ||
59 | + private ConcurrentMap<DeviceId, Set<FlowEntry>> flowTable = new ConcurrentHashMap<>(); | ||
60 | + | ||
61 | + private FlowRuleProviderService providerService; | ||
62 | + | ||
63 | + private HashedWheelTimer timer = Timer.getTimer(); | ||
64 | + private Timeout timeout; | ||
65 | + | ||
66 | + public NetconfFlowRuleProvider() { | ||
67 | + super(new ProviderId("null", "org.onosproject.provider.nil")); | ||
68 | + } | ||
69 | + | ||
70 | + @Activate | ||
71 | + public void activate() { | ||
72 | + providerService = providerRegistry.register(this); | ||
73 | + timeout = timer.newTimeout(new StatisticTask(), 5, TimeUnit.SECONDS); | ||
74 | + applyRule(); | ||
75 | + | ||
76 | + log.info("Started"); | ||
77 | + } | ||
78 | + | ||
79 | + @Deactivate | ||
80 | + public void deactivate() { | ||
81 | + providerRegistry.unregister(this); | ||
82 | + providerService = null; | ||
83 | + timeout.cancel(); | ||
84 | + | ||
85 | + log.info("Stopped"); | ||
86 | + } | ||
87 | + | ||
88 | + @Modified | ||
89 | + public void modified() { | ||
90 | + applyRule(); | ||
91 | + | ||
92 | + } | ||
93 | + | ||
94 | + @Override | ||
95 | + public void applyFlowRule(FlowRule... flowRules) { | ||
96 | + // String editXml=parser will take schema and flowrule object to build | ||
97 | + // xml | ||
98 | + // execute xml command using JNC client | ||
99 | + } | ||
100 | + | ||
101 | + @Override | ||
102 | + public void removeFlowRule(FlowRule... flowRules) { | ||
103 | + // String editXml=parser will take schema and flowrule object to build | ||
104 | + // xml | ||
105 | + // execute xml command using JNC client | ||
106 | + } | ||
107 | + | ||
108 | + private void applyRule() { | ||
109 | + // applyFlowRule(flowRules);//currentl | ||
110 | + } | ||
111 | + | ||
112 | + @Override | ||
113 | + public void removeRulesById(ApplicationId id, FlowRule... flowRules) { | ||
114 | + log.info("removal by app id not supported in null provider"); | ||
115 | + } | ||
116 | + | ||
117 | + @Override | ||
118 | + public void executeBatch(FlowRuleBatchOperation batch) { | ||
119 | + | ||
120 | + } | ||
121 | + | ||
122 | + private class StatisticTask implements TimerTask { | ||
123 | + | ||
124 | + @Override | ||
125 | + public void run(Timeout to) throws Exception { | ||
126 | + for (DeviceId devId : flowTable.keySet()) { | ||
127 | + providerService.pushFlowMetrics(devId, flowTable | ||
128 | + .getOrDefault(devId, Collections.emptySet())); | ||
129 | + } | ||
130 | + timeout = timer.newTimeout(to.getTask(), 5, TimeUnit.SECONDS); | ||
131 | + | ||
132 | + } | ||
133 | + } | ||
134 | +} |
providers/netconf/flow/src/main/java/org/onosproject/provider/netconf/flow/impl/package-info.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2014 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +/** | ||
18 | + * Provider that will accept any flow rules. | ||
19 | + */ | ||
20 | +package org.onosproject.provider.netconf.flow.impl; | ||
21 | + |
-
Please register or login to post a comment