Committed by
Yuta HIGUCHI
NetconfAlarmProvider alerts core about notifications given subscription.
Change-Id: I7561ba680eb8bac33a8543d6aa1bccf6732e95db
Showing
13 changed files
with
377 additions
and
29 deletions
| ... | @@ -141,7 +141,41 @@ public interface NetconfSession { | ... | @@ -141,7 +141,41 @@ public interface NetconfSession { |
| 141 | boolean deleteConfig(String targetConfiguration) throws NetconfException; | 141 | boolean deleteConfig(String targetConfiguration) throws NetconfException; |
| 142 | 142 | ||
| 143 | /** | 143 | /** |
| 144 | - * Locks the candidate configuration. | 144 | + * Starts subscription to the device's notifications. |
| 145 | + * | ||
| 146 | + * @throws NetconfException when there is a problem starting the subscription | ||
| 147 | + */ | ||
| 148 | + void startSubscription() throws NetconfException; | ||
| 149 | + | ||
| 150 | + /** | ||
| 151 | + * Ends subscription to the device's notifications. | ||
| 152 | + * | ||
| 153 | + * @throws NetconfException when there is a problem ending the subscription | ||
| 154 | + */ | ||
| 155 | + void endSubscription() throws NetconfException; | ||
| 156 | + | ||
| 157 | + /** | ||
| 158 | + * Locks the specified configuration. | ||
| 159 | + * | ||
| 160 | + * @param configType type of configuration to be locked | ||
| 161 | + * @return true if successful. | ||
| 162 | + * @throws NetconfException when there is a problem in the communication process on | ||
| 163 | + * the underlying connection | ||
| 164 | + */ | ||
| 165 | + boolean lock(String configType) throws NetconfException; | ||
| 166 | + | ||
| 167 | + /** | ||
| 168 | + * Unlocks the specified configuration. | ||
| 169 | + * | ||
| 170 | + * @param configType type of configuration to be locked | ||
| 171 | + * @return true if successful. | ||
| 172 | + * @throws NetconfException when there is a problem in the communication process on | ||
| 173 | + * the underlying connection | ||
| 174 | + */ | ||
| 175 | + boolean unlock(String configType) throws NetconfException; | ||
| 176 | + | ||
| 177 | + /** | ||
| 178 | + * Locks the running configuration. | ||
| 145 | * | 179 | * |
| 146 | * @return true if successful. | 180 | * @return true if successful. |
| 147 | * @throws NetconfException when there is a problem in the communication process on | 181 | * @throws NetconfException when there is a problem in the communication process on |
| ... | @@ -150,7 +184,7 @@ public interface NetconfSession { | ... | @@ -150,7 +184,7 @@ public interface NetconfSession { |
| 150 | boolean lock() throws NetconfException; | 184 | boolean lock() throws NetconfException; |
| 151 | 185 | ||
| 152 | /** | 186 | /** |
| 153 | - * Unlocks the candidate configuration. | 187 | + * Unlocks the running configuration. |
| 154 | * | 188 | * |
| 155 | * @return true if successful. | 189 | * @return true if successful. |
| 156 | * @throws NetconfException when there is a problem in the communication process on | 190 | * @throws NetconfException when there is a problem in the communication process on | ... | ... |
| ... | @@ -7,6 +7,7 @@ COMPILE_DEPS = [ | ... | @@ -7,6 +7,7 @@ COMPILE_DEPS = [ |
| 7 | TEST_DEPS = [ | 7 | TEST_DEPS = [ |
| 8 | '//lib:TEST_ADAPTERS', | 8 | '//lib:TEST_ADAPTERS', |
| 9 | '//utils/osgi:onlab-osgi-tests', | 9 | '//utils/osgi:onlab-osgi-tests', |
| 10 | + '//core/api:onos-api-tests', | ||
| 10 | ] | 11 | ] |
| 11 | 12 | ||
| 12 | osgi_jar_with_tests ( | 13 | osgi_jar_with_tests ( | ... | ... |
| ... | @@ -81,9 +81,10 @@ public class NetconfSessionImpl implements NetconfSession { | ... | @@ -81,9 +81,10 @@ public class NetconfSessionImpl implements NetconfSession { |
| 81 | private List<String> deviceCapabilities = | 81 | private List<String> deviceCapabilities = |
| 82 | Collections.singletonList("urn:ietf:params:netconf:base:1.0"); | 82 | Collections.singletonList("urn:ietf:params:netconf:base:1.0"); |
| 83 | private String serverCapabilities; | 83 | private String serverCapabilities; |
| 84 | - private NetconfStreamHandler t; | 84 | + private NetconfStreamHandler streamHandler; |
| 85 | private Map<Integer, CompletableFuture<String>> replies; | 85 | private Map<Integer, CompletableFuture<String>> replies; |
| 86 | private List<String> errorReplies; | 86 | private List<String> errorReplies; |
| 87 | + private boolean subscriptionConnected = false; | ||
| 87 | 88 | ||
| 88 | 89 | ||
| 89 | public NetconfSessionImpl(NetconfDeviceInfo deviceInfo) throws NetconfException { | 90 | public NetconfSessionImpl(NetconfDeviceInfo deviceInfo) throws NetconfException { |
| ... | @@ -136,9 +137,9 @@ public class NetconfSessionImpl implements NetconfSession { | ... | @@ -136,9 +137,9 @@ public class NetconfSessionImpl implements NetconfSession { |
| 136 | try { | 137 | try { |
| 137 | sshSession = netconfConnection.openSession(); | 138 | sshSession = netconfConnection.openSession(); |
| 138 | sshSession.startSubSystem("netconf"); | 139 | sshSession.startSubSystem("netconf"); |
| 139 | - t = new NetconfStreamThread(sshSession.getStdout(), sshSession.getStdin(), | 140 | + streamHandler = new NetconfStreamThread(sshSession.getStdout(), sshSession.getStdin(), |
| 140 | - sshSession.getStderr(), deviceInfo, | 141 | + sshSession.getStderr(), deviceInfo, |
| 141 | - new NetconfSessionDelegateImpl()); | 142 | + new NetconfSessionDelegateImpl()); |
| 142 | this.addDeviceOutputListener(new NetconfDeviceOutputEventListenerImpl(deviceInfo)); | 143 | this.addDeviceOutputListener(new NetconfDeviceOutputEventListenerImpl(deviceInfo)); |
| 143 | sendHello(); | 144 | sendHello(); |
| 144 | } catch (IOException e) { | 145 | } catch (IOException e) { |
| ... | @@ -148,6 +149,45 @@ public class NetconfSessionImpl implements NetconfSession { | ... | @@ -148,6 +149,45 @@ public class NetconfSessionImpl implements NetconfSession { |
| 148 | } | 149 | } |
| 149 | } | 150 | } |
| 150 | 151 | ||
| 152 | + private void startSubscriptionConnection() throws NetconfException { | ||
| 153 | + if (!serverCapabilities.contains("interleave")) { | ||
| 154 | + throw new NetconfException("Device" + deviceInfo + "does not support interleave"); | ||
| 155 | + } | ||
| 156 | + String reply = sendRequest(createSubscriptionString()); | ||
| 157 | + if (!checkReply(reply)) { | ||
| 158 | + throw new NetconfException("Subscription not successful with device " | ||
| 159 | + + deviceInfo + " with reply " + reply); | ||
| 160 | + } | ||
| 161 | + subscriptionConnected = true; | ||
| 162 | + } | ||
| 163 | + | ||
| 164 | + public void startSubscription() throws NetconfException { | ||
| 165 | + if (!subscriptionConnected) { | ||
| 166 | + startSubscriptionConnection(); | ||
| 167 | + } | ||
| 168 | + streamHandler.setEnableNotifications(true); | ||
| 169 | + } | ||
| 170 | + | ||
| 171 | + private String createSubscriptionString() { | ||
| 172 | + StringBuilder subscriptionbuffer = new StringBuilder(); | ||
| 173 | + subscriptionbuffer.append("<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"); | ||
| 174 | + subscriptionbuffer.append(" <create-subscription\n"); | ||
| 175 | + subscriptionbuffer.append("xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\">\n"); | ||
| 176 | + subscriptionbuffer.append(" </create-subscription>\n"); | ||
| 177 | + subscriptionbuffer.append("</rpc>\n"); | ||
| 178 | + subscriptionbuffer.append(ENDPATTERN); | ||
| 179 | + return subscriptionbuffer.toString(); | ||
| 180 | + } | ||
| 181 | + | ||
| 182 | + @Override | ||
| 183 | + public void endSubscription() throws NetconfException { | ||
| 184 | + if (subscriptionConnected) { | ||
| 185 | + streamHandler.setEnableNotifications(false); | ||
| 186 | + } else { | ||
| 187 | + throw new NetconfException("Subscription does not exist."); | ||
| 188 | + } | ||
| 189 | + } | ||
| 190 | + | ||
| 151 | private void sendHello() throws NetconfException { | 191 | private void sendHello() throws NetconfException { |
| 152 | serverCapabilities = sendRequest(createHelloString()); | 192 | serverCapabilities = sendRequest(createHelloString()); |
| 153 | } | 193 | } |
| ... | @@ -197,7 +237,7 @@ public class NetconfSessionImpl implements NetconfSession { | ... | @@ -197,7 +237,7 @@ public class NetconfSessionImpl implements NetconfSession { |
| 197 | 237 | ||
| 198 | @Override | 238 | @Override |
| 199 | public CompletableFuture<String> request(String request) { | 239 | public CompletableFuture<String> request(String request) { |
| 200 | - CompletableFuture<String> ftrep = t.sendMessage(request); | 240 | + CompletableFuture<String> ftrep = streamHandler.sendMessage(request); |
| 201 | replies.put(messageIdInteger.get(), ftrep); | 241 | replies.put(messageIdInteger.get(), ftrep); |
| 202 | return ftrep; | 242 | return ftrep; |
| 203 | } | 243 | } |
| ... | @@ -382,31 +422,47 @@ public class NetconfSessionImpl implements NetconfSession { | ... | @@ -382,31 +422,47 @@ public class NetconfSessionImpl implements NetconfSession { |
| 382 | } | 422 | } |
| 383 | 423 | ||
| 384 | @Override | 424 | @Override |
| 385 | - public boolean lock() throws NetconfException { | 425 | + public boolean lock(String configType) throws NetconfException { |
| 386 | StringBuilder rpc = new StringBuilder(XML_HEADER); | 426 | StringBuilder rpc = new StringBuilder(XML_HEADER); |
| 387 | - rpc.append("<rpc>"); | 427 | + rpc.append("<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"); |
| 388 | rpc.append("<lock>"); | 428 | rpc.append("<lock>"); |
| 389 | rpc.append("<target>"); | 429 | rpc.append("<target>"); |
| 390 | - rpc.append("<candidate/>"); | 430 | + rpc.append("<"); |
| 431 | + rpc.append(configType); | ||
| 432 | + rpc.append("/>"); | ||
| 391 | rpc.append("</target>"); | 433 | rpc.append("</target>"); |
| 392 | rpc.append("</lock>"); | 434 | rpc.append("</lock>"); |
| 393 | rpc.append("</rpc>"); | 435 | rpc.append("</rpc>"); |
| 394 | rpc.append(ENDPATTERN); | 436 | rpc.append(ENDPATTERN); |
| 395 | - return checkReply(sendRequest(rpc.toString())); | 437 | + String lockReply = sendRequest(rpc.toString()); |
| 438 | + return checkReply(lockReply); | ||
| 396 | } | 439 | } |
| 397 | 440 | ||
| 398 | @Override | 441 | @Override |
| 399 | - public boolean unlock() throws NetconfException { | 442 | + public boolean unlock(String configType) throws NetconfException { |
| 400 | StringBuilder rpc = new StringBuilder(XML_HEADER); | 443 | StringBuilder rpc = new StringBuilder(XML_HEADER); |
| 401 | - rpc.append("<rpc>"); | 444 | + rpc.append("<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"); |
| 402 | rpc.append("<unlock>"); | 445 | rpc.append("<unlock>"); |
| 403 | rpc.append("<target>"); | 446 | rpc.append("<target>"); |
| 404 | - rpc.append("<candidate/>"); | 447 | + rpc.append("<"); |
| 448 | + rpc.append(configType); | ||
| 449 | + rpc.append("/>"); | ||
| 405 | rpc.append("</target>"); | 450 | rpc.append("</target>"); |
| 406 | rpc.append("</unlock>"); | 451 | rpc.append("</unlock>"); |
| 407 | rpc.append("</rpc>"); | 452 | rpc.append("</rpc>"); |
| 408 | rpc.append(ENDPATTERN); | 453 | rpc.append(ENDPATTERN); |
| 409 | - return checkReply(sendRequest(rpc.toString())); | 454 | + String unlockReply = sendRequest(rpc.toString()); |
| 455 | + return checkReply(unlockReply); | ||
| 456 | + } | ||
| 457 | + | ||
| 458 | + @Override | ||
| 459 | + public boolean lock() throws NetconfException { | ||
| 460 | + return lock("running"); | ||
| 461 | + } | ||
| 462 | + | ||
| 463 | + @Override | ||
| 464 | + public boolean unlock() throws NetconfException { | ||
| 465 | + return unlock("running"); | ||
| 410 | } | 466 | } |
| 411 | 467 | ||
| 412 | @Override | 468 | @Override |
| ... | @@ -454,12 +510,12 @@ public class NetconfSessionImpl implements NetconfSession { | ... | @@ -454,12 +510,12 @@ public class NetconfSessionImpl implements NetconfSession { |
| 454 | 510 | ||
| 455 | @Override | 511 | @Override |
| 456 | public void addDeviceOutputListener(NetconfDeviceOutputEventListener listener) { | 512 | public void addDeviceOutputListener(NetconfDeviceOutputEventListener listener) { |
| 457 | - t.addDeviceEventListener(listener); | 513 | + streamHandler.addDeviceEventListener(listener); |
| 458 | } | 514 | } |
| 459 | 515 | ||
| 460 | @Override | 516 | @Override |
| 461 | public void removeDeviceOutputListener(NetconfDeviceOutputEventListener listener) { | 517 | public void removeDeviceOutputListener(NetconfDeviceOutputEventListener listener) { |
| 462 | - t.removeDeviceEventListener(listener); | 518 | + streamHandler.removeDeviceEventListener(listener); |
| 463 | } | 519 | } |
| 464 | 520 | ||
| 465 | private boolean checkReply(String reply) throws NetconfException { | 521 | private boolean checkReply(String reply) throws NetconfException { |
| ... | @@ -481,6 +537,7 @@ public class NetconfSessionImpl implements NetconfSession { | ... | @@ -481,6 +537,7 @@ public class NetconfSessionImpl implements NetconfSession { |
| 481 | @Override | 537 | @Override |
| 482 | public void notify(NetconfDeviceOutputEvent event) { | 538 | public void notify(NetconfDeviceOutputEvent event) { |
| 483 | Optional<Integer> messageId = event.getMessageID(); | 539 | Optional<Integer> messageId = event.getMessageID(); |
| 540 | + | ||
| 484 | if (!messageId.isPresent()) { | 541 | if (!messageId.isPresent()) { |
| 485 | errorReplies.add(event.getMessagePayload()); | 542 | errorReplies.add(event.getMessagePayload()); |
| 486 | log.error("Device {} sent error reply {}", | 543 | log.error("Device {} sent error reply {}", | ... | ... |
| ... | @@ -16,6 +16,7 @@ | ... | @@ -16,6 +16,7 @@ |
| 16 | 16 | ||
| 17 | package org.onosproject.netconf.ctl; | 17 | package org.onosproject.netconf.ctl; |
| 18 | 18 | ||
| 19 | +import com.google.common.annotations.Beta; | ||
| 19 | import org.onosproject.netconf.NetconfDeviceOutputEventListener; | 20 | import org.onosproject.netconf.NetconfDeviceOutputEventListener; |
| 20 | 21 | ||
| 21 | import java.util.concurrent.CompletableFuture; | 22 | import java.util.concurrent.CompletableFuture; |
| ... | @@ -46,4 +47,13 @@ public interface NetconfStreamHandler { | ... | @@ -46,4 +47,13 @@ public interface NetconfStreamHandler { |
| 46 | * @param listener Netconf device event listener | 47 | * @param listener Netconf device event listener |
| 47 | */ | 48 | */ |
| 48 | void removeDeviceEventListener(NetconfDeviceOutputEventListener listener); | 49 | void removeDeviceEventListener(NetconfDeviceOutputEventListener listener); |
| 50 | + | ||
| 51 | + @Beta | ||
| 52 | + /** | ||
| 53 | + * Sets instance variable that when true allows receipt of notifications. | ||
| 54 | + * | ||
| 55 | + * @param enableNotifications if true, allows action based off notifications | ||
| 56 | + * else, stops action based off notifications | ||
| 57 | + */ | ||
| 58 | + void setEnableNotifications(boolean enableNotifications); | ||
| 49 | } | 59 | } | ... | ... |
| ... | @@ -57,8 +57,9 @@ public class NetconfStreamThread extends Thread implements NetconfStreamHandler | ... | @@ -57,8 +57,9 @@ public class NetconfStreamThread extends Thread implements NetconfStreamHandler |
| 57 | private NetconfDeviceInfo netconfDeviceInfo; | 57 | private NetconfDeviceInfo netconfDeviceInfo; |
| 58 | private NetconfSessionDelegate sessionDelegate; | 58 | private NetconfSessionDelegate sessionDelegate; |
| 59 | private NetconfMessageState state; | 59 | private NetconfMessageState state; |
| 60 | - private List<NetconfDeviceOutputEventListener> netconfDeviceEventListeners | 60 | + private List<NetconfDeviceOutputEventListener> netconfDeviceEventListeners |
| 61 | - = Lists.newArrayList(); | 61 | + = Lists.newCopyOnWriteArrayList(); |
| 62 | + private boolean enableNotifications = true; | ||
| 62 | 63 | ||
| 63 | public NetconfStreamThread(final InputStream in, final OutputStream out, | 64 | public NetconfStreamThread(final InputStream in, final OutputStream out, |
| 64 | final InputStream err, NetconfDeviceInfo deviceInfo, | 65 | final InputStream err, NetconfDeviceInfo deviceInfo, |
| ... | @@ -195,12 +196,14 @@ public class NetconfStreamThread extends Thread implements NetconfStreamHandler | ... | @@ -195,12 +196,14 @@ public class NetconfStreamThread extends Thread implements NetconfStreamHandler |
| 195 | netconfDeviceEventListeners.forEach( | 196 | netconfDeviceEventListeners.forEach( |
| 196 | listener -> listener.event(event)); | 197 | listener -> listener.event(event)); |
| 197 | } else if (deviceReply.contains(NOTIFICATION_LABEL)) { | 198 | } else if (deviceReply.contains(NOTIFICATION_LABEL)) { |
| 198 | - final String finalDeviceReply = deviceReply; | 199 | + if (enableNotifications) { |
| 199 | - netconfDeviceEventListeners.forEach( | 200 | + final String finalDeviceReply = deviceReply; |
| 200 | - listener -> listener.event(new NetconfDeviceOutputEvent( | 201 | + netconfDeviceEventListeners.forEach( |
| 201 | - NetconfDeviceOutputEvent.Type.DEVICE_NOTIFICATION, | 202 | + listener -> listener.event(new NetconfDeviceOutputEvent( |
| 202 | - null, finalDeviceReply, getMsgId(finalDeviceReply), | 203 | + NetconfDeviceOutputEvent.Type.DEVICE_NOTIFICATION, |
| 203 | - netconfDeviceInfo))); | 204 | + null, finalDeviceReply, getMsgId(finalDeviceReply), |
| 205 | + netconfDeviceInfo))); | ||
| 206 | + } | ||
| 204 | } else { | 207 | } else { |
| 205 | log.info("Error on replay from device {} ", deviceReply); | 208 | log.info("Error on replay from device {} ", deviceReply); |
| 206 | } | 209 | } |
| ... | @@ -240,4 +243,8 @@ public class NetconfStreamThread extends Thread implements NetconfStreamHandler | ... | @@ -240,4 +243,8 @@ public class NetconfStreamThread extends Thread implements NetconfStreamHandler |
| 240 | public void removeDeviceEventListener(NetconfDeviceOutputEventListener listener) { | 243 | public void removeDeviceEventListener(NetconfDeviceOutputEventListener listener) { |
| 241 | netconfDeviceEventListeners.remove(listener); | 244 | netconfDeviceEventListeners.remove(listener); |
| 242 | } | 245 | } |
| 246 | + | ||
| 247 | + public void setEnableNotifications(boolean enableNotifications) { | ||
| 248 | + this.enableNotifications = enableNotifications; | ||
| 249 | + } | ||
| 243 | } | 250 | } | ... | ... |
providers/netconf/alarm/pom.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | +<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| 3 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| 4 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| 5 | + <parent> | ||
| 6 | + <artifactId>onos-netconf-providers</artifactId> | ||
| 7 | + <groupId>org.onosproject</groupId> | ||
| 8 | + <version>1.7.0-SNAPSHOT</version> | ||
| 9 | + </parent> | ||
| 10 | + <modelVersion>4.0.0</modelVersion> | ||
| 11 | + | ||
| 12 | + <artifactId>onos-netconf-provider-alarm</artifactId> | ||
| 13 | + <packaging>bundle</packaging> | ||
| 14 | + | ||
| 15 | + <description>ONOS Netconf protocol alarm provider</description> | ||
| 16 | + | ||
| 17 | + <dependencies> | ||
| 18 | + <dependency> | ||
| 19 | + <groupId>org.onosproject</groupId> | ||
| 20 | + <artifactId>onlab-junit</artifactId> | ||
| 21 | + <scope>test</scope> | ||
| 22 | + </dependency> | ||
| 23 | + <dependency> | ||
| 24 | + <groupId>org.onosproject</groupId> | ||
| 25 | + <artifactId>onos-netconf-api</artifactId> | ||
| 26 | + <version>${project.version}</version> | ||
| 27 | + </dependency> | ||
| 28 | + <dependency> | ||
| 29 | + <groupId>org.onosproject</groupId> | ||
| 30 | + <artifactId>onos-netconf-ctl</artifactId> | ||
| 31 | + <version>${project.version}</version> | ||
| 32 | + </dependency> | ||
| 33 | + </dependencies> | ||
| 34 | + | ||
| 35 | + <build> | ||
| 36 | + <plugins> | ||
| 37 | + <plugin> | ||
| 38 | + <groupId>org.apache.felix</groupId> | ||
| 39 | + <artifactId>maven-scr-plugin</artifactId> | ||
| 40 | + </plugin> | ||
| 41 | + <plugin> | ||
| 42 | + <groupId>org.onosproject</groupId> | ||
| 43 | + <artifactId>onos-maven-plugin</artifactId> | ||
| 44 | + </plugin> | ||
| 45 | + </plugins> | ||
| 46 | + </build> | ||
| 47 | + | ||
| 48 | + | ||
| 49 | +</project> | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | +/* | ||
| 2 | + * Copyright 2016-present 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 | +package org.onosproject.provider.netconf.alarm; | ||
| 18 | + | ||
| 19 | +import com.google.common.collect.Maps; | ||
| 20 | +import org.apache.felix.scr.annotations.Activate; | ||
| 21 | +import org.apache.felix.scr.annotations.Component; | ||
| 22 | +import org.apache.felix.scr.annotations.Deactivate; | ||
| 23 | +import org.apache.felix.scr.annotations.Reference; | ||
| 24 | +import org.apache.felix.scr.annotations.ReferenceCardinality; | ||
| 25 | +import org.onosproject.incubator.net.faultmanagement.alarm.Alarm; | ||
| 26 | +import org.onosproject.incubator.net.faultmanagement.alarm.AlarmProvider; | ||
| 27 | +import org.onosproject.incubator.net.faultmanagement.alarm.AlarmProviderService; | ||
| 28 | +import org.onosproject.incubator.net.faultmanagement.alarm.AlarmService; | ||
| 29 | +import org.onosproject.incubator.net.faultmanagement.alarm.AlarmProviderRegistry; | ||
| 30 | +import org.onosproject.incubator.net.faultmanagement.alarm.DefaultAlarm; | ||
| 31 | +import org.onosproject.net.DeviceId; | ||
| 32 | +import org.onosproject.net.provider.AbstractProvider; | ||
| 33 | +import org.onosproject.net.provider.ProviderId; | ||
| 34 | +import org.onosproject.netconf.NetconfController; | ||
| 35 | +import org.onosproject.netconf.NetconfDevice; | ||
| 36 | +import org.onosproject.netconf.NetconfDeviceInfo; | ||
| 37 | +import org.onosproject.netconf.NetconfDeviceListener; | ||
| 38 | +import org.onosproject.netconf.NetconfDeviceOutputEvent; | ||
| 39 | +import org.onosproject.netconf.NetconfDeviceOutputEventListener; | ||
| 40 | +import org.onosproject.netconf.NetconfSession; | ||
| 41 | +import org.onosproject.netconf.ctl.NetconfDeviceOutputEventListenerImpl; | ||
| 42 | +import org.slf4j.Logger; | ||
| 43 | + | ||
| 44 | +import java.util.Collection; | ||
| 45 | +import java.util.Collections; | ||
| 46 | +import java.util.Map; | ||
| 47 | + | ||
| 48 | +import static org.slf4j.LoggerFactory.getLogger; | ||
| 49 | + | ||
| 50 | +/** | ||
| 51 | + * Provider which uses an Alarm Manager to keep track of device notifications. | ||
| 52 | + */ | ||
| 53 | +@Component(immediate = true) | ||
| 54 | +public class NetconfAlarmProvider extends AbstractProvider implements AlarmProvider { | ||
| 55 | + | ||
| 56 | + public static final String ACTIVE = "active"; | ||
| 57 | + private final Logger log = getLogger(getClass()); | ||
| 58 | + | ||
| 59 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 60 | + protected AlarmProviderRegistry providerRegistry; | ||
| 61 | + | ||
| 62 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 63 | + protected NetconfController controller; | ||
| 64 | + | ||
| 65 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 66 | + protected AlarmService alarmService; | ||
| 67 | + | ||
| 68 | + protected AlarmProviderService providerService; | ||
| 69 | + | ||
| 70 | + private Map<DeviceId, InternalNotificationListener> idNotificationListenerMap = Maps.newHashMap(); | ||
| 71 | + | ||
| 72 | + public NetconfAlarmProvider() { | ||
| 73 | + super(new ProviderId("netconf", "org.onosproject.netconf")); | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + private NetconfDeviceListener deviceListener = new InnerDeviceListener(); | ||
| 77 | + | ||
| 78 | + @Activate | ||
| 79 | + public void activate() { | ||
| 80 | + providerService = providerRegistry.register(this); | ||
| 81 | + controller.getNetconfDevices().forEach(id -> { | ||
| 82 | + NetconfDevice device = controller.getNetconfDevice(id); | ||
| 83 | + NetconfSession session = device.getSession(); | ||
| 84 | + InternalNotificationListener listener = new InternalNotificationListener(device.getDeviceInfo()); | ||
| 85 | + session.addDeviceOutputListener(listener); | ||
| 86 | + idNotificationListenerMap.put(id, listener); | ||
| 87 | + }); | ||
| 88 | + controller.addDeviceListener(deviceListener); | ||
| 89 | + log.info("NetconfAlarmProvider Started"); | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + @Deactivate | ||
| 93 | + public void deactivate() { | ||
| 94 | + providerRegistry.unregister(this); | ||
| 95 | + idNotificationListenerMap.forEach((id, listener) -> { | ||
| 96 | + controller.getNetconfDevice(id) | ||
| 97 | + .getSession() | ||
| 98 | + .removeDeviceOutputListener(listener); | ||
| 99 | + }); | ||
| 100 | + controller.removeDeviceListener(deviceListener); | ||
| 101 | + providerService = null; | ||
| 102 | + log.info("NetconfAlarmProvider Stopped"); | ||
| 103 | + } | ||
| 104 | + | ||
| 105 | + @Override | ||
| 106 | + public void triggerProbe(DeviceId deviceId) { | ||
| 107 | + log.debug("Alarm probe triggered with " + deviceId); | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + private void triggerProbe(DeviceId deviceId, Collection<Alarm> alarms) { | ||
| 111 | + providerService.updateAlarmList(deviceId, alarms); | ||
| 112 | + triggerProbe(deviceId); | ||
| 113 | + } | ||
| 114 | + | ||
| 115 | + private class InternalNotificationListener extends NetconfDeviceOutputEventListenerImpl | ||
| 116 | + implements NetconfDeviceOutputEventListener { | ||
| 117 | + | ||
| 118 | + InternalNotificationListener(NetconfDeviceInfo deviceInfo) { | ||
| 119 | + super(deviceInfo); | ||
| 120 | + } | ||
| 121 | + | ||
| 122 | + @Override | ||
| 123 | + public void event(NetconfDeviceOutputEvent event) { | ||
| 124 | + if (event.type() == NetconfDeviceOutputEvent.Type.DEVICE_NOTIFICATION) { | ||
| 125 | + DeviceId deviceId = event.getDeviceInfo().getDeviceId(); | ||
| 126 | + Alarm newAlarm = new DefaultAlarm.Builder(deviceId, event.getMessagePayload(), | ||
| 127 | + Alarm.SeverityLevel.WARNING, 0).build(); | ||
| 128 | + Collection<Alarm> alarms = Collections.singleton(newAlarm); | ||
| 129 | + triggerProbe(deviceId, alarms); | ||
| 130 | + } | ||
| 131 | + } | ||
| 132 | + } | ||
| 133 | + | ||
| 134 | + private class InnerDeviceListener implements NetconfDeviceListener { | ||
| 135 | + | ||
| 136 | + @Override | ||
| 137 | + public void deviceAdded(DeviceId deviceId) { | ||
| 138 | + NetconfDevice device = controller.getNetconfDevice(deviceId); | ||
| 139 | + NetconfSession session = device.getSession(); | ||
| 140 | + InternalNotificationListener listener = new InternalNotificationListener(device.getDeviceInfo()); | ||
| 141 | + session.addDeviceOutputListener(listener); | ||
| 142 | + idNotificationListenerMap.put(deviceId, listener); | ||
| 143 | + } | ||
| 144 | + | ||
| 145 | + @Override | ||
| 146 | + public void deviceRemoved(DeviceId deviceId) { | ||
| 147 | + idNotificationListenerMap.remove(deviceId); | ||
| 148 | + } | ||
| 149 | + } | ||
| 150 | +} |
providers/netconf/alarm/src/main/java/org/onosproject/provider/netconf/alarm/package-info.java
0 → 100644
| 1 | +/* | ||
| 2 | + * Copyright 2016-present 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 uses Netconf device output listener capability to send | ||
| 19 | + * appropriate alarms to the alarm manager. | ||
| 20 | + */ | ||
| 21 | +package org.onosproject.provider.netconf.alarm; | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| ... | @@ -17,11 +17,13 @@ | ... | @@ -17,11 +17,13 @@ |
| 17 | <app name="org.onosproject.netconf" origin="ON.Lab" version="${project.version}" | 17 | <app name="org.onosproject.netconf" origin="ON.Lab" version="${project.version}" |
| 18 | category="Provider" url="https://wiki.onosproject.org/display/ONOS/NETCONF" title="NETCONF Provider" | 18 | category="Provider" url="https://wiki.onosproject.org/display/ONOS/NETCONF" title="NETCONF Provider" |
| 19 | featuresRepo="mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features" | 19 | featuresRepo="mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features" |
| 20 | + apps="org.onosproject.faultmanagement" | ||
| 20 | features="${project.artifactId}"> | 21 | features="${project.artifactId}"> |
| 21 | <description>${project.description}</description> | 22 | <description>${project.description}</description> |
| 22 | <artifact>mvn:${project.groupId}/onos-netconf-api/${project.version}</artifact> | 23 | <artifact>mvn:${project.groupId}/onos-netconf-api/${project.version}</artifact> |
| 23 | <artifact>mvn:${project.groupId}/onos-netconf-ctl/${project.version}</artifact> | 24 | <artifact>mvn:${project.groupId}/onos-netconf-ctl/${project.version}</artifact> |
| 24 | 25 | ||
| 25 | <artifact>mvn:${project.groupId}/onos-netconf-provider-device/${project.version}</artifact> | 26 | <artifact>mvn:${project.groupId}/onos-netconf-provider-device/${project.version}</artifact> |
| 27 | + <artifact>mvn:${project.groupId}/onos-netconf-provider-alarm/${project.version}</artifact> | ||
| 26 | 28 | ||
| 27 | </app> | 29 | </app> | ... | ... |
| ... | @@ -23,6 +23,7 @@ | ... | @@ -23,6 +23,7 @@ |
| 23 | <bundle>mvn:${project.groupId}/onos-netconf-ctl/${project.version}</bundle> | 23 | <bundle>mvn:${project.groupId}/onos-netconf-ctl/${project.version}</bundle> |
| 24 | 24 | ||
| 25 | <bundle>mvn:${project.groupId}/onos-netconf-provider-device/${project.version}</bundle> | 25 | <bundle>mvn:${project.groupId}/onos-netconf-provider-device/${project.version}</bundle> |
| 26 | + <bundle>mvn:${project.groupId}/onos-netconf-provider-alarm/${project.version}</bundle> | ||
| 26 | </feature> | 27 | </feature> |
| 27 | </features> | 28 | </features> |
| 28 | 29 | ... | ... |
| ... | @@ -16,7 +16,7 @@ | ... | @@ -16,7 +16,7 @@ |
| 16 | --> | 16 | --> |
| 17 | <project xmlns="http://maven.apache.org/POM/4.0.0" | 17 | <project xmlns="http://maven.apache.org/POM/4.0.0" |
| 18 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | 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"> | 19 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-4_0_0.xsd"> |
| 20 | <modelVersion>4.0.0</modelVersion> | 20 | <modelVersion>4.0.0</modelVersion> |
| 21 | 21 | ||
| 22 | <parent> | 22 | <parent> |
| ... | @@ -26,7 +26,19 @@ | ... | @@ -26,7 +26,19 @@ |
| 26 | </parent> | 26 | </parent> |
| 27 | 27 | ||
| 28 | <artifactId>onos-netconf-app</artifactId> | 28 | <artifactId>onos-netconf-app</artifactId> |
| 29 | - <packaging>pom</packaging> | 29 | + <packaging>bundle</packaging> |
| 30 | + | ||
| 31 | + <properties> | ||
| 32 | + <onos.app.name>org.onosproject.netconf</onos.app.name> | ||
| 33 | + <onos.app.title>Netconf Meta App</onos.app.title> | ||
| 34 | + <onos.app.category>Provider</onos.app.category> | ||
| 35 | + <onos.app.requires> | ||
| 36 | + org.onosproject.incubator.net.faultmanagement | ||
| 37 | + </onos.app.requires> | ||
| 38 | + <onos.app.url> | ||
| 39 | + https://wiki.onosproject.org/display/ONOS/Application+Subsystem | ||
| 40 | + </onos.app.url> | ||
| 41 | + </properties> | ||
| 30 | 42 | ||
| 31 | <description>NETCONF protocol southbound providers</description> | 43 | <description>NETCONF protocol southbound providers</description> |
| 32 | 44 | ||
| ... | @@ -36,6 +48,11 @@ | ... | @@ -36,6 +48,11 @@ |
| 36 | <artifactId>onos-netconf-provider-device</artifactId> | 48 | <artifactId>onos-netconf-provider-device</artifactId> |
| 37 | <version>${project.version}</version> | 49 | <version>${project.version}</version> |
| 38 | </dependency> | 50 | </dependency> |
| 51 | + <dependency> | ||
| 52 | + <groupId>org.onosproject</groupId> | ||
| 53 | + <artifactId>onos-netconf-provider-alarm</artifactId> | ||
| 54 | + <version>${project.version}</version> | ||
| 55 | + </dependency> | ||
| 39 | <!-- Add other dependencies here as more bundles are added to the app --> | 56 | <!-- Add other dependencies here as more bundles are added to the app --> |
| 40 | 57 | ||
| 41 | </dependencies> | 58 | </dependencies> | ... | ... |
| ... | @@ -302,8 +302,6 @@ public class NetconfDeviceProvider extends AbstractProvider | ... | @@ -302,8 +302,6 @@ public class NetconfDeviceProvider extends AbstractProvider |
| 302 | DeviceKeyId.deviceKeyId(deviceId.toString()), | 302 | DeviceKeyId.deviceKeyId(deviceId.toString()), |
| 303 | null, addr.name(), addr.password())); | 303 | null, addr.name(), addr.password())); |
| 304 | providerService.deviceConnected(deviceId, deviceDescription); | 304 | providerService.deviceConnected(deviceId, deviceDescription); |
| 305 | - | ||
| 306 | - | ||
| 307 | }); | 305 | }); |
| 308 | } catch (ConfigException e) { | 306 | } catch (ConfigException e) { |
| 309 | log.error("Cannot read config error " + e); | 307 | log.error("Cannot read config error " + e); | ... | ... |
-
Please register or login to post a comment