Search in sources :

Example 1 with Notify

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Notify in project openflowplugin by opendaylight.

the class ConnectionManagerImplTest method testOnSwitchConnected2.

/**
 * Test method for
 * {@link org.opendaylight.openflowplugin.impl.connection.ConnectionManagerImpl#onSwitchConnected(
 * org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter)}.
 * invoking onHelloMessage, scenario:
 * <ol>
 * <li>receive hello from device (notification)</li>
 * <li>send hello to device (rpc with void output)</li>
 * <li>send getFeature to device (rpc with getFeatureOutput)</li>
 * <li>wait for rpc to finish with getFeatureOutput</li>
 * </ol>
 *
 * @throws InterruptedException - interrupted exception
 */
@Test
public void testOnSwitchConnected2() throws Exception {
    connectionManagerImpl.onSwitchConnected(connection);
    Mockito.verify(connection).setConnectionReadyListener(connectionReadyListenerAC.capture());
    Mockito.verify(connection).setMessageListener(ofpListenerAC.capture());
    // prepare void reply (hello rpc output)
    final SettableFuture<RpcResult<Void>> voidResponseFx = SettableFuture.<RpcResult<Void>>create();
    Mockito.when(connection.hello(Matchers.any(HelloInput.class))).thenReturn(voidResponseFx);
    // prepare getFeature reply (getFeture rpc output)
    final SettableFuture<RpcResult<GetFeaturesOutput>> featureResponseFx = SettableFuture.<RpcResult<GetFeaturesOutput>>create();
    Mockito.when(connection.getFeatures(Matchers.any(GetFeaturesInput.class))).thenReturn(featureResponseFx);
    // fire handshake - send hello reply
    final HelloMessage hello = new HelloMessageBuilder().setVersion(OFConstants.OFP_VERSION_1_3).setXid(1L).build();
    ofpListenerAC.getValue().onHelloMessage(hello);
    // notify about connection ready
    connectionReadyListenerAC.getValue().onConnectionReady();
    // deliver hello send output (void)
    Thread.sleep(100L);
    final RpcResult<Void> helloResponse = RpcResultBuilder.success((Void) null).build();
    voidResponseFx.set(helloResponse);
    // deliver getFeature output
    Thread.sleep(100L);
    final GetFeaturesOutput getFeatureOutput = new GetFeaturesOutputBuilder().setDatapathId(BigInteger.TEN).setVersion(OFConstants.OFP_VERSION_1_3).setXid(2L).setTables((short) 15).build();
    final RpcResult<GetFeaturesOutput> rpcFeaturesOutput = RpcResultBuilder.success(getFeatureOutput).build();
    featureResponseFx.set(rpcFeaturesOutput);
    Mockito.verify(deviceConnectedHandler, Mockito.timeout(FINAL_STEP_TIMEOUT)).deviceConnected(Matchers.any(ConnectionContext.class));
}
Also used : GetFeaturesOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutputBuilder) GetFeaturesInput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesInput) HelloMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessage) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) HelloInput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInput) GetFeaturesOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput) HelloMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessageBuilder) ConnectionContext(org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext) Test(org.junit.Test)

Example 2 with Notify

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Notify in project cxf by apache.

the class JmsPullPoint method getMessages.

