use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone in project bgpcep by opendaylight.
the class AbstractBGPSessionNegotiator method startNegotiation.
@SuppressWarnings("checkstyle:illegalCatch")
private synchronized void startNegotiation() {
LOG.debug("Starting negotiating with {}, current state: {}", channel.remoteAddress(), state);
if (!(this.state == State.IDLE || this.state == State.OPEN_CONFIRM)) {
return;
}
// Open can be sent first either from ODL (IDLE) or from peer (OPEN_CONFIRM)
final IpAddressNoZone remoteIp = getRemoteIp();
try {
// Check if peer is configured in registry before retrieving preferences
if (!this.registry.isPeerConfigured(remoteIp)) {
final BGPDocumentedException cause = new BGPDocumentedException(String.format("BGP peer with ip: %s not configured, check configured peers in : %s", remoteIp, this.registry), BGPError.CONNECTION_REJECTED);
negotiationFailed(cause);
return;
}
final BGPSessionPreferences preferences = this.registry.getPeerPreferences(remoteIp);
final Uint16 as = openASNumber(preferences.getMyAs().getValue().longValue());
sendMessage(new OpenBuilder().setMyAsNumber(as).setHoldTimer(Uint16.valueOf(preferences.getHoldTime())).setBgpIdentifier(preferences.getBgpId()).setBgpParameters(preferences.getParams()).build());
if (this.state != State.FINISHED) {
this.state = State.OPEN_SENT;
this.pending = this.channel.eventLoop().schedule(() -> {
synchronized (AbstractBGPSessionNegotiator.this) {
AbstractBGPSessionNegotiator.this.pending = null;
if (AbstractBGPSessionNegotiator.this.state != State.FINISHED) {
AbstractBGPSessionNegotiator.this.sendMessage(buildErrorNotify(BGPError.HOLD_TIMER_EXPIRED));
negotiationFailed(new BGPDocumentedException("HoldTimer expired", BGPError.FSM_ERROR));
AbstractBGPSessionNegotiator.this.state = State.FINISHED;
}
}
}, INITIAL_HOLDTIMER, TimeUnit.MINUTES);
}
} catch (final Exception e) {
LOG.warn("Unexpected negotiation failure", e);
negotiationFailedCloseChannel(e);
}
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone in project bgpcep by opendaylight.
the class BGPPeerAcceptorImplTest method testBGPPeerAcceptorImpl.
@Test
public void testBGPPeerAcceptorImpl() throws Exception {
final InetSocketAddress inetServerAddress = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
final IpAddressNoZone serverIpAddress = new IpAddressNoZone(new Ipv4AddressNoZone(InetSocketAddressUtil.toHostAndPort(inetServerAddress).getHost()));
final PortNumber portNumber = new PortNumber(Uint16.valueOf(InetSocketAddressUtil.toHostAndPort(inetServerAddress).getPort()));
this.registry.addPeer(serverIpAddress, this.serverListener, createPreferences(inetServerAddress));
final BGPPeerAcceptorImpl bgpPeerAcceptor = new BGPPeerAcceptorImpl(serverIpAddress, portNumber, this.serverDispatcher);
bgpPeerAcceptor.start();
final Future<BGPSessionImpl> futureClient = this.clientDispatcher.createClient(this.clientAddress, inetServerAddress, 2, true);
waitFutureSuccess(futureClient);
final BGPSessionImpl session = futureClient.get();
Assert.assertEquals(State.UP, this.clientListener.getState());
Assert.assertEquals(AS_NUMBER, session.getAsNumber());
Assert.assertEquals(Sets.newHashSet(IPV_4_TT), session.getAdvertisedTableTypes());
session.close();
checkIdleState(this.clientListener);
bgpPeerAcceptor.close();
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone in project bgpcep by opendaylight.
the class PEDistinguisherLabelsAttributeHandler method parseAttribute.
@Override
public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder, final RevisedErrorHandling errorHandling, final PeerSpecificParserConstraint constraint) throws BGPTreatAsWithdrawException {
final int readable = buffer.readableBytes();
if (readable == 0) {
return;
}
final boolean isIpv4;
final int count;
if (readable % 7 == 0) {
count = readable / 7;
isIpv4 = true;
} else if (readable % 19 == 0) {
count = readable / 19;
isIpv4 = false;
} else {
// as though all the routes contained in this Update had been withdrawn.
throw new BGPTreatAsWithdrawException(BGPError.MALFORMED_ATTR_LIST, "PE Distinguisher Labels has incorrect length %s", readable);
}
final List<PeDistinguisherLabelAttribute> list = new ArrayList<>(count);
for (int i = 0; i < count; ++i) {
final PeDistinguisherLabelAttributeBuilder attribute = new PeDistinguisherLabelAttributeBuilder();
if (isIpv4) {
attribute.setPeAddress(new IpAddressNoZone(Ipv4Util.addressForByteBuf(buffer)));
} else {
attribute.setPeAddress(new IpAddressNoZone(Ipv6Util.addressForByteBuf(buffer)));
}
attribute.setMplsLabel(MplsLabelUtil.mplsLabelForByteBuf(buffer));
list.add(attribute.build());
}
builder.addAugmentation(new PeDistinguisherLabelsAttributeAugmentationBuilder().setPeDistinguisherLabelsAttribute(new PeDistinguisherLabelsAttributeBuilder().setPeDistinguisherLabelAttribute(list).build()).build());
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone in project bgpcep by opendaylight.
the class LinkstateAttributeParserTest method testPositiveTELspAttribute.
@Test
public void testPositiveTELspAttribute() throws BGPParsingException, BGPDocumentedException {
final AttributesBuilder builder = createBuilder(new TeLspCaseBuilder().build());
this.parser.parseAttribute(Unpooled.copiedBuffer(TE_LSP_ATTR), builder, null);
final Attributes1 attrs = builder.augmentation(Attributes1.class);
final TeLspAttributes teLspAttributes = ((TeLspAttributesCase) attrs.getLinkStateAttribute()).getTeLspAttributes();
assertNotNull(teLspAttributes);
final TspecObject tSpec = teLspAttributes.getTspecObject();
assertNotNull(tSpec);
assertEquals(new Float32(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01 }), tSpec.getTokenBucketRate());
assertEquals(new Float32(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x02 }), teLspAttributes.getTspecObject().getTokenBucketSize());
assertEquals(new Float32(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x03 }), tSpec.getPeakDataRate());
assertEquals(Uint32.valueOf(4), tSpec.getMinimumPolicedUnit());
assertEquals(Uint32.valueOf(5), tSpec.getMaximumPacketSize());
final AssociationObject associationObject = teLspAttributes.getAssociationObject();
assertEquals(AssociationType.Recovery, associationObject.getAssociationType());
final IpAddressNoZone ipv4 = new IpAddressNoZone(Ipv4Util.addressForByteBuf(Unpooled.copiedBuffer(new byte[] { 0x01, 0x02, 0x03, 0x04 })));
assertEquals(ipv4, associationObject.getIpAddress());
final short associationId = 2;
assertEquals(associationId, associationObject.getAssociationId().shortValue());
// serialization
final ByteBuf buff = Unpooled.buffer();
this.parser.serializeAttribute(builder.build(), buff);
assertArrayEquals(TE_LSP_ATTR, ByteArray.getAllBytes(buff));
assertTrue(Arrays.equals(TE_LSP_ATTR, ByteArray.getAllBytes(buff)));
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone in project bgpcep by opendaylight.
the class PCEPTlvParserTest method testRSVPError4SpecTlv.
@Test
public void testRSVPError4SpecTlv() throws PCEPDeserializerException {
final StatefulRSVPErrorSpecTlvParser parser = new StatefulRSVPErrorSpecTlvParser();
final RsvpErrorBuilder builder = new RsvpErrorBuilder().setNode(new IpAddressNoZone(Ipv4Util.addressForByteBuf(Unpooled.wrappedBuffer(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 })))).setFlags(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ErrorSpec.Flags(false, true)).setCode(Uint8.valueOf(146)).setValue(Uint16.valueOf(5634));
final RsvpErrorSpec tlv = new RsvpErrorSpecBuilder().setErrorType(new RsvpCaseBuilder().setRsvpError(builder.build()).build()).build();
assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(RSVP_ERROR_BYTES, 4))));
final ByteBuf buff = Unpooled.buffer();
parser.serializeTlv(tlv, buff);
assertArrayEquals(RSVP_ERROR_BYTES, ByteArray.getAllBytes(buff));
}
Aggregations