use of Nodes.Node in project netvirt by opendaylight.
the class BaseVrfEntryHandler method makeConnectedRoute.
protected void makeConnectedRoute(BigInteger dpId, long vpnId, VrfEntry vrfEntry, String rd, List<InstructionInfo> instructions, int addOrRemove, WriteTransaction tx, List<SubTransaction> subTxns) {
Boolean wrTxPresent = true;
if (tx == null) {
wrTxPresent = false;
tx = dataBroker.newWriteOnlyTransaction();
}
LOG.trace("makeConnectedRoute: vrfEntry {}", vrfEntry);
String[] values = vrfEntry.getDestPrefix().split("/");
String ipAddress = values[0];
int prefixLength = values.length == 1 ? 0 : Integer.parseInt(values[1]);
if (addOrRemove == NwConstants.ADD_FLOW) {
LOG.debug("Adding route to DPN {} for rd {} prefix {} ", dpId, rd, vrfEntry.getDestPrefix());
} else {
LOG.debug("Removing route from DPN {} for rd {} prefix {}", dpId, rd, vrfEntry.getDestPrefix());
}
InetAddress destPrefix;
try {
destPrefix = InetAddress.getByName(ipAddress);
} catch (UnknownHostException e) {
LOG.error("Failed to get destPrefix for prefix {} rd {} VpnId {} DPN {}", vrfEntry.getDestPrefix(), rd, vpnId, dpId, e);
return;
}
List<MatchInfo> matches = new ArrayList<>();
matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(vpnId), MetaDataUtil.METADATA_MASK_VRFID));
if (destPrefix instanceof Inet4Address) {
matches.add(MatchEthernetType.IPV4);
if (prefixLength != 0) {
matches.add(new MatchIpv4Destination(destPrefix.getHostAddress(), Integer.toString(prefixLength)));
}
} else {
matches.add(MatchEthernetType.IPV6);
if (prefixLength != 0) {
matches.add(new MatchIpv6Destination(destPrefix.getHostAddress() + "/" + prefixLength));
}
}
int priority = DEFAULT_FIB_FLOW_PRIORITY + prefixLength;
String flowRef = FibUtil.getFlowRef(dpId, NwConstants.L3_FIB_TABLE, rd, priority, destPrefix);
FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.L3_FIB_TABLE, flowRef, priority, flowRef, 0, 0, COOKIE_VM_FIB_TABLE, matches, instructions);
Flow flow = flowEntity.getFlowBuilder().build();
String flowId = flowEntity.getFlowId();
FlowKey flowKey = new FlowKey(new FlowId(flowId));
Node nodeDpn = FibUtil.buildDpnNode(dpId);
InstanceIdentifier<Flow> flowInstanceId = InstanceIdentifier.builder(Nodes.class).child(Node.class, nodeDpn.getKey()).augmentation(FlowCapableNode.class).child(Table.class, new TableKey(flow.getTableId())).child(Flow.class, flowKey).build();
if (RouteOrigin.value(vrfEntry.getOrigin()) == RouteOrigin.BGP) {
SubTransaction subTransaction = new SubTransactionImpl();
if (addOrRemove == NwConstants.ADD_FLOW) {
subTransaction.setInstanceIdentifier(flowInstanceId);
subTransaction.setInstance(flow);
subTransaction.setAction(SubTransaction.CREATE);
} else {
subTransaction.setInstanceIdentifier(flowInstanceId);
subTransaction.setAction(SubTransaction.DELETE);
}
subTxns.add(subTransaction);
}
if (addOrRemove == NwConstants.ADD_FLOW) {
tx.put(LogicalDatastoreType.CONFIGURATION, flowInstanceId, flow, true);
} else {
tx.delete(LogicalDatastoreType.CONFIGURATION, flowInstanceId);
}
if (!wrTxPresent) {
tx.submit();
}
}
use of Nodes.Node in project netvirt by opendaylight.
the class Ipv6RouterAdvt method transmitRtrAdvertisement.
public boolean transmitRtrAdvertisement(Ipv6RtrAdvertType raType, VirtualPort routerPort, List<NodeConnectorRef> outportList, RouterSolicitationPacket rsPdu) {
RouterAdvertisementPacketBuilder raPacket = new RouterAdvertisementPacketBuilder();
updateRAResponse(raType, rsPdu, raPacket, routerPort);
// Serialize the response packet
byte[] txPayload = fillRouterAdvertisementPacket(raPacket.build());
for (NodeConnectorRef outport : outportList) {
InstanceIdentifier<Node> outNode = outport.getValue().firstIdentifierOf(Node.class);
TransmitPacketInput input = new TransmitPacketInputBuilder().setPayload(txPayload).setNode(new NodeRef(outNode)).setEgress(outport).build();
LOG.debug("Transmitting the Router Advt packet out {}", outport);
JdkFutures.addErrorLogging(packetService.transmitPacket(input), LOG, "transmitPacket");
}
return true;
}
use of Nodes.Node in project openflowplugin by opendaylight.
the class OpenflowpluginTestServiceProvider method register.
public ObjectRegistration<OpenflowpluginTestServiceProvider> register(final ProviderContext ctx) {
RoutedRpcRegistration<SalFlowService> addRoutedRpcImplementation = ctx.<SalFlowService>addRoutedRpcImplementation(SalFlowService.class, this);
setFlowRegistration(addRoutedRpcImplementation);
InstanceIdentifierBuilder<Nodes> builderII = InstanceIdentifier.<Nodes>builder(Nodes.class);
NodeId nodeId = new NodeId(OpenflowpluginTestActivator.NODE_ID);
NodeKey nodeKey = new NodeKey(nodeId);
InstanceIdentifierBuilder<Node> nodeIdentifier = builderII.<Node, NodeKey>child(Node.class, nodeKey);
InstanceIdentifier<Node> instance = nodeIdentifier.build();
flowRegistration.registerPath(NodeContext.class, instance);
RoutedRpcRegistration<SalFlowService> flowRegistration2 = getFlowRegistration();
return new AbstractObjectRegistration<OpenflowpluginTestServiceProvider>(this) {
@Override
protected void removeRegistration() {
flowRegistration2.close();
}
};
}
use of Nodes.Node in project openflowplugin by opendaylight.
the class ShellUtil method getNodeInfo.
public static OFNode getNodeInfo(final Long nodeId, final DataBroker broker) {
OFNode ofNode = null;
ReadOnlyTransaction tx = broker.newReadOnlyTransaction();
InstanceIdentifier<Node> path = InstanceIdentifier.builder(Nodes.class).child(Node.class, new NodeKey(new NodeId(NODE_PREFIX + nodeId))).build();
Optional<Node> result;
try {
CheckedFuture<Optional<Node>, ReadFailedException> checkedFuture = tx.read(LogicalDatastoreType.OPERATIONAL, path);
result = checkedFuture.get();
if (result.isPresent()) {
Node node = result.get();
String name = null;
List<NodeConnector> nodeConnectors = null;
List<String> portList = new ArrayList<>();
FlowCapableNode flowCapableNode = node.<FlowCapableNode>getAugmentation(FlowCapableNode.class);
if (flowCapableNode != null) {
name = node.<FlowCapableNode>getAugmentation(FlowCapableNode.class).getDescription();
} else {
LOG.error("Error while converting OFNode:{} to FlowCapableNode: {}", node.getId());
return null;
}
nodeConnectors = node.getNodeConnector();
for (NodeConnector nodeConnector : nodeConnectors) {
FlowCapableNodeConnector flowCapableNodeConnector = nodeConnector.getAugmentation(FlowCapableNodeConnector.class);
if (flowCapableNodeConnector == null) {
LOG.error("Error for OFNode:{} while reading nodeConnectors {}", node.getId());
return null;
} else {
String portName = flowCapableNodeConnector.getName();
portList.add(portName);
}
}
ofNode = new OFNode(nodeId, name, portList);
} else {
LOG.error("OFNode with nodeId {} not present Inventory DS: {}", nodeId);
return null;
}
} catch (ExecutionException | InterruptedException e) {
LOG.error("Error reading node {} from Inventory DS: {}", nodeId, e);
}
return ofNode;
}
use of Nodes.Node in project openflowplugin by opendaylight.
the class ShellUtil method getAllNodes.
@Nonnull
public static List<OFNode> getAllNodes(final DataBroker broker) {
List<Node> nodes = null;
ReadOnlyTransaction tx = broker.newReadOnlyTransaction();
InstanceIdentifier<Nodes> path = InstanceIdentifier.builder(Nodes.class).build();
try {
CheckedFuture<Optional<Nodes>, ReadFailedException> checkedFuture = tx.read(LogicalDatastoreType.OPERATIONAL, path);
Optional<Nodes> result = checkedFuture.get();
if (result.isPresent()) {
nodes = result.get().getNode();
}
} catch (ExecutionException | InterruptedException | NullPointerException e) {
LOG.error("Error reading nodes from Inventory DS", e);
}
if (nodes != null) {
List<OFNode> nodeList = new ArrayList<>();
for (Node node : nodes) {
String[] nodeId = node.getId().getValue().split(":");
String name = null;
FlowCapableNode flowCapableNode = node.<FlowCapableNode>getAugmentation(FlowCapableNode.class);
if (flowCapableNode != null) {
name = node.<FlowCapableNode>getAugmentation(FlowCapableNode.class).getDescription();
} else {
LOG.error("Error while converting OFNode: {} to FlowCapableNode", node.getId());
return Collections.emptyList();
}
OFNode ofNode = new OFNode(Long.parseLong(nodeId[1]), name);
LOG.trace("Added OFNode: {} to the list", ofNode.getNodeId());
nodeList.add(ofNode);
}
Collections.sort(nodeList);
return nodeList;
}
return Collections.emptyList();
}
Aggregations