@Override
protected List<NotificationMessageHolderType> getMessages(int max) throws ResourceUnknownFault, UnableToGetMessagesFault {
    try {
        if (max == 0) {
            max = 256;
        }
        initSession();
        List<NotificationMessageHolderType> messages = new ArrayList<>();
        for (int i = 0; i < max; i++) {
            final Message msg;
            synchronized (consumerSession) {
                msg = consumer.receiveNoWait();
            }
            if (msg == null) {
                break;
            }
            TextMessage txtMsg = (TextMessage) msg;
            StringReader reader = new StringReader(txtMsg.getText());
            XMLStreamReader xreader = StaxUtils.createXMLStreamReader(reader);
            Notify notify = (Notify) jaxbContext.createUnmarshaller().unmarshal(xreader);
            try {
                xreader.close();
            } catch (XMLStreamException e) {
            // ignoreable
            }
            messages.addAll(notify.getNotificationMessage());
        }
        return messages;
    } catch (JMSException e) {
        LOGGER.log(Level.INFO, "Error retrieving messages", e);
        closeSession();
        UnableToGetMessagesFaultType fault = new UnableToGetMessagesFaultType();
        throw new UnableToGetMessagesFault("Unable to retrieve messages", fault, e);
    } catch (JAXBException e) {
        LOGGER.log(Level.INFO, "Error retrieving messages", e);
        UnableToGetMessagesFaultType fault = new UnableToGetMessagesFaultType();
        throw new UnableToGetMessagesFault("Unable to retrieve messages", fault, e);
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) Notify(org.oasis_open.docs.wsn.b_2.Notify) JAXBException(javax.xml.bind.JAXBException) ArrayList(java.util.ArrayList) JMSException(javax.jms.JMSException) NotificationMessageHolderType(org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType) AbstractPullPoint(org.apache.cxf.wsn.AbstractPullPoint) UnableToGetMessagesFaultType(org.oasis_open.docs.wsn.b_2.UnableToGetMessagesFaultType) XMLStreamException(javax.xml.stream.XMLStreamException) StringReader(java.io.StringReader) UnableToGetMessagesFault(org.oasis_open.docs.wsn.bw_2.UnableToGetMessagesFault) TextMessage(javax.jms.TextMessage)

Example 3 with Notify

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Notify in project cxf by apache.

the class NotificationBroker method notify.

public void notify(Referencable publisher, String topic, Object msg) {
    getBroker();
    if (this.context != null) {
        try {
            DOMResult result = new DOMResult();
            context.createMarshaller().marshal(msg, result);
            msg = result.getNode();
            if (msg instanceof Document) {
                msg = ((Document) msg).getDocumentElement();
            }
        } catch (JAXBException e) {
        // ignore, we'll try and let the runtime handle it as is
        }
    }
    Notify notify = new Notify();
    NotificationMessageHolderType holder = new NotificationMessageHolderType();
    if (publisher != null) {
        holder.setProducerReference(publisher.getEpr());
    }
    if (topic != null) {
        TopicExpressionType topicExp = new TopicExpressionType();
        topicExp.getContent().add(topic);
        holder.setTopic(topicExp);
    }
    holder.setMessage(new NotificationMessageHolderType.Message());
    holder.getMessage().setAny(msg);
    notify.getNotificationMessage().add(holder);
    getBroker().notify(notify);
}
Also used : DOMResult(javax.xml.transform.dom.DOMResult) Notify(org.oasis_open.docs.wsn.b_2.Notify) TopicExpressionType(org.oasis_open.docs.wsn.b_2.TopicExpressionType) JAXBException(javax.xml.bind.JAXBException) Document(org.w3c.dom.Document) NotificationMessageHolderType(org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType)

Example 4 with Notify

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Notify in project cxf by apache.

the class JmsSubscription method onMessage.

public void onMessage(Message jmsMessage) {
    try {
        TextMessage text = (TextMessage) jmsMessage;
        XMLStreamReader reader = StaxUtils.createXMLStreamReader(new StringReader(text.getText()));
        Notify notify = (Notify) jaxbContext.createUnmarshaller().unmarshal(reader);
        reader.close();
        for (Iterator<NotificationMessageHolderType> ith = notify.getNotificationMessage().iterator(); ith.hasNext(); ) {
            NotificationMessageHolderType h = ith.next();
            Object content = h.getMessage().getAny();
            if (!(content instanceof Element)) {
                DocumentFragment doc = DOMUtils.getEmptyDocument().createDocumentFragment();
                jaxbContext.createMarshaller().marshal(content, doc);
                content = DOMUtils.getFirstElement(doc);
            }
            if (!doFilter((Element) content)) {
                ith.remove();
            } else {
                h.setTopic(topic);
                h.setSubscriptionReference(getEpr());
            }
        }
        if (!notify.getNotificationMessage().isEmpty()) {
            doNotify(notify);
        }
    } catch (Exception e) {
        LOGGER.log(Level.WARNING, "Error notifying consumer", e);
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) Notify(org.oasis_open.docs.wsn.b_2.Notify) Element(org.w3c.dom.Element) StringReader(java.io.StringReader) NotificationMessageHolderType(org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType) TextMessage(javax.jms.TextMessage) DocumentFragment(org.w3c.dom.DocumentFragment) XPathExpressionException(javax.xml.xpath.XPathExpressionException) JMSException(javax.jms.JMSException) JAXBException(javax.xml.bind.JAXBException)

Example 5 with Notify

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Notify in project netvirt by opendaylight.

the class AclInterfaceStateListener method add.

@Override
public void add(InstanceIdentifier<Interface> key, Interface added) {
    if (!L2vlan.class.equals(added.getType())) {
        return;
    }
    if (aclInterfaceCache.get(added.getName()) == null) {
        org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface iface = interfaceManager.getInterfaceInfoFromConfigDataStore(added.getName());
        if (iface == null) {
            LOG.error("No interface with name {} available in interfaceConfig, servicing interfaceState ADD" + "for ACL failed", added.getName());
            return;
        }
        InterfaceAcl aclInPort = iface.augmentation(InterfaceAcl.class);
        if (aclInPort == null) {
            LOG.trace("Interface {} is not an ACL Interface, ignoring ADD interfaceState event", added.getName());
            return;
        }
        aclInterfaceCache.addOrUpdate(added.getName(), (prevAclInterface, builder) -> {
            builder.portSecurityEnabled(aclInPort.isPortSecurityEnabled()).interfaceType(aclInPort.getInterfaceType()).securityGroups(aclInPort.getSecurityGroups()).allowedAddressPairs(new ArrayList<AllowedAddressPairs>(aclInPort.nonnullAllowedAddressPairs().values())).subnetInfo(new ArrayList<SubnetInfo>(aclInPort.nonnullSubnetInfo().values()));
        });
    }
    AclInterface aclInterface = aclInterfaceCache.addOrUpdate(added.getName(), (prevAclInterface, builder) -> {
        builder.dpId(AclServiceUtils.getDpIdFromIterfaceState(added)).lPortTag(added.getIfIndex()).isMarkedForDelete(false);
        if (AclServiceUtils.isOfInterest(prevAclInterface)) {
            SortedSet<Integer> ingressRemoteAclTags = aclServiceUtils.getRemoteAclTags(prevAclInterface.getSecurityGroups(), DirectionIngress.class);
            SortedSet<Integer> egressRemoteAclTags = aclServiceUtils.getRemoteAclTags(prevAclInterface.getSecurityGroups(), DirectionEgress.class);
            builder.ingressRemoteAclTags(ingressRemoteAclTags).egressRemoteAclTags(egressRemoteAclTags);
        }
    });
    if (AclServiceUtils.isOfInterest(aclInterface)) {
        List<Uuid> aclList = aclInterface.getSecurityGroups();
        if (aclList != null) {
            aclDataUtil.addOrUpdateAclInterfaceMap(aclList, aclInterface);
        }
        if (aclInterface.getElanId() == null) {
            LOG.debug("On Add event, skip ADD since ElanId is not updated");
            return;
        }
        if (aclClusterUtil.isEntityOwner()) {
            LOG.debug("On add event, notify ACL service manager to add ACL for interface: {}", aclInterface);
            aclServiceManger.notify(aclInterface, null, Action.BIND);
            if (aclList != null) {
                aclServiceUtils.addAclPortsLookup(aclInterface, aclList, aclInterface.getAllowedAddressPairs());
            }
            aclServiceManger.notify(aclInterface, null, Action.ADD);
        }
    }
}
Also used : AclInterface(org.opendaylight.netvirt.aclservice.api.utils.AclInterface) L2vlan(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev170119.L2vlan) ArrayList(java.util.ArrayList) InterfaceAcl(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.InterfaceAcl) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) SubnetInfo(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.interfaces._interface.SubnetInfo)

Aggregations

Test (org.junit.Test)16 Notify (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Notify)12 MapNotify (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapNotify)8 Notification (org.opendaylight.yangtools.yang.binding.Notification)6 ArrayList (java.util.ArrayList)5 JAXBException (javax.xml.bind.JAXBException)5 Notify (org.oasis_open.docs.wsn.b_2.Notify)5 Open (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Open)5 JMSException (javax.jms.JMSException)4 AclInterface (org.opendaylight.netvirt.aclservice.api.utils.AclInterface)4 MappingRecord (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord)4 Message (javax.jms.Message)3 TextMessage (javax.jms.TextMessage)3 NotificationMessageHolderType (org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType)3 BGPDocumentedException (org.opendaylight.protocol.bgp.parser.BGPDocumentedException)3 Ipv4AddressNoZone (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone)3 OpenBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.OpenBuilder)3 Optional (com.google.common.base.Optional)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 ByteBuf (io.netty.buffer.ByteBuf)2