+++ /dev/null
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.protocol.bgp.parser;
-
-
-/**
- * Basic structure for BGP Message. There is not other common feature than the serialization.
- */
-@Deprecated
-public interface BGPMessage {
-
-}
package org.opendaylight.protocol.bgp.parser;
import org.opendaylight.protocol.framework.ProtocolMessageFactory;
+import org.opendaylight.yangtools.yang.binding.Notification;
/**
* Interface to expose BGP specific MessageFactory.
*/
-public interface BGPMessageFactory extends ProtocolMessageFactory<BGPMessage> {
+public interface BGPMessageFactory extends ProtocolMessageFactory<Notification> {
}
import org.opendaylight.protocol.bgp.concepts.BGPTableType;
import org.opendaylight.protocol.framework.ProtocolSession;
+import org.opendaylight.yangtools.yang.binding.Notification;
/**
* BGP Session represents the finite state machine in BGP, including timers and its purpose is to create a BGP
*
* If the session is up, it has to redirect messages to/from user. Handles also malformed messages and unknown requests.
*/
-public interface BGPSession extends ProtocolSession<BGPMessage> {
+public interface BGPSession extends ProtocolSession<Notification> {
public Set<BGPTableType> getAdvertisedTableTypes();
}
package org.opendaylight.protocol.bgp.parser;
import org.opendaylight.protocol.framework.SessionListener;
+import org.opendaylight.yangtools.yang.binding.Notification;
/**
* Listener that receives session informations from the session.
*/
-public interface BGPSessionListener extends SessionListener<BGPMessage, BGPSession, BGPTerminationReason> {
+public interface BGPSessionListener extends SessionListener<Notification, BGPSession, BGPTerminationReason> {
}
*/
package org.opendaylight.protocol.bgp.parser;
+import org.opendaylight.yangtools.yang.binding.Notification;
+
/**
* Marker interface for events resulting from parsing of an BGP UPDATE message. An unfortunate twist in BGP spec makes
* use of a specially-crafted message to indicate that a per-AFI RIB has been completely synchronized.
*
* Extends ProtocolMessage to allow parsing of BGP Update Messages in BGP listener.
*/
-public interface BGPUpdateEvent extends BGPMessage {
+public interface BGPUpdateEvent extends Notification {
}
import java.util.Set;
import org.opendaylight.protocol.bgp.concepts.BGPObject;
-
+import org.opendaylight.yangtools.yang.binding.Notification;
/**
*
* kind of situation. Therefore, first step is to remove objects, then add the other set.
*
*/
-public interface BGPUpdateMessage extends BGPUpdateEvent, BGPMessage {
+public interface BGPUpdateMessage extends BGPUpdateEvent, Notification {
/**
* Objects that are identified with Identifiers in this set, need to be removed from topology.
*
*/
package org.opendaylight.protocol.bgp.parser.message;
-import org.opendaylight.protocol.bgp.parser.BGPMessage;
+import org.opendaylight.yangtools.yang.binding.Notification;
/**
* BGP KeepAlive message. Always empty.
*
* @see <a href="http://tools.ietf.org/html/rfc4271#section-4.4">BGP KeepAlive message</a>
*/
-public final class BGPKeepAliveMessage implements BGPMessage {
-
- private static final long serialVersionUID = 5469664138660829255L;
+public final class BGPKeepAliveMessage implements Notification {
/**
* Creates a BGP KeepAlive message.
import java.util.Arrays;
import org.opendaylight.protocol.bgp.parser.BGPError;
-import org.opendaylight.protocol.bgp.parser.BGPMessage;
-
+import org.opendaylight.yangtools.yang.binding.Notification;
/**
* Representation of BGPNotification message.
*
* @see <a link="http://tools.ietf.org/html/rfc4271#section-4.5">BGP Notification Message</a>
*/
-public final class BGPNotificationMessage implements BGPMessage {
-
- private static final long serialVersionUID = -5860147919167775673L;
+public final class BGPNotificationMessage implements Notification {
private final BGPError error;
import java.util.List;
-import org.opendaylight.protocol.bgp.parser.BGPMessage;
import org.opendaylight.protocol.bgp.parser.BGPParameter;
import org.opendaylight.protocol.concepts.IPv4Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
+import org.opendaylight.yangtools.yang.binding.Notification;
/**
* Representation of BGPOpen message.
*
* @see <a href="http://tools.ietf.org/html/rfc4271#section-4.2">BGP Open Message</a>
*/
-public final class BGPOpenMessage implements BGPMessage {
-
- private static final long serialVersionUID = -3507481736478860117L;
+public final class BGPOpenMessage implements Notification {
/**
* Current BGP version.
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.ExtendedCommunity;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.CIpv4NextHopBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.c.ipv4.next.hop.Ipv4NextHopBuilder;
+import org.opendaylight.yangtools.yang.binding.Notification;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
@Test
public void testBGPKeepAliveMessage() {
- final BGPMessage msg = new BGPKeepAliveMessage();
+ final Notification msg = new BGPKeepAliveMessage();
assertTrue(msg instanceof BGPKeepAliveMessage);
}
@Test
public void testBGPNotificationMessage() {
- final BGPMessage msg = new BGPNotificationMessage(BGPError.AS_PATH_MALFORMED);
+ final Notification msg = new BGPNotificationMessage(BGPError.AS_PATH_MALFORMED);
assertTrue(msg instanceof BGPNotificationMessage);
assertEquals(BGPError.AS_PATH_MALFORMED, ((BGPNotificationMessage) msg).getError());
assertNull(((BGPNotificationMessage) msg).getData());
@Test
public void testBGPOpenMessage() {
- final BGPMessage msg = new BGPOpenMessage(new AsNumber((long) 58), (short) 5, null, null);
+ final Notification msg = new BGPOpenMessage(new AsNumber((long) 58), (short) 5, null, null);
assertNull(((BGPOpenMessage) msg).getOptParams());
}
@Test
public void testToString() {
- final BGPMessage o = new BGPOpenMessage(new AsNumber((long) 58), (short) 5, null, null);
- final BGPMessage n = new BGPNotificationMessage(BGPError.ATTR_FLAGS_MISSING);
+ final Notification o = new BGPOpenMessage(new AsNumber((long) 58), (short) 5, null, null);
+ final Notification n = new BGPNotificationMessage(BGPError.ATTR_FLAGS_MISSING);
assertNotSame(o.toString(), n.toString());
}
}
import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
import org.opendaylight.protocol.bgp.parser.BGPError;
-import org.opendaylight.protocol.bgp.parser.BGPMessage;
import org.opendaylight.protocol.bgp.parser.BGPMessageFactory;
import org.opendaylight.protocol.bgp.parser.impl.message.BGPNotificationMessageParser;
import org.opendaylight.protocol.bgp.parser.impl.message.BGPOpenMessageParser;
import org.opendaylight.protocol.framework.DeserializerException;
import org.opendaylight.protocol.framework.DocumentedException;
import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.yangtools.yang.binding.Notification;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* @see org.opendaylight.protocol.bgp.parser.BGPMessageParser#parse(byte[])
*/
@Override
- public List<BGPMessage> parse(final byte[] bytes) throws DeserializerException, DocumentedException {
+ public List<Notification> parse(final byte[] bytes) throws DeserializerException, DocumentedException {
if (bytes == null) {
throw new IllegalArgumentException("Array of bytes is mandatory.");
}
logger.debug("Attempt to parse message from bytes: {}", ByteArray.bytesToHexString(msgBody));
- final BGPMessage msg;
+ final Notification msg;
switch (messageType) {
case 1:
}
@Override
- public byte[] put(final BGPMessage msg) {
+ public byte[] put(final Notification msg) {
if (msg == null) {
throw new IllegalArgumentException("BGPMessage is mandatory.");
}
import java.util.List;
import java.util.Map;
-import org.opendaylight.protocol.bgp.parser.BGPMessage;
import org.opendaylight.protocol.framework.DeserializerException;
import org.opendaylight.protocol.framework.DocumentedException;
import org.opendaylight.protocol.framework.ProtocolMessageFactory;
+import org.opendaylight.yangtools.yang.binding.Notification;
/**
* Mock implementation of {@link BGPMessageParser}. It implements the required interface by having two internal maps,
* each used in one of the methods. It looks up the key provided to the method and returns whatever value is stored in
* the map.
*/
-public class BGPMessageParserMock implements ProtocolMessageFactory<BGPMessage> {
- private final Map<byte[], List<BGPMessage>> messages;
+public class BGPMessageParserMock implements ProtocolMessageFactory<Notification> {
+ private final Map<byte[], List<Notification>> messages;
/**
* @param updateMessages Map<byte[], BGPUpdateEvent>
*/
- public BGPMessageParserMock(final Map<byte[], List<BGPMessage>> messages) {
+ public BGPMessageParserMock(final Map<byte[], List<Notification>> messages) {
this.messages = messages;
}
@Override
- public List<BGPMessage> parse(final byte[] bytes) throws DeserializerException, DocumentedException {
- final List<BGPMessage> ret = this.messages.get(bytes);
+ public List<Notification> parse(final byte[] bytes) throws DeserializerException, DocumentedException {
+ final List<Notification> ret = this.messages.get(bytes);
if (ret == null) {
throw new IllegalArgumentException("Undefined message encountered");
}
}
@Override
- public byte[] put(final BGPMessage msg) {
+ public byte[] put(final Notification msg) {
// nothing
return null;
}
import org.opendaylight.protocol.bgp.concepts.BaseBGPObjectState;
import org.opendaylight.protocol.bgp.linkstate.NetworkObjectState;
import org.opendaylight.protocol.bgp.linkstate.NetworkRouteState;
-import org.opendaylight.protocol.bgp.parser.BGPMessage;
import org.opendaylight.protocol.bgp.parser.BGPParameter;
import org.opendaylight.protocol.bgp.parser.BGPRoute;
import org.opendaylight.protocol.bgp.parser.BGPUpdateMessage;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.CNextHop;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.CIpv6NextHopBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.c.ipv6.next.hop.Ipv6NextHopBuilder;
+import org.opendaylight.yangtools.yang.binding.Notification;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
*/
@Test
public void testGetUpdateMessage() throws DeserializerException, DocumentedException, IOException {
- final Map<byte[], List<BGPMessage>> updateMap = Maps.newHashMap();
+ final Map<byte[], List<Notification>> updateMap = Maps.newHashMap();
for (int i = 0; i < this.inputBytes.length; i++) {
- updateMap.put(this.inputBytes[i], Lists.newArrayList((BGPMessage) this.messages.get(i)));
+ updateMap.put(this.inputBytes[i], Lists.newArrayList((Notification) this.messages.get(i)));
}
final BGPMessageParserMock mockParser = new BGPMessageParserMock(updateMap);
*/
@Test(expected = IllegalArgumentException.class)
public void testGetUpdateMessageException() throws DeserializerException, DocumentedException, IOException {
- final Map<byte[], List<BGPMessage>> updateMap = Maps.newHashMap();
+ final Map<byte[], List<Notification>> updateMap = Maps.newHashMap();
for (int i = 0; i < this.inputBytes.length; i++) {
- updateMap.put(this.inputBytes[i], Lists.newArrayList((BGPMessage) this.messages.get(i)));
+ updateMap.put(this.inputBytes[i], Lists.newArrayList((Notification) this.messages.get(i)));
}
final BGPMessageParserMock mockParser = new BGPMessageParserMock(updateMap);
@Test
public void testGetOpenMessage() throws DeserializerException, DocumentedException, IOException {
- final Map<byte[], List<BGPMessage>> openMap = Maps.newHashMap();
+ final Map<byte[], List<Notification>> openMap = Maps.newHashMap();
final Set<BGPTableType> type = Sets.newHashSet();
type.add(new BGPTableType(Ipv4AddressFamily.class, MplsLabeledVpnSubsequentAddressFamily.class));
final byte[] input = new byte[] { 5, 8, 13, 21 };
- openMap.put(input, Lists.newArrayList((BGPMessage) new BGPOpenMessage(new AsNumber((long) 30), (short) 30, null, params)));
+ openMap.put(input, Lists.newArrayList((Notification) new BGPOpenMessage(new AsNumber((long) 30), (short) 30, null, params)));
final BGPMessageParserMock mockParser = new BGPMessageParserMock(openMap);
import io.netty.channel.ChannelHandler;
-import org.opendaylight.protocol.bgp.parser.BGPMessage;
import org.opendaylight.protocol.bgp.parser.BGPMessageFactory;
import org.opendaylight.protocol.framework.ProtocolHandlerFactory;
import org.opendaylight.protocol.framework.ProtocolMessageDecoder;
import org.opendaylight.protocol.framework.ProtocolMessageEncoder;
+import org.opendaylight.yangtools.yang.binding.Notification;
/**
* BGP specific factory for protocol inbound/outbound handlers.
*/
-public class BGPHandlerFactory extends ProtocolHandlerFactory<BGPMessage> {
- private final ProtocolMessageEncoder<BGPMessage> encoder;
+public class BGPHandlerFactory extends ProtocolHandlerFactory<Notification> {
+ private final ProtocolMessageEncoder<Notification> encoder;
public BGPHandlerFactory(final BGPMessageFactory msgFactory) {
super(msgFactory);
- this.encoder = new ProtocolMessageEncoder<BGPMessage>(this.msgFactory);
+ this.encoder = new ProtocolMessageEncoder<Notification>(this.msgFactory);
}
@Override
@Override
public ChannelHandler[] getDecoders() {
- return new ChannelHandler[] { new BGPMessageHeaderDecoder(), new ProtocolMessageDecoder<BGPMessage>(this.msgFactory) };
+ return new ChannelHandler[] { new BGPMessageHeaderDecoder(), new ProtocolMessageDecoder<Notification>(this.msgFactory) };
}
}
import java.util.Set;
import org.opendaylight.protocol.bgp.concepts.BGPTableType;
-import org.opendaylight.protocol.bgp.parser.BGPMessage;
import org.opendaylight.protocol.bgp.parser.BGPSession;
import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
import org.opendaylight.protocol.bgp.parser.BGPTerminationReason;
import org.opendaylight.protocol.bgp.parser.BGPUpdateMessage;
+import org.opendaylight.yangtools.yang.binding.Notification;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
}
@Override
- public void onMessage(final BGPSession session, final BGPMessage message) {
+ public void onMessage(final BGPSession session, final Notification message) {
if (message instanceof BGPUpdateMessage) {
final BGPUpdateMessage m = (BGPUpdateMessage) message;
this.rib.updateTables(this, m.getAddedObjects(), m.getRemovedObjects());
import org.opendaylight.protocol.bgp.concepts.BGPTableType;
import org.opendaylight.protocol.bgp.parser.BGPError;
-import org.opendaylight.protocol.bgp.parser.BGPMessage;
import org.opendaylight.protocol.bgp.parser.BGPParameter;
import org.opendaylight.protocol.bgp.parser.BGPSession;
import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
import org.opendaylight.protocol.bgp.parser.message.BGPOpenMessage;
import org.opendaylight.protocol.bgp.parser.parameter.MultiprotocolCapability;
import org.opendaylight.protocol.framework.AbstractProtocolSession;
+import org.opendaylight.yangtools.yang.binding.Notification;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.collect.Sets;
@VisibleForTesting
-public class BGPSessionImpl extends AbstractProtocolSession<BGPMessage> implements BGPSession {
+public class BGPSessionImpl extends AbstractProtocolSession<Notification> implements BGPSession {
private static final Logger logger = LoggerFactory.getLogger(BGPSessionImpl.class);
*/
public enum State {
/**
- * The session object is created by the negotiator in OpenConfirm state.
- * While in this state, the session object is half-alive, e.g. the timers
- * are running, but the session is not completely up, e.g. it has not been
- * announced to the listener. If the session is torn down in this state,
- * we do not inform the listener.
+ * The session object is created by the negotiator in OpenConfirm state. While in this state, the session object
+ * is half-alive, e.g. the timers are running, but the session is not completely up, e.g. it has not been
+ * announced to the listener. If the session is torn down in this state, we do not inform the listener.
*/
OpenConfirm,
/**
* @param msg incoming message
*/
@Override
- public void handleMessage(final BGPMessage msg) {
+ public void handleMessage(final Notification msg) {
// Update last reception time
this.lastMessageReceivedAt = System.nanoTime();
}
}
- void sendMessage(final BGPMessage msg) {
+ void sendMessage(final Notification msg) {
try {
this.channel.writeAndFlush(msg);
this.lastMessageSentAt = System.nanoTime();
import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
import org.opendaylight.protocol.bgp.parser.BGPError;
-import org.opendaylight.protocol.bgp.parser.BGPMessage;
import org.opendaylight.protocol.bgp.parser.BGPParameter;
import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
import org.opendaylight.protocol.bgp.parser.message.BGPKeepAliveMessage;
import org.opendaylight.protocol.framework.AbstractSessionNegotiator;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateAddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateSubsequentAddressFamily;
+import org.opendaylight.yangtools.yang.binding.Notification;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
-public final class BGPSessionNegotiator extends AbstractSessionNegotiator<BGPMessage, BGPSessionImpl> {
+public final class BGPSessionNegotiator extends AbstractSessionNegotiator<Notification, BGPSessionImpl> {
// 4 minutes recommended in http://tools.ietf.org/html/rfc4271#section-8.2.2
// FIXME to actual value
protected static final int INITIAL_HOLDTIMER = 1;
}
@Override
- protected synchronized void handleMessage(final BGPMessage msg) {
+ protected synchronized void handleMessage(final Notification msg) {
logger.debug("Channel {} handling message in state {}", this.channel, this.state);
switch (this.state) {
import io.netty.util.Timer;
import io.netty.util.concurrent.Promise;
-import org.opendaylight.protocol.bgp.parser.BGPMessage;
import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
import org.opendaylight.protocol.framework.SessionListenerFactory;
import org.opendaylight.protocol.framework.SessionNegotiator;
import org.opendaylight.protocol.framework.SessionNegotiatorFactory;
+import org.opendaylight.yangtools.yang.binding.Notification;
import com.google.common.base.Preconditions;
-public final class BGPSessionNegotiatorFactory implements SessionNegotiatorFactory<BGPMessage, BGPSessionImpl, BGPSessionListener> {
+public final class BGPSessionNegotiatorFactory implements SessionNegotiatorFactory<Notification, BGPSessionImpl, BGPSessionListener> {
private final BGPSessionPreferences initialPrefs;
private final Timer timer;
@Override
public SessionNegotiator<BGPSessionImpl> getSessionNegotiator(final SessionListenerFactory<BGPSessionListener> factory,
final Channel channel, final Promise<BGPSessionImpl> promise) {
- return new BGPSessionNegotiator(timer, promise, channel, initialPrefs, factory.getSessionListener());
+ return new BGPSessionNegotiator(this.timer, promise, channel, this.initialPrefs, factory.getSessionListener());
}
}
import org.mockito.stubbing.Answer;
import org.opendaylight.protocol.bgp.concepts.BGPTableType;
import org.opendaylight.protocol.bgp.parser.BGPError;
-import org.opendaylight.protocol.bgp.parser.BGPMessage;
import org.opendaylight.protocol.bgp.parser.BGPParameter;
import org.opendaylight.protocol.bgp.parser.message.BGPKeepAliveMessage;
import org.opendaylight.protocol.bgp.parser.message.BGPNotificationMessage;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateSubsequentAddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
+import org.opendaylight.yangtools.yang.binding.Notification;
import com.google.common.collect.Lists;
private final BGPTableType linkstatett = new BGPTableType(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class);
- private final List<BGPMessage> receivedMsgs = Lists.newArrayList();
+ private final List<Notification> receivedMsgs = Lists.newArrayList();
private BGPOpenMessage classicOpen;
@Override
public Object answer(final InvocationOnMock invocation) {
final Object[] args = invocation.getArguments();
- FSMTest.this.receivedMsgs.add((BGPMessage) args[0]);
+ FSMTest.this.receivedMsgs.add((Notification) args[0]);
return null;
}
- }).when(this.speakerListener).writeAndFlush(any(BGPMessage.class));
+ }).when(this.speakerListener).writeAndFlush(any(Notification.class));
doReturn("TestingChannel").when(this.speakerListener).toString();
doReturn(this.pipeline).when(this.speakerListener).pipeline();
doReturn(this.pipeline).when(this.pipeline).replace(any(ChannelHandler.class), any(String.class), any(ChannelHandler.class));
this.clientSession.handleMessage(new BGPOpenMessage(new AsNumber((long) 30), (short) 1, null, null));
assertEquals(2, this.receivedMsgs.size());
assertTrue(this.receivedMsgs.get(1) instanceof BGPNotificationMessage);
- final BGPMessage m = this.receivedMsgs.get(this.receivedMsgs.size() - 1);
+ final Notification m = this.receivedMsgs.get(this.receivedMsgs.size() - 1);
assertEquals(BGPError.UNSPECIFIC_OPEN_ERROR, ((BGPNotificationMessage) m).getError());
}
assertTrue(this.receivedMsgs.get(0) instanceof BGPOpenMessage);
Thread.sleep(BGPSessionNegotiator.INITIAL_HOLDTIMER * 1000 * 60);
Thread.sleep(100);
- final BGPMessage m = this.receivedMsgs.get(this.receivedMsgs.size() - 1);
+ final Notification m = this.receivedMsgs.get(this.receivedMsgs.size() - 1);
assertEquals(BGPError.HOLD_TIMER_EXPIRED, ((BGPNotificationMessage) m).getError());
}
import org.opendaylight.protocol.bgp.concepts.BGPTableType;
import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
import org.opendaylight.protocol.bgp.parser.BGPError;
-import org.opendaylight.protocol.bgp.parser.BGPMessage;
import org.opendaylight.protocol.bgp.parser.BGPParameter;
import org.opendaylight.protocol.bgp.parser.impl.BGPMessageFactoryImpl;
import org.opendaylight.protocol.bgp.parser.message.BGPKeepAliveMessage;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateAddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
+import org.opendaylight.yangtools.yang.binding.Notification;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
public class ParserTest {
public static final byte[] openBMsg = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
- (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
- (byte) 0xff, (byte) 0x00, (byte) 0x1d, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x64, (byte) 0x00, (byte) 0xb4,
- (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x00 };
+ (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ (byte) 0xff, (byte) 0x00, (byte) 0x1d, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x64, (byte) 0x00, (byte) 0xb4,
+ (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x00 };
public static final byte[] keepAliveBMsg = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
- (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
- (byte) 0xff, (byte) 0x00, (byte) 0x13, (byte) 0x04 };
+ (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ (byte) 0xff, (byte) 0x00, (byte) 0x13, (byte) 0x04 };
public static final byte[] notificationBMsg = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
- (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
- (byte) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0x17, (byte) 0x03, (byte) 0x02, (byte) 0x04, (byte) 0x04, (byte) 0x09 };
+ (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ (byte) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0x17, (byte) 0x03, (byte) 0x02, (byte) 0x04, (byte) 0x04, (byte) 0x09 };
- final ProtocolMessageFactory<BGPMessage> factory = new BGPMessageFactoryImpl();
+ final ProtocolMessageFactory<Notification> factory = new BGPMessageFactoryImpl();
@Test
public void testHeaderErrors() throws DeserializerException, DocumentedException {
@Test
public void testKeepAliveMsg() throws DeserializerException, DocumentedException {
- final BGPMessage keepAlive = new BGPKeepAliveMessage();
+ final Notification keepAlive = new BGPKeepAliveMessage();
final byte[] bytes = this.factory.put(keepAlive);
assertArrayEquals(keepAliveBMsg, bytes);
- final BGPMessage m = this.factory.parse(bytes).get(0);
+ final Notification m = this.factory.parse(bytes).get(0);
assertTrue(m instanceof BGPKeepAliveMessage);
}
@Test
public void testOpenMessage() throws UnknownHostException, DeserializerException, DocumentedException {
- final BGPMessage open = new BGPOpenMessage(new AsNumber((long) 100), (short) 180, new IPv4Address(InetAddress.getByName("20.20.20.20")), null);
+ final Notification open = new BGPOpenMessage(new AsNumber((long) 100), (short) 180, new IPv4Address(InetAddress.getByName("20.20.20.20")), null);
final byte[] bytes = this.factory.put(open);
assertArrayEquals(openBMsg, bytes);
- final BGPMessage m = this.factory.parse(bytes).get(0);
+ final Notification m = this.factory.parse(bytes).get(0);
assertTrue(m instanceof BGPOpenMessage);
assertEquals(new AsNumber((long) 100), ((BGPOpenMessage) m).getMyAS());
@Test
public void testNotificationMsg() throws DeserializerException, DocumentedException {
- BGPMessage notMsg = new BGPNotificationMessage(BGPError.OPT_PARAM_NOT_SUPPORTED, new byte[] { 4, 9 });
+ Notification notMsg = new BGPNotificationMessage(BGPError.OPT_PARAM_NOT_SUPPORTED, new byte[] { 4, 9 });
byte[] bytes = this.factory.put(notMsg);
assertArrayEquals(notificationBMsg, bytes);
- BGPMessage m = this.factory.parse(bytes).get(0);
+ Notification m = this.factory.parse(bytes).get(0);
assertTrue(m instanceof BGPNotificationMessage);
assertEquals(BGPError.OPT_PARAM_NOT_SUPPORTED, ((BGPNotificationMessage) m).getError());
import java.util.List;
-import org.opendaylight.protocol.bgp.parser.BGPMessage;
import org.opendaylight.protocol.bgp.parser.BGPSession;
import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
import org.opendaylight.protocol.bgp.parser.BGPTerminationReason;
+import org.opendaylight.yangtools.yang.binding.Notification;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
*/
public class SimpleSessionListener implements BGPSessionListener {
- private final List<BGPMessage> listMsg = Lists.newArrayList();
+ private final List<Notification> listMsg = Lists.newArrayList();
public boolean up = false;
public boolean down = false;
- public List<BGPMessage> getListMsg() {
+ public List<Notification> getListMsg() {
return this.listMsg;
}
@Override
- public void onMessage(final BGPSession session, final BGPMessage message) {
+ public void onMessage(final BGPSession session, final Notification message) {
this.listMsg.add(message);
logger.debug("Message received:" + message);
}
import java.util.Set;
import org.opendaylight.protocol.bgp.concepts.BGPTableType;
-import org.opendaylight.protocol.bgp.parser.BGPMessage;
import org.opendaylight.protocol.bgp.parser.BGPSession;
import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
import org.opendaylight.protocol.bgp.parser.BGPTerminationReason;
+import org.opendaylight.yangtools.yang.binding.Notification;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
*/
public class SpeakerSessionListener implements BGPSessionListener {
- public List<BGPMessage> messages = Lists.newArrayList();
+ public List<Notification> messages = Lists.newArrayList();
public boolean up = false;
}
@Override
- public void onMessage(final BGPSession session, final BGPMessage message) {
+ public void onMessage(final BGPSession session, final Notification message) {
logger.debug("Received message: " + message.getClass() + " " + message);
this.messages.add(message);
}
import io.netty.channel.Channel;
import io.netty.util.HashedWheelTimer;
-import org.opendaylight.protocol.bgp.parser.BGPMessage;
import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
import org.opendaylight.protocol.bgp.parser.message.BGPOpenMessage;
+import org.opendaylight.yangtools.yang.binding.Notification;
/**
* Mock of the BGP speakers session.
}
@Override
- public void sendMessage(final BGPMessage msg) {
+ public void sendMessage(final Notification msg) {
this.lastMessageSentAt = System.nanoTime();
this.client.onMessage(this, msg);
}
import javax.annotation.concurrent.ThreadSafe;
import org.opendaylight.protocol.bgp.parser.BGPError;
-import org.opendaylight.protocol.bgp.parser.BGPMessage;
import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
import org.opendaylight.protocol.bgp.parser.impl.BGPMessageFactoryImpl;
import org.opendaylight.protocol.bgp.parser.message.BGPNotificationMessage;
import org.opendaylight.protocol.framework.ProtocolMessageFactory;
import org.opendaylight.protocol.framework.ReconnectStrategy;
import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.yangtools.yang.binding.Notification;
import com.google.common.collect.Lists;
import com.google.common.eventbus.EventBus;
*/
@ThreadSafe
public final class BGPMock implements BGP, Closeable {
- static final BGPMessage connectionLostMagicMessage = new BGPNotificationMessage(BGPError.CEASE);
+ static final Notification connectionLostMagicMessage = new BGPNotificationMessage(BGPError.CEASE);
@GuardedBy("this")
private final List<byte[]> allPreviousByteMessages;
- private final List<BGPMessage> allPreviousBGPMessages;
+ private final List<Notification> allPreviousBGPMessages;
private final EventBus eventBus;
@GuardedBy("this")
private final List<EventBusRegistration> openRegistrations = Lists.newLinkedList();
this.allPreviousBGPMessages = this.parsePrevious(this.allPreviousByteMessages);
}
- private List<BGPMessage> parsePrevious(final List<byte[]> msgs) {
- final List<BGPMessage> messages = Lists.newArrayList();
- final ProtocolMessageFactory<BGPMessage> parser = new BGPMessageFactoryImpl();
+ private List<Notification> parsePrevious(final List<byte[]> msgs) {
+ final List<Notification> messages = Lists.newArrayList();
+ final ProtocolMessageFactory<Notification> parser = new BGPMessageFactoryImpl();
try {
for (final byte[] b : msgs) {
* @return ListenerRegistration
*/
@Override
- public synchronized ListenerRegistration<BGPSessionListener> registerUpdateListener(final BGPSessionListener listener, final ReconnectStrategy strategy) {
+ public synchronized ListenerRegistration<BGPSessionListener> registerUpdateListener(final BGPSessionListener listener,
+ final ReconnectStrategy strategy) {
return EventBusRegistration.createAndRegister(this.eventBus, listener, this.allPreviousBGPMessages);
}
this.insertMessage(connectionLostMagicMessage);
}
- public synchronized void insertMessages(final List<BGPMessage> messages) {
- for (final BGPMessage message : messages) {
+ public synchronized void insertMessages(final List<Notification> messages) {
+ for (final Notification message : messages) {
this.insertMessage(message);
}
}
- private synchronized void insertMessage(final BGPMessage message) {
+ private synchronized void insertMessage(final Notification message) {
this.allPreviousBGPMessages.add(message);
this.eventBus.post(message);
}
import javax.annotation.concurrent.GuardedBy;
import org.opendaylight.protocol.bgp.concepts.BGPTableType;
-import org.opendaylight.protocol.bgp.parser.BGPMessage;
import org.opendaylight.protocol.bgp.parser.BGPParameter;
import org.opendaylight.protocol.bgp.parser.BGPSession;
import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
import org.opendaylight.protocol.bgp.parser.message.BGPOpenMessage;
import org.opendaylight.protocol.bgp.parser.parameter.MultiprotocolCapability;
import org.opendaylight.protocol.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.binding.Notification;
import com.google.common.collect.Sets;
import com.google.common.eventbus.EventBus;
private boolean closed = false;
public static EventBusRegistration createAndRegister(final EventBus eventBus, final BGPSessionListener listener,
- final List<BGPMessage> allPreviousMessages) {
+ final List<Notification> allPreviousMessages) {
final EventBusRegistration instance = new EventBusRegistration(eventBus, listener, allPreviousMessages);
eventBus.register(instance);
return instance;
}
- private EventBusRegistration(final EventBus eventBus, final BGPSessionListener listener, final List<BGPMessage> allPreviousMessages) {
+ private EventBusRegistration(final EventBus eventBus, final BGPSessionListener listener, final List<Notification> allPreviousMessages) {
this.eventBus = eventBus;
this.listener = listener;
- for (final BGPMessage message : allPreviousMessages) {
+ for (final Notification message : allPreviousMessages) {
sendMessage(listener, message);
}
}
@Subscribe
- public void onMessage(final BGPMessage message) {
+ public void onMessage(final Notification message) {
sendMessage(this.listener, message);
}
this.closed = true;
}
- private static void sendMessage(final BGPSessionListener listener, final BGPMessage message) {
+ private static void sendMessage(final BGPSessionListener listener, final Notification message) {
if (BGPMock.connectionLostMagicMessage.equals(message)) {
listener.onSessionTerminated(null, null);
} else if (message instanceof BGPOpenMessage) {
import java.util.Collections;
import java.util.List;
-import org.opendaylight.protocol.bgp.parser.BGPMessage;
import org.opendaylight.protocol.bgp.parser.BGPSession;
import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
import org.opendaylight.protocol.bgp.parser.BGPTerminationReason;
-
+import org.opendaylight.yangtools.yang.binding.Notification;
/**
* Mock implementation of {@link BGPListener} for testing purposes.
*/
final class BGPListenerMock implements BGPSessionListener {
- private final List<BGPMessage> buffer = Collections.synchronizedList(new ArrayList<BGPMessage>());
+ private final List<Notification> buffer = Collections.synchronizedList(new ArrayList<Notification>());
private boolean connected = false;
- protected List<BGPMessage> getBuffer() {
+ protected List<Notification> getBuffer() {
return this.buffer;
}
}
@Override
- public void onMessage(final BGPSession session, final BGPMessage message) {
+ public void onMessage(final BGPSession session, final Notification message) {
this.buffer.add(message);
}
*/
package org.opendaylight.protocol.bgp.testtool;
-import org.opendaylight.protocol.bgp.parser.BGPMessage;
import org.opendaylight.protocol.bgp.parser.BGPSession;
import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
import org.opendaylight.protocol.bgp.parser.BGPTerminationReason;
+import org.opendaylight.yangtools.yang.binding.Notification;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static final Logger logger = LoggerFactory.getLogger(TestingListener.class);
@Override
- public void onMessage(final BGPSession session, final BGPMessage message) {
+ public void onMessage(final BGPSession session, final Notification message) {
logger.info("Client Listener: message received: {}", message.toString());
}
import java.io.IOException;
import java.net.InetSocketAddress;
-import org.opendaylight.protocol.bgp.parser.BGPMessage;
import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
import org.opendaylight.protocol.bgp.parser.impl.BGPMessageFactoryImpl;
import org.opendaylight.protocol.bgp.rib.impl.BGPHandlerFactory;
import org.opendaylight.protocol.framework.SessionListenerFactory;
import org.opendaylight.protocol.framework.SessionNegotiatorFactory;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
+import org.opendaylight.yangtools.yang.binding.Notification;
import com.google.common.base.Preconditions;
-public class BGPSpeakerMock<M, S extends ProtocolSession<M>, L extends SessionListener<M, ?, ?>> extends
-AbstractDispatcher<S, L> {
+public class BGPSpeakerMock<M, S extends ProtocolSession<M>, L extends SessionListener<M, ?, ?>> extends AbstractDispatcher<S, L> {
private final SessionNegotiatorFactory<M, S, L> negotiatorFactory;
private final ProtocolHandlerFactory<?> factory;
@Override
public void initializeChannel(final SocketChannel ch, final Promise<S> promise) {
- ch.pipeline().addLast(factory.getDecoders());
- ch.pipeline().addLast("negotiator", negotiatorFactory.getSessionNegotiator(listenerFactory, ch, promise));
- ch.pipeline().addLast(factory.getEncoders());
+ ch.pipeline().addLast(BGPSpeakerMock.this.factory.getDecoders());
+ ch.pipeline().addLast("negotiator",
+ BGPSpeakerMock.this.negotiatorFactory.getSessionNegotiator(listenerFactory, ch, promise));
+ ch.pipeline().addLast(BGPSpeakerMock.this.factory.getEncoders());
}
});
}
final BGPSessionPreferences prefs = new BGPSessionProposalImpl((short) 90, new AsNumber((long) 25), IPv4.FAMILY.addressForString("127.0.0.2")).getProposal();
- final SessionNegotiatorFactory<BGPMessage, BGPSessionImpl, BGPSessionListener> snf = new BGPSessionNegotiatorFactory(new HashedWheelTimer(), prefs);
+ final SessionNegotiatorFactory<Notification, BGPSessionImpl, BGPSessionListener> snf = new BGPSessionNegotiatorFactory(new HashedWheelTimer(), prefs);
- final BGPSpeakerMock<BGPMessage, BGPSessionImpl, BGPSessionListener> mock = new BGPSpeakerMock<BGPMessage, BGPSessionImpl, BGPSessionListener>(snf, new BGPHandlerFactory(new BGPMessageFactoryImpl()), new DefaultPromise<BGPSessionImpl>(GlobalEventExecutor.INSTANCE));
+ final BGPSpeakerMock<Notification, BGPSessionImpl, BGPSessionListener> mock = new BGPSpeakerMock<Notification, BGPSessionImpl, BGPSessionListener>(snf, new BGPHandlerFactory(new BGPMessageFactoryImpl()), new DefaultPromise<BGPSessionImpl>(GlobalEventExecutor.INSTANCE));
mock.createServer(new InetSocketAddress("127.0.0.2", 12345), f);
}
*/
package org.opendaylight.protocol.bgp.testtool;
-import org.opendaylight.protocol.bgp.parser.BGPMessage;
import org.opendaylight.protocol.bgp.parser.BGPSession;
import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
import org.opendaylight.protocol.bgp.parser.BGPTerminationReason;
+import org.opendaylight.yangtools.yang.binding.Notification;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
}
@Override
- public void onMessage(final BGPSession session, final BGPMessage message) {
+ public void onMessage(final BGPSession session, final Notification message) {
logger.info("Server: Message received: {}", message);
// this.d.stop();
}